1
$\begingroup$

I'm trying to implement the $[\![7,1,3]\!]$ Steane code on Stim. My circuit is below:

circuit = stim.Circuit('''
    R 0 1 2 3 4 5 6 7 8 9 10 11 12
    MPP X0*X2*X4*X6
    MPP X3*X4*X5*X6
    MPP X1*X2*X5*X6

    DETECTOR rec[-3]
    DETECTOR rec[-2]
    DETECTOR rec[-1]
                           
    X_ERROR(1) 0
                           
    REPEAT 3 {
        MPP X0*X2*X4*X6
        MPP X3*X4*X5*X6
        MPP X1*X2*X5*X6
        
        MPP Z0*Z2*Z4*Z6
        MPP Z3*Z4*Z5*Z6
        MPP Z1*Z2*Z5*Z6
                                            
        .
        .  
        '''  
    }

The idea is that the first part puts my qubits into a logical state by measuring the $X$ stabilizers. I need to do two things.

  1. Keep the outcomes of the first three MPPs somewhere since these eigenvalues define my logical $\vert 0\rangle$.

  2. I want to implement a correction based on the stabilizer eigenvalues in the REPEAT section. If all of MPP X0 X2 X4 X6, MPP X3 X4 X5 X6 and MPP X1 X2 X5 X6 disagree with the answers in 1., then I have a $Z$ error on qubit $6$. I want to implement a controlled $Z$ gate on qubit $6$ with the control being decided by the aforementioned logic.

What's the best way to do this?

EDIT: Updated circuit based on Craig Gidney's answer.

circuit = stim.Circuit('''
R 0 1 2 3 4 5 6 7 8 9 10 11 12

MPP X0*X2*X4*X6
MPP X3*X4*X5*X6
MPP X1*X2*X5*X6

MPP Z0*Z2*Z4*Z6
MPP Z3*Z4*Z5*Z6
MPP Z1*Z2*Z5*Z6
                       
X_ERROR(1) 0
                       
REPEAT 2 {
    MPP X0*X2*X4*X6
    MPP X3*X4*X5*X6
    MPP X1*X2*X5*X6
    
    MPP Z0*Z2*Z4*Z6
    MPP Z3*Z4*Z5*Z6
    MPP Z1*Z2*Z5*Z6
                                        
    DETECTOR rec[-6] rec[-12]
    DETECTOR rec[-5] rec[-11]
    DETECTOR rec[-4] rec[-10]
    DETECTOR rec[-3] rec[-9]                                      
    DETECTOR rec[-2] rec[-8]
    DETECTOR rec[-1] rec[-7]
}
''')                                            

Indeed, I only get one True on the stabilizer $Z0Z2Z4Z6$ in the first round as that's where the error is.

$\endgroup$

1 Answer 1

2
$\begingroup$

The trick is that you don't. Stim's design assumes that corrections are being handled by the classical control system, not by the quantum circuit itself.

So, for example, if the decoder determines that an X gate is needed to correct an error on qubit 5, then it will apply that correction not by sending microwave pulses to qubit 5 but instead by leaving a note in the control system that says "qubit 5 has an X on it". As Clifford gates are executed, this X will spread around and change but will always remain equal to some product of Pauli operators. Eventually these spreading Paulis will start reaching measurements, and the control system will account for that by intercepting uncorrected measurement results and flipping them (or not, depending on the Pauli) before they reach the overlying algorithm.

Anyways, in your case all you need to do is to declare a DETECTOR comparing each stabilizer measurement to the same measurement from the previous round. And also an OBSERVABLE_INCLUDE comparing the observable measurement at the start to the observable measurement at the end. The goal of decoding is to determine if the observable was flipped, given the detection events.

The DETECTOR instructions that you do have in the circuit currently are wrong, because they are not annotating deterministic measurement sets. Each of the X basis measurements is random, so they are not detectors. But comparing those measurements between rounds does form detectors.

$\endgroup$
1
  • $\begingroup$ Understood, thanks! I've updated the question with a suitable circuit based on your answer. $\endgroup$ Mar 5 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.