Background
This question was triggered when I wanted to learn about stim and how to use it to run simulations for error correction. The resources I used for learning about stim were basically Craig Gidney's YouTube videos and his getting started-notebook.
Before I state my questions, I want to provide some background information (Everything I write is 'as I understand it' - if my thought process does not make sense anywhere, I'm more than happy for feedback!): The standard example to evaluate 'how good a code' is always goes like this example with the repetition code:
circuit = stim.Circuit.generated(
"repetition_code:memory",
rounds=2,
distance=3,
before_round_data_depolarization=0.04,
before_measure_flip_probability=0.01)
The circuit looks like this:
So, we are basically starting with the data qubits in state $|0\rangle^{\otimes 3}$, and then measure the observables (in this case $Z_1Z_2$ and $Z_2Z_3$) to get a logical $|0\rangle_L$ in repetition code (up to possible -1 outcomes which we don't care about). After performing as many error correction cycles as we feel like, we measure $Z_1$, $Z_2$, as well as $Z_3$, which each are logical $Z$ observables.
The neat thing now is that by measuring not only one logical observable (which in the noiseless case gives exactly as much information as measuring all three of them) but all three, we get once more syndrome information: We know that the product of the outcomes of the $Z_1$ and $Z_2$ measurements in the noiseless case would be equal to the outcome of the $Z_1 Z_2$ stabiliser measurement in the last error correction round. This is crucial: If, for example, in the whole circuit, there was no error happening, but in the very end, right before the logical measurement of the first qubit, there was an X-error, we would be screwed if we'd only measured this first qubit to measure the logical observable. But since we basically get one more round of repetition code error syndromes from these three observables $Z_1$, $Z_2$ and $Z_3$, our decoding algorithm can understand that the whole error syndrome flips the value of the logical observable $Z_1$.
My question
Now, I tried as an exercise to implement the $[\![5,1,3]\!]$ five-qubit perfect code.
It has stabiliser generators $XZZX\mathbb{1}$, $\mathbb{1}XZZX$, $X\mathbb{1}XZZ$ and $ZX\mathbb{1}XZ$.
It is, of course, not hard to implement (I guess non-fault tolerantly, but that is not the topic of this question...) the $[\![5,1,3]\!]$ code in stim:
perfect_code = stim.Circuit('''
H 0 1 2 3
DEPOLARIZE1(0.01) 0 1 2 3
CX 0 4
DEPOLARIZE2(0.01) 0 4
CZ 0 5
DEPOLARIZE2(0.01) 0 5
CZ 0 6
DEPOLARIZE2(0.01) 0 6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OBSERVABLE_INCLUDE(0) rec[-1] rec[-2] rec[-3] rec[-4] rec[-5]
The following screenshot is probably a bit hard to decipher, but I guess if one is used to stim it might still help to see the coarse structure..
My problem/question is the following: I do not believe that we can apply a similar procedure as for the repetition code to protect ourselves from errors happening shortly before the final logical measurements. Here is a complete list of logical $Z$ operators on the [5,1,3] code (ignoring $\pm 1, \pm i$ prefactors).
| $IIYZY$ | $YIIYZ$ | $XIZIX$ | $ZIXXI$ |
| $IXXIZ$ | $YXZXY$ | $XXIZI$ | $ZXYYX$ |
| $IYZYI$ | $YYXZX$ | $XYYXZ$ | $ZYIIY$ |
| $IZIXX$ | $YZYII$ | $XZXYY$ | $ZZZZZ$ |
Looking at it, we can see that by picking $P_1, \dots , P_5$ single qubit Paulis that we measure on the data qubits, the best that we can achieve is that we get information about two different representatives of the logical operator and about one of the stabilisers, e.g.:
$$ P_1 = X\,,\\ P_2 = Z\,, \\P_3 = X\,,\\ P_4 = Z\,,\\ P_5 = Z\,,$$
gives information about the representatives $IZXZI, XZIIZ$ of $Z_L$ as well as the stabiliser $XIXZZ$. In this case, an X-error on the second system would screw everything up and would let us think the outcome is the opposite of what it was supposed to be (and it would be consistent with all other information we have!)
I also wrote some script that tries all possibilities of Paulis one can measure and this is indeed the best one can do I think.
I tried to find this 'phenomenon' in the literature but I never found it mentioned anywhere.
I would be super happy to get any feedback on this. A few precise questions I would be happy to get an answer for:
- I feel like there should be a theory about what I just described, like a theory of when it is possible to reliably measure logical operators (by measuring single Paulis) and when not. I would be very happy to get some references if this has been studied before.
- My intuition is that for CSS codes, the described problems cannot occur. (Proof sketch: For CSS codes, the stabilisers and the logical operators can be chosen as products of only $Z$s or of only $X$s. So, if we measure all data qubits in $Z$ basis, we get another round of $Z$ type syndromes for free as well as the value of logical $Z$ operator we are interested in. If a $Z$-type error would happen shortly before the final, logical measurement, this wouldn't affect the outcome of the single qubit $Z$ measurements. If an $X$-error happens, it would affect the outcomes but it can be detected from the additional stabiliser syndromes.)
- Are there non-CSS codes for which this problem can be avoided?


