Skip to main content
FlagQuantum

Quantum computing, built for learning.

A PyTorch-first framework for differentiable quantum computing and quantum AI.

Quick start · Documentation · Examples

Turn quantum circuits into trainable models. FlagQuantum brings PyTorch learning, multiple simulation representations, and hardware execution into one workflow. Its long-term goal is a continuous path from local scientific exploration to distributed training, device modeling, and fault-tolerant quantum computing research.

  • Train with PyTorch. Compose quantum and classical layers with autograd and familiar optimizers.
  • Choose the representation. Statevector, matrix product state (MPS), and tensor-network simulation for different circuit structures and resource budgets.
  • Connect simulation to hardware. Keep the circuit and requested observable explicit as you move between supported execution targets.

This is a pre-release framework. Local training and selected distributed paths have correctness evidence; support is specific to each backend and workload. See the validation scope for what has been tested and what remains a research goal.

Train your first quantum model

Requires Python 3.10–3.12. From the repository root:

python -m pip install -e .

Build a two-qubit circuit and learn its rotation angle by minimizing ⟨Z₀⟩. fq.Module exposes the quantum model to PyTorch; outputs selects what to measure after training.

import torch
import flagquantum as fq


def circuit(parameters):
    return fq.Circuit(2).ry(0, parameters[0]).cx(0, 1)


model = fq.Module(circuit, n_parameters=1, init=torch.tensor([0.25]))
training = fq.train(
    model,
    optimizer=torch.optim.Adam(model.parameters(), lr=0.05),
    objective=lambda z: z.mean(),
    steps=10,
)

trained_circuit = circuit(next(model.parameters()).detach())
measurement = fq.expectation(fq.Z(0))
result = fq.run(trained_circuit, outputs=measurement)
print(result.expectation())

For a complete classical–quantum model, follow the hybrid training example.

Same circuit. Different execution targets.

The experimental adapters can evaluate the same observable on a Jiuding GPU workspace or Quafu quantum hardware. Configure the Jiuding workspace and credentials or the Quafu token and QSteed plugin before running the corresponding call.

# GPU simulation in a running Jiuding workspace
jiuding_result = fq.run(
    trained_circuit, target="jiuding:gpu", outputs=measurement,
)

# Quantum hardware: compile, submit, and estimate from measured shots
quafu_result = fq.run(
    trained_circuit, target="quafu:Baihua", compiler="qsteed",
    outputs=measurement, shots=1024,
)

Jiuding computes a simulated expectation; Quafu estimates it from hardware measurements. The training example runs on your local machine; these calls evaluate the trained circuit remotely. Live provider access is required and is not certified by the local or A800 checks.

Go further

Connect simulation with device observations. Use QPU digital twins to compare calibration-based model predictions with measured counts. See the experiment guide for task binding and the scope of hardware validation.

Toward fault-tolerant quantum computing. Start with a local QEC memory experiment connecting syndrome extraction, decoding, and correction. Logical operations and hardware feedback are longer-term research goals.

Quantum AI tutorials · Distributed statevector · Distributed MPS · ARCHITECTURE.md

Support varies by execution path. See the capability catalog for maturity and limitations.

Benchmarks and validated results


Contributing · Apache License 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flagquantum-0.2.0.tar.gz (916.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flagquantum-0.2.0-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file flagquantum-0.2.0.tar.gz.

File metadata

  • Download URL: flagquantum-0.2.0.tar.gz
  • Upload date:
  • Size: 916.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.14

File hashes

Hashes for flagquantum-0.2.0.tar.gz
Algorithm Hash digest
SHA256 51daef641ee411e74741e0e8050a438571ea6309824609a2da7e981407c12741
MD5 52c6a651e1c9ef0a8d49ed6865bd12e9
BLAKE2b-256 b96570a2e5d1a6945d065658425a91227cf1855c8ff2b43db57f9dd14f63323c

See more details on using hashes here.

File details

Details for the file flagquantum-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: flagquantum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.14

File hashes

Hashes for flagquantum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09dba84bfa90a7098390b204f91bb1e57ecd984ef43ba884761daf6f6cbe768c
MD5 0faddc993aa8b177b7125b743b5fe010
BLAKE2b-256 8352dfd131c56233abaa6caef99bc4ba78fba2131c731ea6fa50f17cd3a079a8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page