Back to News
quantum-computing

stim: why would order of CNOT operations affect detectors

unknown
Loading...
5 min read
0 likes
⚡ Quantum Brief
CNOT gate ordering in quantum circuits can break determinism, as demonstrated by two nearly identical circuits where swapping two CNOT layers triggered a "non-deterministic detector" error in the second. The error arises because CNOTs don’t always commute—qubit 0 acts as both control and target in overlapping operations, creating dependencies that alter measurement outcomes when reordered. Stim’s simulator flags this as invalid because detector operations must produce consistent classical bits, but the reordered circuit violates this by introducing ambiguous qubit state histories. The issue underscores a key quantum programming pitfall: assuming gate commutativity without verifying qubit roles, particularly when qubits participate in multiple CNOTs within the same layer. Experts recommend avoiding qubit reuse in single CX commands for clarity, merging them only after confirming deterministic behavior to prevent performance or correctness trade-offs.
AI Audio Summary
0:00 / 0:00
Click to play
Quantum computing technology
Unsplash · Validated Fallback

I have two circuits (below) : first works fine (no complaints from stim); second comes back with a "non-deterministic detector" error. The difference between the two circuits is that the order of the first and second set of CNOTs is swapped; everything else is the same. I wasn't expecting the order of CNOT's to matter so this looks strange. Any explanation for it? circuit #1 : (works ok) R 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 H 27 28 29 30 31 32 33 34 35 TICK CX 0 18 1 19 2 20 3 21 4 22 5 23 6 24 7 25 8 26 27 0 28 1 29 2 30 3 31 4 32 5 33 6 34 7 35 8 TICK CX 3 18 4 19 5 20 6 21 7 22 8 23 0 24 1 25 2 26 27 2 28 0 29 1 30 5 31 3 32 4 33 8 34 6 35 7 TICK CX 10 18 11 19 9 20 13 21 14 22 12 23 16 24 17 25 15 26 27 15 28 16 29 17 30 9 31 10 32 11 33 12 34 13 35 14 TICK CX 9 18 10 19 11 20 12 21 13 22 14 23 15 24 16 25 17 26 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 TICK H 27 28 29 30 31 32 33 34 35 X_ERROR(0.01) 18 19 20 21 22 23 24 25 26 MR 18 19 20 21 22 23 24 25 26 DETECTOR rec[-9] DETECTOR rec[-8] DETECTOR rec[-7] DETECTOR rec[-6] DETECTOR rec[-5] DETECTOR rec[-4] DETECTOR rec[-3] DETECTOR rec[-2] DETECTOR rec[-1] TICK X_ERROR(0.01) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 MR 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 DETECTOR rec[-18] rec[-15] rec[-9] rec[-8] rec[-27] DETECTOR rec[-17] rec[-14] rec[-8] rec[-7] rec[-26] DETECTOR rec[-16] rec[-13] rec[-9] rec[-7] rec[-25] DETECTOR rec[-15] rec[-12] rec[-6] rec[-5] rec[-24] DETECTOR rec[-14] rec[-11] rec[-5] rec[-4] rec[-23] DETECTOR rec[-13] rec[-10] rec[-6] rec[-4] rec[-22] DETECTOR rec[-18] rec[-12] rec[-3] rec[-2] rec[-21] DETECTOR rec[-17] rec[-11] rec[-2] rec[-1] rec[-20] DETECTOR rec[-16] rec[-10] rec[-3] rec[-1] rec[-19] OBSERVABLE_INCLUDE(0) rec[-12] rec[-11] rec[-10] OBSERVABLE_INCLUDE(1) rec[-7] rec[-4] rec[-1] circuit #2 : (non-deterministic detector error) R 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 H 27 28 29 30 31 32 33 34 35 TICK CX 3 18 4 19 5 20 6 21 7 22 8 23 0 24 1 25 2 26 27 2 28 0 29 1 30 5 31 3 32 4 33 8 34 6 35 7 TICK CX 0 18 1 19 2 20 3 21 4 22 5 23 6 24 7 25 8 26 27 0 28 1 29 2 30 3 31 4 32 5 33 6 34 7 35 8 TICK CX 10 18 11 19 9 20 13 21 14 22 12 23 16 24 17 25 15 26 27 15 28 16 29 17 30 9 31 10 32 11 33 12 34 13 35 14 TICK CX 9 18 10 19 11 20 12 21 13 22 14 23 15 24 16 25 17 26 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 TICK H 27 28 29 30 31 32 33 34 35 X_ERROR(0.01) 18 19 20 21 22 23 24 25 26 MR 18 19 20 21 22 23 24 25 26 DETECTOR rec[-9] DETECTOR rec[-8] DETECTOR rec[-7] DETECTOR rec[-6] DETECTOR rec[-5] DETECTOR rec[-4] DETECTOR rec[-3] DETECTOR rec[-2] DETECTOR rec[-1] TICK X_ERROR(0.01) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 MR 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 DETECTOR rec[-18] rec[-15] rec[-9] rec[-8] rec[-27] DETECTOR rec[-17] rec[-14] rec[-8] rec[-7] rec[-26] DETECTOR rec[-16] rec[-13] rec[-9] rec[-7] rec[-25] DETECTOR rec[-15] rec[-12] rec[-6] rec[-5] rec[-24] DETECTOR rec[-14] rec[-11] rec[-5] rec[-4] rec[-23] DETECTOR rec[-13] rec[-10] rec[-6] rec[-4] rec[-22] DETECTOR rec[-18] rec[-12] rec[-3] rec[-2] rec[-21] DETECTOR rec[-17] rec[-11] rec[-2] rec[-1] rec[-20] DETECTOR rec[-16] rec[-10] rec[-3] rec[-1] rec[-19] OBSERVABLE_INCLUDE(0) rec[-12] rec[-11] rec[-10] OBSERVABLE_INCLUDE(1) rec[-7] rec[-4] rec[-1] error : ValueError: The circuit contains non-deterministic detectors. Circuit stack trace: during TICK layer #1 of 7 at instruction #1 [which is R 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35] There is no reason these groups of CNOTs should commute, because in both of them qubit $0$ is the control of a CNOT ($0\to24$ / $0\to18$) and the target of another one ($28\to0$ / $27\to0$). So the differing behaviour is not surprising. My advice is to never use a qubit more than once in a single CX command as it tends to reduce legibility. You can always merge them back at the end once the circuit works if you fear having too many commands might have a negative impact on the performances.

Read Original

Source Information

Source: Quantum Computing Stack Exchange

Discussion

0 professional contributions

Sign in to join this professional discussion.

Be the first to add a constructive contribution.