Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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.

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.

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

PyTorch 2.13 does not publish macOS Intel (x86_64) wheels, so this FlagQuantum release cannot provide a working Intel macOS installation.

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.13.x and 2.14.x. 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.

GPU: Select a PyTorch 2.13.x or 2.14.x command matching your accelerator from the PyTorch installer, then run:

python -m pip install flagquantum

Installing from source? Follow the short setup in CONTRIBUTING.md.

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 GPU workspace or Quafu quantum hardware. Configure the Jiuding workspace and credentials or the Quafu token 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: service compilation and estimation from measured shots
quafu_result = fq.run(
    trained_circuit, target="quafu:Baihua",
    outputs=measurement, shots=1024,
)

The Jiuding 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, including the 0.3.0rc3 prerelease. 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 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

Metadata

Release files for flagquantum 0.3.0rc3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flagquantum 0.3.0rc3
File Size Uploaded
flagquantum-0.3.0rc3.tar.gz 1.8 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for flagquantum 0.3.0rc3
File Interpreter ABI Platform
flagquantum-0.3.0rc3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
flagquantum-0.3.0rc3-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
flagquantum-0.3.0rc3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 9.1 MB

Release files / flagquantum-0.3.0rc3.tar.gz

Download URL flagquantum-0.3.0rc3.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
94359a449faefbb95821b53c2167fe212a9e916728baf37426970413fa1989af
BLAKE2b-256 checksum
How to use checksums
221539ea53cbdb115148d589a0093373091ce0d33cb19020fa763a403c22d8cf
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 11, 2026.

Transparency log

Release files / flagquantum-0.3.0rc3-cp310-abi3-win_amd64.whl

Download URL flagquantum-0.3.0rc3-cp310-abi3-win_amd64.whl
Size 2.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
128e850a19a52ebcc0fb154433b596c1f5a43fc07ad7e7158f64fa717dc84fbc
BLAKE2b-256 checksum
How to use checksums
5353bde35d224c89891d87f3ea70fef8153522ebb1df0fa680fb378eb6a056c3
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 11, 2026.

Transparency log

Release files / flagquantum-0.3.0rc3-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL flagquantum-0.3.0rc3-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
6adf67187f297d2ac6ebcdb245076624b8ffefc13b884b9ce9c72bfe446f60dc
BLAKE2b-256 checksum
How to use checksums
38e3bda06834203de34ce0aa76fa52b800c64b3d34941c2e4a7f77fb156ee8fc
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 11, 2026.

Transparency log

Release files / flagquantum-0.3.0rc3-cp310-abi3-macosx_11_0_arm64.whl

Download URL flagquantum-0.3.0rc3-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
1d0b39b5f601fac775229046b6643507b38057c80b3498a907f2b4895f853351
BLAKE2b-256 checksum
How to use checksums
11a4843d93d851ccd98135f6b166743f6bc50116cb32ffbed8f209bfb6930a05
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 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

4 release files

0.3.0

4 release files

This release

0.3.0rc3 This release

4 release files

0.2.0

2 release files

0.1.1

2 release 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