I am working with stim's excellent code generator together with pymatching, using stim's generated error model and the glue code in the tutorial here. I am trying to understand better what the output of the decoder means. Specifically, is it correct to say that the output of the decoder xor the logical observable, sampled using OBSERVABLE_INCLUDE
, gives the output of a "stanard" decoder, created using a matching matrix and specifying the number of repetitions as arguments to pymatching's Matching
constructor?
To clarify what I mean, I created a simple example of a distance 3 repetition code, which I decode using both the stim error model based decoder and the "conventionally" defined decoder. I am using an example generated by calling
repc = stim.Circuit.generated(
"repetition_code:memory",
rounds=1,
distance=3)
and adapting it to include an error on qubits 0 and 2 with probability 0.5:
repc = stim.Circuit('''
R 0 1 2 3 4
TICK
CX 0 1 2 3
TICK
CX 2 1 4 3
TICK
MR 1 3
DETECTOR(1, 0) rec[-2]
DETECTOR(3, 0) rec[-1]
X_ERROR(0.5) 0 2
M 0 2 4
DETECTOR(1, 1) rec[-2] rec[-3] rec[-5]
DETECTOR(3, 1) rec[-1] rec[-2] rec[-4]
OBSERVABLE_INCLUDE(0) rec[-1]
''')
m = detector_error_model_to_pymatching_graph(repc.detector_error_model(decompose_errors=True))
shots = repc.compile_detector_sampler().sample(1, append_observables=True)[0]
observable = shots[-1]
print('observable = ', observable)
# decode using glue code and error model
expanded_det = np.resize(shots[:-1], repc.num_detectors + 1)
expanded_det[-1] = 0
print('error model decode', m.decode(expanded_det))
# decode using matching matrix
detector_events = expanded_det[:-1].reshape(-1, 2)
print(detector_events)
m_matrix = pymatching.Matching([[1, 1, 0], [0, 1, 1]], repetitions=2)
print('matrix decode', m_matrix.decode(detector_events.T))
First of all, would it be possible to clarify why the logical observable was chosen to be qubit 4 (rather than, say 0^2^4)?
Secondly, in a shot where there are errors both on 0 and on 2, the output is:
observable = 0
error model decode [0]
[[0 0]
[0 1]]
matrix decode [0 0 1]
In this case my naive expectation would be that the error model decoder will want to flip the logical bit (which would result in a logical error), which is what the conventional decoder does. Does that make sense? If not, I'd be really happy to understand better how to interpret the result of the decoder.