In Stim, is there a easy way to encode qubits into a code state $| 0_L \rangle$ in stabilizer codes, other than constructing an encoding quantum circuit? For example, in Steane's seven-qubit code, can I prepare a simultaneous eigenstate with eigenvalues +1 for the following six stabilizer generators in an easy way?

\begin{equation} IIIXXXX \end{equation} \begin{equation} IXXIIXX \end{equation} \begin{equation} XIXIXIX \end{equation} \begin{equation} IIIZZZZ \end{equation} \begin{equation} IZZIIZZ \end{equation} \begin{equation} ZIZIZIZ \end{equation}

  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    May 4, 2023 at 14:00

2 Answers 2


Measuring the stabilizers puts you in a +1 or -1 eigenstate of each stabilizer. You can measure the stabilizers using the 'MPP' (Measure Pauli products) Instruction. https://github.com/quantumlib/Stim/blob/main/doc/gates.md#the-mpp-instruction

Usually, it does not matter if you initialize into the +1 or -1 eigenstate. The reason is that errors are discovered using detectors, which are parity constraints on measurement outcomes. So if you were to initialize into the -1 eigenstate, you would just expect to continuously measure -1.


As noted in the other answer, you can use 'MPP' to project into the +1 or -1 eigenspace of arbitrary Pauli strings:

# Project into Steane's seven qubit code, up to sign:
# 0123456
# ___XXXX
# _XX__XX
# X_X_X_X
# ___ZZZZ
# _ZZ__ZZ
# Z_Z_Z_Z
MPP X3*X4*X5*X6
MPP X1*X2*X5*X6
MPP X0*X2*X4*X6
# Z stabilizers were already satisfied by starting in |0000000>

This has the downside of not guaranteeing you end up in the +1 eigenstate, but all fault tolerance properties still hold. Just compare future measurements to past measurements, instead of comparing to +1.

I don't recommend trying to force the +1 eigenvalue, as this requires doing extra work on the quantum computer which is expensive and noisy and just generally bad. It's way way easier to focus on tracking the state rather than asserting control over the exact state at all times. It's easier both in theory, using fewer operations, and in practice, requiring fewer capabilities from the hardware. Anyways Stim can do feedback operations, and you can use that to guide the system into the +1 eigenstates:

# Use feedback to flip any inverted signs above
CZ rec[-3] 3
CZ rec[-2] 1
CZ rec[-1] 0

Here the feedback to use is easy to figure out because each $X$ stabilizer has one qubit that only it touches. In general, the feedback to use can be solved for by using stim.TableauSimulator.measure_kickback. The kickback pauli string tells you how to flip the state to exactly match the opposite measurement result.

Not having to solve for the feedback is a great example of why you'd want to be chill about the signs, instead of trying to control them.

  • $\begingroup$ By using MPP, I understand that each stabilizer can be in an eigenstate with an eigenvalue of +1 or -1. However, with this method, each stabilizer becomes independently either an eigenstate with an eigenvalue of +1 or -1, so I don't think they necessarily become simultaneous eigenstates. For example, MPP X3*X4*X5*X6 MPP X1*X2*X5*X6 MPP X0*X2*X4*X6 DETECTOR rec[-3] DETECTOR rec[-2] DETECTOR rec[-1] provide sometimes [False True False], and sometimes [False False True]. How can I use MPP to make all stabilizers have an eigenvalue of +1 or make all stabilizers have an eigenvalue of -1? $\endgroup$
    – lassel
    May 4, 2023 at 14:37
  • $\begingroup$ @dseed You don't need them to be all in the same eigenstate for error correction to work. If you want to do extra work for no benefit in order to force them into an eigenstate, use feedback like I showed in my answer. There's no fundamental distinction between trying to control all signs vs one sign. $\endgroup$ May 4, 2023 at 15:29
  • $\begingroup$ @ Craig Gidney Thank you very much. I understand that point. However, I have another question. What I want to do now is to prepare $| 0_L \rangle$ (or $| 1 _L\rangle$) as the initial state, perform a logical Z measurement at the end, and determine whether a logical X operator was applied during the process or not (or to prepare $| +_L \rangle$ as the initial state, perform a logical X measurement at the end, and determine whether a logical Z operator was applied). With the method of preparing the code state using MPP, is it possible to do this? $\endgroup$
    – lassel
    May 4, 2023 at 18:41
  • $\begingroup$ @dseed Just treat as another stabilizer to prepare. And again don't try to control it, just track it. $\endgroup$ May 4, 2023 at 18:45
  • $\begingroup$ @ Craig Gidney I'm sorry, but I don't quite understand the meaning of "treat as another stabilizer to prepare". Could you please explain it in more detail? $\endgroup$
    – lassel
    May 4, 2023 at 19:03

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.