# Understanding better the notation DETECTOR(X,Y) rec in Stim

In the tutorial example of Stim, there is a repetition code example.

The circuit is the following:

stim.Circuit('''
R 0 1 2 3 4
TICK
DEPOLARIZE1(0.04) 0 2 4
CX 0 1 2 3
TICK
CX 2 1 4 3
TICK
X_ERROR(0.01) 1 3
MR 1 3
DETECTOR(1, 0) rec[-2]
DETECTOR(3, 0) rec[-1]
REPEAT 24 {
TICK
DEPOLARIZE1(0.04) 0 2 4
CX 0 1 2 3
TICK
CX 2 1 4 3
TICK
X_ERROR(0.01) 1 3
MR 1 3
SHIFT_COORDS(0, 1)
DETECTOR(1, 0) rec[-2] rec[-4]
DETECTOR(3, 0) rec[-1] rec[-3]
}
X_ERROR(0.01) 0 2 4
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]
''')


I am confused by the meaning of the lines such as:

DETECTOR(1, 0) rec[-2]

Question 1: What does X and Y mean in Detector (X,Y)?

In the doc it says it represents "coordinates" but what does it mean? I am a beginner in Stim I only know the very basic of the initial tutorial (hence I am looking for a very basic answer).

Question 2: My understanding of a detector is that it should compare the outcome of two measurements and return TRUE if they are not consistent. For instance if Z measurements output 00 or 11, the detector will return False. If the measurement is 01 or 10 it will return True.

• What does it mean to only put a single measurement outcome in a detector? For instance, the line DETECTOR(1, 0) rec[-2].
• What does it mean to put more than 2 measurement outcomes in a detector? For instance, the line DETECTOR(1, 0) rec[-2] rec[-4].

Question 1: What does X and Y mean in Detector (X,Y)? In the doc it says it represents "coordinates" but what does it mean?

The checks of an error correcting code can be drawn as a Tanner graph. X and Y define the location in the plane to draw the check node that is equivalent to the detector.

What does it mean to only put a single measurement outcome in a detector? For instance, the line DETECTOR(1, 0) rec[-2].

A detector refers to a parity constraint on measurement outcomes. Consider the single qubit circuit: prepare $$|0 \rangle$$, then measure $$M_Z$$. If no noise occurs the measurement should always be 0. Therefore one can construct a weight 1 parity constraint: $$m_1 = 0$$.

What does it mean to put more than 2 measurement outcomes in a detector? For instance, the line DETECTOR(1, 0) rec[-2] rec[-4].

Hopefully an example of a weight 4 stabilizer will help. Consider four qubits being stabilized by $$S_Z=Z_1 Z_2 Z_3 Z_4$$ and $$S_X=X_1 X_2 X_3 X_4$$. If you measure the weight four Z-stabilizer, the measurement outcome is deterministic. If you were to measure a single qubit in the Z basis, this measurement would be non-determinist. But if you were to measure all 4 qubit individually, you can combine the measurement results to find the outcome you would've got by measuring $$S_Z$$ directly. The parity constraint here is $$m_1 \oplus m_2 \oplus m_3 \oplus m_4 = 0$$.

• Thanks. So for Question1: the X,Y are only here for graphical representation purposes right? They do not affect any of the "numerical" estimate (i.e. True/False values) for the detector? For your first answer of Question2: how is the detector supposed to know what happens if the circuit is noiseless (while I have put noise in the circuit). Does it mean that when the detector is called, two circuit instances are ran "in practice": one noiseless and one noisy. If their outcomes disagree on the measurement catched by the detector it returns True. Is it how it works? Mar 12 at 16:37
• - the X,Y are only here for graphical representation purposes right? Yes Mar 12 at 16:49
• "Does it mean that when the detector is called, two circuit instances are ran "in practice": one noiseless and one noisy. If their outcomes disagree on the measurement catched by the detector it returns True. Is it how it works?" Detectors are not called. The circuit is ran and then using the measurement results one can check which detectors are violated Mar 12 at 16:52
• - "how is the detector supposed to know what happens if the circuit is noiseless (while I have put noise in the circuit)" The detector can know this by simulating the noiseless (Clifford) circuit. Mar 12 at 16:53
• I asked a question to be sure I understand the definition of Detector here: quantumcomputing.stackexchange.com/questions/37234/… Mar 13 at 15:30