I am attempting to perform a CNOT between two surface code qubits in Stim, based on this paper by Daniel Litinski and Felix von Oppen.

The CNOT they perform is shown in the figure below (Figure 3 from the paper).

CNOT between surface code qubits.

In Stim, how do I go about obtaining the parity of the $ZZ$ and $XX$ measurements? Following this, how would one apply Pauli gates controlled by these parities in Stim?


1 Answer 1


Stim's supported gates documentation includes the gate MXX and the gate MZZ which are exactly the two-qubit parity measurement gates you want:

import stim

lattice_surgery_cnot = stim.Circuit("""
    RX 1
    MZZ 0 1
    MXX 1 2
    MZ 1
    CZ rec[-2] 0
    CX rec[-1] 2 rec[-3] 2

# Verify it's a CNOT
assert lattice_surgery_cnot.has_all_flows([
    stim.Flow("X0 -> X0*X2"),
    stim.Flow("X2 -> X2"),
    stim.Flow("Z0 -> Z0"),
    stim.Flow("Z2 -> Z0*Z2"),

q0: ----MZZ:rec[0]------------Z^rec[1]----------
q1: -RX-MZZ--------MXX:rec[1]-M:rec[2]----------
q2: ---------------MXX--------X^rec[2]-X^rec[0]-

Stim also has MPP, which can Measure Pauli Products with arbitrarily many terms:

MPP X0*X1 Z1*Z2
MPP X2*Y3*Z5
MPP X10*X11*X12*X13*X14*X15*X16*X17
  • $\begingroup$ Thank you for the reply, that is very helpful! At the risk of being verbose, the MPP measurements are considered as one measurement in Stim correct? I.e. if MPP X2*Y3*Z5 is performed as the most recent measurement, then rec[-1] corresponds to the entirety of MPP X2*Y3*Z5? $\endgroup$
    – decaf
    Commented Jun 7 at 16:23
  • $\begingroup$ @MaxwellPoster Correct. $\endgroup$ Commented Jun 7 at 16:31

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.