# Stim error when measuring detectors

I am attempting to compute the circuit for the syndrome extraction of the [[144, 12, 12]] code using stim so as to consider circuit-level noise. Unfortunately, when trying to obtain the detector error model, there is an error in which it says that the circuit contains non-deterministic detectors. That should not be, since all measurements within the Z-basis should be determined.

The logic of the circuit goes as follows (it follows the process of the figure from Fowler et al, but with 6 data qubits):

1. Initialize all data qubits and checks to the |0> state.
2. Make z-checks (Hx generators) to undergo a Hadamard gate.
3. Apply CNOTs from data qubit to x-check and from z-check to data qubit in an ordered manner as described in Bravyi et al.
4. Make z-checks to undergo a Hadamard gate.
5. Measure all checks in the Z base.

The CNOT schedule makes n/2 data qubits interact first with the x-checks while the other n/2 interact first with the z-checks. It is when the data qubits interact with the other half of checks that detection error model cannot be computed. I have trying to compute it both with depolarizing 1 qubit gate and 2 qubit gate errors and with perfect gates and both fail. Is there a significant point that I am missing?

The code follows the structure:

    full_circuit = stim.Circuit()
circuit = stim.Circuit()

ldatas = [i for i in range(self.Hz.shape[1]//2)]
rdatas = [ldatas[-1] + 1 + i for i in range(self.Hz.shape[1]//2)]
xchecks = [rdatas[-1] + 1 + i for i in range(self.Hx.shape[0])]
zchecks = [xchecks[-1] + 1 + i for i in range(self.Hz.shape[0])]

full_circuit.append_operation("R", ldatas + rdatas + xchecks + zchecks)
full_circuit.append_operation("M", xchecks + zchecks)

circuit.append_operation("R", xchecks + zchecks)
circuit.append_operation("H", zchecks)

As = [A1, A2, A3, B1.T, B2.T, B3.T]
Bs = [A1.T, A2.T, A3.T, B1, B2, B3]
# A and B are the polynomials used to make the parity check matrix.

for j in range(len(As)//2):
A = As[j]
B = Bs[j]
for i in range(len(xchecks)):
index_data = np.where(A[i] == 1)[0][0]
circuit.append_operation("CNOT", (zchecks[i],ldatas[index_data]))
circuit.append_operation("DEPOLARIZE2", (zchecks[i], ldatas[index_data]), p)
index_data = np.where(B[i] == 1)[0][0]
circuit.append_operation("CNOT", (rdatas[index_data], xchecks[i]))
circuit.append_operation("DEPOLARIZE2", (rdatas[index_data], xchecks[i]), p)

for j in range(len(As)//2, len(As)):
A = As[j]
B = Bs[j]
for i in range(len(xchecks)):
index_data = np.where(A[i] == 1)[0][0]
circuit.append_operation("CNOT", (zchecks[i],rdatas[index_data]))
circuit.append_operation("DEPOLARIZE2", (zchecks[i], rdatas[index_data]), p)
index_data = np.where(B[i] == 1)[0][0]
circuit.append_operation("CNOT", (ldatas[index_data], xchecks[i]))
circuit.append_operation("DEPOLARIZE2", (ldatas[index_data], xchecks[i]), p)

circuit.append_operation("H", zchecks)
circuit.append_operation("M", xchecks + zchecks)

#  I only record parity of detectors susceptible to X-noise.
for i in range(len(xchecks)):
circuit.append_operation("DETECTOR", [stim.target_rec(i-(4*self.Hz.shape[0])), stim.target_rec(i-(2*self.Hz.shape[0]))])

full_circuit += circuit * (rounds -1)


The first CNOT loop can be computed and the detector error model successfully extracted, nevertheless, upon applying the second for loop (with or without DEPOLARIZE2 errors), I reach a stack trace error.

A simplified version of the circuit can be found in the last figure.

• It's not possible to debug the problem if you don't share the actual stim circuit. But the most likely issue is that you did the operations in a bad order. Commented Nov 3, 2023 at 22:27
• Try only measuring one stabilizer and get that working, then add the operations for a second, and so forth until the error comes back. That will tell you specifically which operation is in the wrong place. Commented Nov 3, 2023 at 22:37
• I have updated the question so as to include the circuit, apologies for that. If I compute only x-check circuit or z-check circuit the circuit works fine (or even if I only compute the first for loop within the stim circuit). Otherwise I face an error. Commented Nov 5, 2023 at 9:49
• You didn't include the full circuit, you included code that generates the circuit. And you didn't include the dependencies of that code, so no one can run it. Commented Nov 5, 2023 at 11:18
• I have now included a figure of a code which undergoes the same error. The top 4 qubits are data qubits, the qubits 4 and 5 are X detectors and the bottom ones are Z-detectors. Upon finding the detector error model I get the error. Commented Nov 6, 2023 at 20:28