Leakage-aware stabilizer simulation built on top of stim.TableauSimulator.
From PyPI:
pip install leakysimFrom source:
git clone https://github.com/inmzhang/leaky.git
cd leaky
pip install .import leaky
import stim
channel = leaky.LeakyPauliChannel(2)
channel.add_transition(
leaky.LeakageStatus(status=[0, 0]),
leaky.LeakageStatus(status=[0, 1]),
"XI",
1.0,
)
sim = leaky.Simulator(4, [channel], seed=1234)
circuit = stim.Circuit("""
R 0 1 2 3
X 0 2
CNOT 0 1 2 3
I[leaky<0>] 0 1 2 3
M 0 1 2 3
""")
sim.do_circuit(circuit)
print(sim.current_measurement_record().tolist()) # [0, 2, 0, 2]LeakageStatus: per-qubit leakage labels.0means computational space.LeakyPauliChannel: leakage transitions plus Pauli corrections on qubits that stay computational.Simulator: executesstim.Circuitobjects while tracking leakage.ReadoutStrategy: controls how leaked measurement results are reported.generalized_pauli_twirling(...): converts Kraus operators into aLeakyPauliChannel.
- Use
I[leaky<n>] ...in a Stim circuit to apply thenth channel bound to a simulator. Simulator(seed=...)only seeds that simulator instance.apply_leaky_channel(...)expects raw qubit targets and broadcasts in groups ofchannel.num_qubits.- For
ReadoutStrategy.RawLabel, leaked measurements are reported as2,3, ... instead of projected bits.
The shipped stub file is the canonical Python API reference: