Clifft¶
A fast exact simulator for near-Clifford quantum circuits.
What is Clifft?¶
Clifft is an exact simulator for quantum circuits whose dominant structure is Clifford, but whose behavior depends on localized non-Clifford operations. It accepts Stim-compatible circuits, extends them with non-Clifford gates, and compiles them into bytecode executed by a high-performance virtual machine.
Clifft works by factoring the quantum state into an offline Clifford frame, an online Pauli frame, and a dense active state vector. Clifford coordinate transformations are resolved ahead of time, while each shot performs only lightweight frame updates and localized state-vector evolution.
The main cost scales with \(2^k\) rather than \(2^n\), where \(n\) is the total number of qubits and \(k\) is the active dimension of the state vector. Non-Clifford operations can increase \(k\), while measurements can reduce it. For near-Clifford protocols with frequent measurements, such as magic-state preparation circuits, this can provide large memory and runtime savings over standard dense state-vector simulation.
Quick Example¶
Install via pip install clifft, then:
import clifft
# Compile a Stim-format circuit extended with T gates.
program = clifft.compile("""
H 0
CNOT 0 1
T 2
M 0 1 2
""")
# Sample measurement outcomes.
result = clifft.sample(program, shots=1000)
print(result.measurements[:5]) # First 5 shots.
Key Features¶
-
Stim-Compatible Format and API
Parse Stim-format circuits, including noise channels, detectors, observables, and repeat blocks, with extensions for non-Clifford gates. Compile once, then sample many shots through a familiar Python interface.
-
Exact Near-Clifford Simulation
Simulate circuits with localized non-Clifford operations exactly, without approximating the quantum state.
-
Optimizing Compiler Pipeline
Multi-level optimization passes reduce active state-vector work before execution.
-
Active-Dimension Scaling
For circuits with bounded active dimension, memory and runtime scale with the localized active state rather than the full qubit count.
For QEC workflows, Clifft also supports detector-based post-selection, survivor sampling, and stratified importance sampling for rare-event estimation.
Get Started¶
What's New in 0.3.0¶
Clifft 0.3.0 adds strong simulation for unitary circuits with clifft.probabilities(), which computes exact probabilities for selected full-register computational-basis bitstrings without materializing the full statevector.
It also removes the old compile-time qubit ceiling by moving Pauli mask storage to runtime-width arenas, and improves playground responsiveness on larger circuits.