PyTorch-first quantum computing

Quantum computing,
the PyTorch way.

Build and train classical–quantum models with familiar PyTorch tools.

Explore simulation backends and run circuits on supported quantum hardware in one workflow.

$ pip install flagquantum
Quantum AI = Classical + QuantumFlagOS

Classical and quantum, working together in one workflow.

Combine classical neural networks with trainable quantum circuits.

Build, optimize, and run hybrid models in a familiar PyTorch workflow.

Hybrid modeling

Combine quantum circuits with PyTorch models, using familiar autograd and optimizers to train hybrid networks.

Flexible simulation

Choose statevector, MPS, or tensor-network simulation to match your circuit structure and available resources.

Simulation to hardware

Keep circuits and measurements consistent as you switch between supported simulators and quantum hardware.

DEVELOPER EXPERIENCE

Build a circuit. Train a model.

model.pyPython
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]),
)
q₀q₁RY(θ)

2 qubits · 1 trainable parameter

01

Quantum models, the PyTorch way

Turn a quantum circuit into a trainable module, ready to combine with classical neural networks.

model.pyPython
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]),
)
q₀q₁RY(θ)

2 qubits · 1 trainable parameter

02

Let training update the parameters

Use automatic differentiation and familiar optimizers. Follow the loss as the model learns.

train.pyPython
training = fq.train(
    model,
    optimizer=torch.optim.Adam(
        model.parameters(), lr=0.08),
    objective=lambda z: z.mean(),
    steps=60,
)
Measured loss · local CPU0.969 → -0.994
Measured training loss over 60 optimization steps10−1160

60 steps · Adam · learning rate 0.08

03

One circuit. Different execution targets.

Keep your circuit and measurement explicit. Run locally or choose a configured quantum backend.

execute.pyPython
trained_circuit = circuit(
    next(model.parameters()).detach())
measurement = fq.expectation(fq.Z(0))

# Local simulation
result = fq.run(
    trained_circuit, outputs=measurement)

# Configured quantum hardware
hardware = fq.run(
    trained_circuit, target="quafu:Baihua",
    compiler="qsteed", outputs=measurement,
    shots=1024,
)
Local simulation result⟨Z₀⟩ = -0.996156

The hardware call requires configured Quafu access; no remote job was run for this demo.

CLASSICAL–QUANTUM PROGRAMMING & COMPILATION

Two levels of hybrid. One programming vision.

Compose independent modules—or bring classical control inside the quantum program.

01

Weak coupling

Independent modules, joint optimization

02

Strong coupling

Classical control within the circuit

Quantum circuitMid-circuit measurementClassical controlMeasurement-conditioned gatesq0q1q2HRyRzRzRymm = 1XZParameterized operationsConditional feed-forwardQuantum operationsClassical feed-forward
From feed-forward to error correction →
HETEROGENEOUS COMPUTING

One framework. Diverse computing platforms.

Explore GPU simulation, the FlagOS multi-chip ecosystem, and quantum hardware through a shared development workflow.

Model · train · execute
CLASSICAL COMPUTING

FlagOS ecosystem

GPGPU, domain-specific AI processors and heterogeneous backends for simulation and model training.

GPGPU

General-purpose GPU computing

NVIDIAHygonMetaXMoore ThreadsIluvatarSunriseT-Head

NPU / DSA

Domain-specific AI computing, including MLU

Huawei AscendCambriconTsingmicroARM China

Other heterogeneous backends

Vendor-specific compute architectures

EnflameHuixiSpacemiTDAMO AcademyKLX
Official backend matrix ↗
QPU

Quantum hardware & cloud

Connect circuits to quantum execution platforms.

Quafu
Multi-route quantum cloudExperimental hardware adapter
Amazon BraketAmazon Braket
OpenQASM / Braket SDKIntegration validation pending
IBM Quantum
QiskitIntegration validation pending

Quafu technology roadmap

SuperconductingConnected
Trapped ionComing soon
Neutral atomComing soon
PhotonicComing soon
Execution workflow

Compile circuit → Submit job → Retrieve results

Hardware execution guide ↗
Compatibility & support scope

Chip names reflect the FlagOS / FlagTree backend ecosystem, not end-to-end FlagQuantum validation on every device. Architecture groups describe broad computing families, not identical microarchitectures; a vendor may span multiple product designs. Availability depends on the compiler branch, runtime, operators and workload. Quafu is a multi-route platform: superconducting access is connected, supercomputer simulation is being built jointly, and trapped-ion, neutral-atom and photonic access are coming soon. These are platform statuses; FlagQuantum execution depends on the selected backend and adapter. Quafu has an experimental FlagQuantum hardware adapter. Amazon Braket and IBM Quantum are listed with proposed OpenQASM / SDK and Qiskit integration paths; end-to-end integration remains to be verified. Circuit export alone does not establish hardware execution support.

FlagTree source ↗
RESEARCH APPLICATIONS

Explore the possibilities.

Learn from data, model molecules, optimize decisions, and understand quantum security.

MACHINE LEARNING

Train classical and quantum together.

Explore how a quantum layer changes learning, and compare it with a classical model.

DIGITS → HYBRID MODEL → PREDICTION0 → 02 → 24 → 46 → 68 → 19 → 2TEST CONFUSION MATRIX450 test images · measured results

10-class test accuracy: 92.2% hybrid · 96.2% classical

One fixed split · 4-qubit simulation

MOLECULES & MATERIALS

Follow the energy toward a reference.

Study how molecular geometry and the choice of initial state affect variational optimization.

H₄ CHAIN · VARIABLE BOND LENGTHHHHH1.1 ÅFULL-CI REFERENCE-2.137971 Ha8 spin orbitals · 36 determinants

H₄ chain · 6 bond lengths · 3 initial states

Total energy · full-CI reference

COMBINATORIAL OPTIMIZATION

Compare competing routes to a solution.

Inspect quantum and classical candidates for the same weighted network problem.

WEIGHTED NETWORK · CANDIDATE CUTCANDIDATE / EXACT OPTIMUM75 / 75512 quantum samples · cut valuesCyan / violet: node partitions

20 nodes · exact best cut: 75

QAOA expectation · annealing mean

QUANTUM SECURITY

Understand what quantum algorithms change.

Follow RSA factorization and Grover search through closed, teaching-scale examples.

TWO ALGORITHMS · TWO SECURITY QUESTIONSSHOROrder finding → factors21 = 3 × 7(N, e) = (21, 5)Teaching RSA · public → privateGROVER64 candidates → target 37Amplitude amplification · closed search

Shor + Grover · step-by-step walkthrough

Quantum algorithms · separate from AI

QUANTUM DIGITAL TWINRESEARCH EXPLORATION

One quantum system. A world of understanding.

From device topology and control pulses to noise and validation: explore a computational counterpart of a quantum system.

Model layers & scope

A digital twin spans device connectivity, frequencies and couplings; Hamiltonian and pulse-level dynamics; noise, leakage and readout; and calibration-driven validation. The view illustrates these layers without claiming an implemented end-to-end FlagQuantum digital twin. Device-specific data and independent checks are essential.

Read the research ↗
PHYSICAL SYSTEMCOMPUTATIONAL TWINMODELFEEDBACKDevice · control · observationStructure · dynamics · predictionCONNECTIVITYqᵢ ↔ qⱼQubits & coupling graphDEVICE PARAMETERSωᵢ · gᵢⱼFrequencies & interactionsMODEL SPACEH₀ + HᵢⱼGeometry & effective Hamiltonian

Swipe to explore the full model ↔

Map qubits, coupling, frequencies and device geometry into a computational model. The nine-node layout is illustrative, not a replica of a connected processor.

FAULT-TOLERANT QUANTUM COMPUTINGRESEARCH EXPLORATION

Physical qubits. Logical possibilities.

Inspect a rotated surface-code patch, follow detection events through time, and connect decoding to logical resources.

Logical operations & limitations

This patch encodes one logical qubit. Logical X and Z can be represented by boundary-to-boundary strings. Fault-tolerant computation also requires repeated measurement, a noise-aware decoder, logical operations such as lattice surgery, and a resource budget. Larger distance helps only in a suitable noise regime; no threshold or logical error rate is estimated here.

Surface-code reference ↗
PHYSICAL QUBITS · LOGICAL PROTECTIONENCODE012345678● Data ■ X checks ■ Z checksCHECK SUPPORT[[9, 1, 3]]One logical qubit in a distance-3 patchX₀ X₁ X₃ X₄Z₁ Z₂ Z₄ Z₅Overlapping checks. Commuting stabilizers.Colored regions identify check support.DATA QUBITS9MEASUREMENT ANCILLAS8LOGICAL QUBIT1

Swipe to explore the full model ↔

Distance-3 rotated surface code: 9 data qubits, 4 X checks and 4 Z checks. Colored faces and boundary checks show stabilizer support. One ancilla per check gives 17 physical qubits.

Get started

Try it now or install from source

Quick start

Install FlagQuantum in your Python environment with pip.

$ pip install flagquantum

Install from source

Clone the full source and follow the setup instructions in the repository.

$ git clone https://github.com/flagos-ai/FlagQuantum.git
OPEN COLLABORATION · GLOBAL POSSIBILITIES

Build the quantum AI ecosystem with us.

Contribute models, build tools, and share experiments with FlagQuantum. Bring your ideas to classical–quantum computing, from research to applications.

World map with light trails radiating from China across continents, symbolizing open collaboration.
An open invitation to developers everywhere.

Institutions & platforms

FlagOS · Beijing Academy of Artificial Intelligence (BAAI)

Quafu Quantum Cloud · Beijing Academy of Quantum Information Sciences (BAQIS)