I was able to setup the encoding and syndrome check for the example $[[5,1,3]]$ code.
import stim
circuit=stim.Circuit('''
RZ 0 1 2 3
RZ 4
H 0
CY 0 4
H 1
CX 1 4
H 2
CZ 2 0
CZ 2 1
CX 2 4
H 3
CZ 3 0
CZ 3 2
CY 3 4
MPP Y0*Z1*Z3*Y4 X1*Z2*Z3*X4 Z0*Z1*X2*X4 Z0*Z2*Y3*Y4
''')
sampler = circuit.compile_sampler()
print(sampler.sample(shots=8))
The results :
[[1 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 1]
[1 0 0 0]
[1 0 0 0]
[1 0 0 1]
[0 0 0 1]]
The results for the second and third stabilizers are ok (always 0).
The first and fourth stabilizers have a problem; they should also be 0.
This is the encoded 0 state. The encoded 1 state is what you would get if you change the second line in the circuit from RZ 4 to RX 4. The problem happens in both cases. I think the problem might be related to the $Y$ gate; the problem stabilizers have it the ones that are ok do not. "My" $Y$ gate is just $XZ$ not $\imath XZ$ so it's orthogonal and unitary but not hermitian. I have my reasons to stay with this convention. Is there way to work with the real (not complex) version of $Y$ in stim; this might solve the problem.
Fixed circuit : (replaces CY with CX and CZ) :
import stim
circuit=stim.Circuit('''
RZ 0 1 2 3
RX 4
H 0
CX 0 4
CZ 0 4
H 1
CX 1 4
H 2
CZ 2 0
CZ 2 1
CX 2 4
H 3
CZ 3 0
CZ 3 2
CX 3 4
CZ 3 4
MPP Y0*Z1*Z3*Y4 X1*Z2*Z3*X4 Z0*Z1*X2*X4 Z0*Z2*Y3*Y4
''')
sampler = circuit.compile_sampler()
print(sampler.sample(shots=8))
With stim 1.9 these two tests give different results :
def TstOk():
circuit=stim.Circuit()
circuit.append_operation("RZ",[0,1,2,3]);
circuit.append_operation("RX",[4]);
circuit.append_operation("H",[0])
circuit.append_operation("CX",[0,4])
circuit.append_operation("CZ",[0,4])
circuit.append_operation("H",[1])
circuit.append_operation("CX",[1,4])
circuit.append_operation("H",[2])
circuit.append_operation("CZ",[2,0])
circuit.append_operation("CZ",[2,1])
circuit.append_operation("CX",[2,4])
circuit.append_operation("H",[3])
circuit.append_operation("CZ",[3,0])
circuit.append_operation("CZ",[3,2])
circuit.append_operation("CX",[3,4])
circuit.append_operation("CZ",[3,4])
circuit.append_operation("MPP",[
stim.target_y(0),stim.target_combiner(), stim.target_z(1),stim.target_z(3),stim.target_combiner(), stim.target_y(4),
stim.target_x(1),stim.target_combiner(), stim.target_z(2),stim.target_z(3),stim.target_combiner(), stim.target_x(4),
stim.target_z(0),stim.target_combiner(), stim.target_z(1),stim.target_x(2),stim.target_combiner(), stim.target_x(4),
stim.target_z(0),stim.target_combiner(), stim.target_z(2),stim.target_y(3),stim.target_combiner(), stim.target_y(4)
])
sampler = circuit.compile_sampler()
print(sampler.sample(shots=8))
results :
[[False False False False False False True True]
[False False False True True False False True]
[ True True True True False False True True]
[ True True False False True True True True]
[False False True True True True True True]
[False False False True True False True False]
[ True True False True False True False True]
[False False True False False True False True]]
"bas test"
def TstNotOk():
circuit=stim.Circuit('''
RZ 0 1 2 3
RX 4
H 0
CX 0 4
CZ 0 4
H 1
CX 1 4
H 2
CZ 2 0
CZ 2 1
CX 2 4
H 3
CZ 3 0
CZ 3 2
CX 3 4
CZ 3 4
MPP Y0*Z1*Z3*Y4 X1*Z2*Z3*X4 Z0*Z1*X2*X4 Z0*Z2*Y3*Y4
''')
sampler = circuit.compile_sampler()
print(sampler.sample(shots=8))
results are always all False
[[False False False False]
[False False False False]
[False False False False]
[False False False False]
[False False False False]
[False False False False]
[False False False False]
[False False False False]]
print(repr(circuit))
, by the way. $\endgroup$R 0 1 2 3 4 5 6 7 8 ...
for logical 0 orRX 0 1 2 3 4 5 6 7 8 ...
for logical plus. $\endgroup$