1

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].
Marco Fellous-Asiani
  • 1,514
  • 2
  • 13
  • 33

1 Answers1

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?

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$.

Peter-Jan
  • 1,529
  • 6
  • 22
  • 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? – Marco Fellous-Asiani Mar 12 '24 at 16:37
  • 1
  • the X,Y are only here for graphical representation purposes right?
  • Yes

    – Peter-Jan Mar 12 '24 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

    – Peter-Jan Mar 12 '24 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.

    – Peter-Jan Mar 12 '24 at 16:53
  • My understanding from Gidney's answer here https://quantumcomputing.stackexchange.com/questions/30006/how-does-stims-detector-sampler-work was that the detector do not actually run the circuit to determine the measurement (too expensive). For this reason I am not sure to understand what you mean by "The circuit is ran and then using the measurement results one can check which detectors are violated"? What I mean is that I don't get how it can compare noiseless vs noisy circuits if it runs two instances (noisy+noiseless) without knowing the measurement outcomes on each of them separately. – Marco Fellous-Asiani Mar 12 '24 at 16:57
  • what do you mean with "the detector do not run the circuit"? How do you define a detector? Perhaps this discussion will be easier if you ask this in a separate question. – Peter-Jan Mar 12 '24 at 17:02
  • 1
    I asked a question to be sure I understand the definition of Detector here: https://quantumcomputing.stackexchange.com/questions/37234/detector-definition-in-stim – Marco Fellous-Asiani Mar 13 '24 at 15:30