Quantum computing, built for learning.
A PyTorch-first framework for differentiable quantum computing and quantum AI.
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.
Support is specific to each backend and workload. Local training and selected distributed paths have correctness evidence. See the validation scope for what has been tested and what remains a research goal.
Qubit ordering: qubit 0 is the most-significant bit
By default, a circuit starts in |00...0>, with amplitude 1 at statevector
index 0 and 0 everywhere else. For example, applying X to qubit 0 of
|000> produces |100> at index 4; applying it to qubit 2 produces
|001> at index 1.
This matches the tensor-product notation
|q0> ⊗ |q1> ⊗ ... ⊗ |q(n-1)>, keeping equations, matrices, and qubit
lists in the same left-to-right order.
| Framework or service | Exposed qubit/result order | Compared with FlagQuantum |
|---|---|---|
| FlagQuantum | Qubit 0 is the MSB |
Native convention |
| Cirq | The first qubit in qubit_order is the MSB |
Same when ordered [q0, q1, ...] |
| PennyLane | Basis-state digits follow the supplied qubit sequence | Same when ordered [0, 1, ...] |
| Qiskit | Qubit 0 is the LSB |
Opposite significance |
| NVIDIA cuStateVec | Index bit 0 is the LSB |
Opposite significance |
| Jiuding QuantumAI Cloud | Runs FlagQuantum remotely and returns FlagQuantum-ordered results | Same |
| Quafu | Provider count strings are converted to logical qubit order, with qubit 0 on the left |
Normalized to the same order |
| Amazon Braket | Ascending qubit order, with qubit 0 as the MSB |
Same |
| Azure Quantum | Depends on the selected Azure target and hardware provider | No platform-wide convention |
Endianness affects statevector, matrix, and bitstring indexing, not the
(control, target) order of gate arguments. Convert representations at framework
boundaries instead of reversing gate arguments. Cloud services commonly expose
measurement results rather than raw statevectors, so the service rows describe
the order visible at FlagQuantum's result boundary.
Install and train your first quantum model
Requires Python 3.10–3.12. Choose the command for your computer.
macOS (Apple Silicon):
python -m pip install flagquantum
This release publishes macOS wheels for Apple Silicon only; Intel macOS is not a supported binary installation target.
Linux or Windows, CPU only:
python -m pip install "torch>=2.13,<2.15" --index-url https://download.pytorch.org/whl/cpu
python -m pip install flagquantum
FlagQuantum's compiled extension uses PyTorch's Stable ABI and is tested with PyTorch 2.10.x through 2.14.x in compatibility CI. New CPU/CUDA environments should use the recommended 2.13.x or 2.14.x runtime above. The first CPU install downloads about 200 MB of PyTorch. On a clean GitHub Ubuntu runner it took about 16 seconds; slower networks will take longer.
NVIDIA GPU: Select a PyTorch 2.13.x or 2.14.x CUDA command from the PyTorch installer, then run:
python -m pip install flagquantum
Installing from source? Follow the short setup in CONTRIBUTING.md.
Native accelerator support: FlagQuantum runs directly on the following vendor-provided PyTorch runtimes.
| NVIDIA CUDA | Upstream PyTorch |
| Hygon DCU | Vendor PyTorch runtime |
| Moore Threads MUSA | Vendor PyTorch runtime |
| MetaX | Vendor PyTorch runtime |
| Biren | Vendor PyTorch runtime |
Keep the vendor runtime installed, then run python -m pip install flagquantum.
The core requirement accepts torch>=2.10,<2.15, including local version labels
such as 2.10.0+metax3.8.1.0; do not replace a managed runtime with an upstream
CPU/CUDA wheel. Avoid --upgrade/--upgrade-strategy eager when retaining a
managed runtime. The invertible extra still requires PyTorch 2.13.x and is not
a vendor-runtime installation shortcut.
To build a CPU or GPU environment with QSteed and optional JAX, follow the container guide.
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 QuantumAI Cloud GPU workspace or Quafu quantum hardware. Configure the Jiuding QuantumAI Cloud workspace and credentials or the Quafu token before running the corresponding call.
# Managed GPU simulation on Jiuding QuantumAI Cloud
jiuding_result = fq.run(
trained_circuit, target="jiuding:gpu", outputs=measurement,
)
# Quantum hardware: service compilation and estimation from measured shots
quafu_result = fq.run(
trained_circuit, target="quafu:Baihua",
outputs=measurement, shots=1024,
)
The Jiuding QuantumAI Cloud call above needs JIUDING_WORKSPACE set to the
running workspace name when it is invoked from outside that workspace; inside
the workspace the name is discovered automatically. See
repeated low-latency workspace execution.
Direct Quafu submission is available in the 0.3 release line. Install
flagquantum==0.3.0 for this path. With the older 0.2.0 release, use the
documented local QSteed compilation path instead: pass compiler="qsteed" after installing the
separate
FlagQuantum Compiler QSteed
plugin, as described in
optional local compiler plugin.
The quafu extra does not install that plugin.
Jiuding QuantumAI Cloud 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
Metadata
Release files for flagquantum 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flagquantum-0.3.0.tar.gz | 1.8 MB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flagquantum-0.3.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| flagquantum-0.3.0-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| flagquantum-0.3.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 9.2 MB
Release files / flagquantum-0.3.0.tar.gz
| Download URL | flagquantum-0.3.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fd8293700886f3507b217812eeb2613eb03f58f7fb5070a239afd47d40d5d2f
|
|
BLAKE2b-256 checksum How to use checksums |
6e214fd9815deba92a57794ec8cad3fd716f49ec91905a09e59b77dbcde1104c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / flagquantum-0.3.0-cp310-abi3-win_amd64.whl
| Download URL | flagquantum-0.3.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
cddb1c516aa4a7ef9efb0b290865008e71378e96cf7d3cd3021aeba1cb67c94b
|
|
BLAKE2b-256 checksum How to use checksums |
acb9738e6e8d583688646a0f06699c3ee0175cee07f9bf2866f421d83a4082ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / flagquantum-0.3.0-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | flagquantum-0.3.0-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
743fde7615170045393681e119ed5b0bf2215e18b5e0380eaf84b5acd14abc9e
|
|
BLAKE2b-256 checksum How to use checksums |
c333ca2b05c468972d1ce34672ef88263b68d2305bdeb7b0ffa1680e4b25a31a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / flagquantum-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | flagquantum-0.3.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.4 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7b7d5a1c8b45f0188b37bf807675eaee10931198ad34d0a8f78174a1ef65b979
|
|
BLAKE2b-256 checksum How to use checksums |
f48f3afdf7fa9da2f89bffaae221cb418aa8965c65d9f5428105e6cefe9030b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency log