Stim is very much a circuit focused simulator. It speaks quantum operations, not stabilizer configurations, so you have to convert your table of stabilizers into a stabilizer circuit. This is a bit inconvenient, but ultimately makes Stim much more flexible as a tool (e.g. it has no issues with gauge codes or non-foliated codes).
The "proper" thing for you to do would be to find the encoding circuit for your code and put that into Stim. A fallback strategy could be to use the MPP
instruction (Measure Pauli Product) to measure the stabilizers of the code. For example, here is a circuit that projects into your given code, applies single qubit depolarizing noise, re-measures the stabilizers, and produces detection events based on whether or not each stabilizer was flipped:
MPP X0*Z1*Z2*X3 X1*Z2*Z3*X4 X0*X2*Z3*Z4 Z0*X1*X3*Z4
DEPOLARIZE1(0.001) 0 1 2 3 4
MPP X0*Z1*Z2*X3 X1*Z2*Z3*X4 X0*X2*Z3*Z4 Z0*X1*X3*Z4
DETECTOR rec[-1] rec[-5]
DETECTOR rec[-2] rec[-6]
DETECTOR rec[-3] rec[-7]
DETECTOR rec[-4] rec[-8]
In python, you append MPP instructions like this:
circuit.append_operation("MPP", [
stim.target_x(0),
stim.target_combiner(),
stim.target_z(1),
stim.target_combiner(),
stim.target_z(2),
stim.target_combiner(),
stim.target_x(3),
])
(The target combiners (*
) are needed because you can give multiple products to MPP
.)
Measuring the stabilizers will randomly project the system into their +1 or -1 eigenstates. If for some reason you need the +1 eigenstate you can do a conditional Pauli correction, e.g. CNOT rec[-1] 3
would apply an X gate to qubit 3 if the most recent measurement was True (presumably indicating the associated stabilizer measurement said the system was in the -1 eigenstate). The stim.TableauSimulator.measure_kickback
method is a bit technical but can be used for finding a Pauli correction that won't ruin the other stabilizers of the state.
Anyways, ideally you would know an encoding circuit already. Otherwise, Stim provides a few basic tools like MPP
andmeasure_kickback
to help discover some of the pieces of such a circuit, but doesn't currently have an end-to-end "give me a well formed list of stabilizers and I give you a circuit" helper method.