Features#
PyTorch-native quantum training#
Trainable circuits as PyTorch modules:
fq.Moduleexposes the quantum model to PyTorch, soloss.backward()and ordinary optimizers train quantum and classical layers in one loop.Flat or named parameter groups: positional parameters and named groups such as
{"encoder": (4,), "readout": ()}are both supported, with reproducible initialization and a module-local seed.Stable training results:
fq.trainreturnsfq.TrainingResultwith versioned summaries, and checkpoint and resume stay onfq.Module.
Several simulation representations, one program#
Statevector: the exact local path, on CPU or one GPU, with automatic dense reference reporting for small systems.
Matrix product state (MPS): low-entanglement systems at far larger wire counts than a dense statevector allows, including constrained TEBD.
Tensor networks: slicing and contraction for circuit structures where neither dense statevector nor MPS fits.
Optional JAX kernels behind the same PyTorch interface, with first-order gradient support across the bridge.
One command to switch:
python examples/quick_start.py --mode sv|mps|tnruns the same hybrid model on three representations without editing code.
Compilation and export#
Target-independent optimization:
flagquantum.compiler.optimizeapplies canonical rewrites to a fixed point and returns new IR.Target-aware compilation:
fq.compile(..., coupling_map=..., routing_strategy=...)emits only topology-valid two-qubit operations and records the routing decision.Compiler plugins: independently installed packages may register a compiler through the extension registry, for example the QSteed plugin used for Quafu submission.
OpenQASM and framework export: circuit export to OpenQASM 3.0 and adapters for Qiskit, PennyLane, Cirq, Braket and CUDA-Q.
Measurement, noise and error correction#
Observables and outputs:
fq.X,fq.Y,fq.Zwith@products and ordinary arithmetic build Hamiltonians;fq.expectation,fq.probabilities,fq.samplesandfq.countsrequest results.Backend-neutral noise: one
NoiseModeldrives exact density-matrix evolution, batched statevector trajectories and MPS quantum trajectories, with thermal relaxation, depolarizing, bit/phase flip and readout errors.Hardware Pauli measurement planning: qubit-wise-commuting grouping with one sealed deployment package per group.
Dynamic circuits: mid-circuit measurement and classical feedback, with a read-only backend preflight.
Quantum error correction: a repetition-code memory experiment connecting syndrome extraction, decoding and correction.
Distributed and accelerator execution#
Sharded statevector training: one logical statevector across ranks, with distributed forward, backward and optimizer state.
Rank-owned MPS: distributed MPS forward, backward and optimizer state for workloads that do not fit one device.
PyTorch-native under a process group: the same module and result surface uses the sharded runtime once a multi-rank process group is initialized.
FlagOS accelerators through Torch-FL: the logical
flagos:0device is reached through Torch-FL, which owns vendor detection and dispatch.
Deployment, interop and ecosystem#
Sealed deployment packages: bind trained parameters, compile for a target and produce an auditable package before submission.
QPU digital twins: calibration-conditioned models that predict a deviceβs measurement distribution and carry explicit evidence boundaries.
Algorithm units: Grover search, amplitude estimation, quantum PCA, quantum k-medians, quantum kernel estimation and kernel ridge classification, feature selection as a QUBO, and QUBO-to-Ising mapping.
Circuit visualization: a text drawer for terminals and a Matplotlib drawer for publication figures.