For a stabilizer code with the stabilizers in canonical form, an encoding circuit has the form that's a product of hadamard gates and general control gates : $H_i C_i(U_i)$. For example for the $[[5,1,3]]$ code, the circuit would be :

$H_{2}C_{2}(Y_{1})$ $H_{3}C_{3}(X_{1})$ $H_{4}C_{4}(X_{1}Z_{2}Z_{3})$ $H_{5}C_{5}(Y_{1}Z_{2}Z_{4})$

$C_i(U_i)$ means apply $U_i$ depending on qubit $i$. The normal $CNOT_{ij}$ would be $C_i(X_j)$. $CZ_{ij}$ gate would be $C_i(Z_j)$; $U_i$ usually needs to be applied to multiple qubits. How would a circuit like this be entered into stim?


1 Answer 1


There currently isn't a controlled Pauli product gate in Stim. You have to decompose it into a series of CX, CY, and CZ gates.

# Apply X1*Y2*Z3 controlled by qubit 0
CX 0 1
CY 0 2
CZ 0 3

# Apply X1*Y2*Z3 if latest measurement result was True
CX rec[-1] 1
CY rec[-1] 2
CZ rec[-1] 3
  • $\begingroup$ A single command would have been more concise (these gates show up often); but it's a minor step to expand them out. Would the example in your answer be counted as 1 gate or 3? (as far as resources : simulation time,...) $\endgroup$
    – unknown
    Oct 11, 2021 at 15:30
  • $\begingroup$ @unknown it's 3 gates. But even a hypothetical compound operation would, under the hood, decompose into the same amount of simulation work. Eg. the tableau simulator measurement code does these sort of operations under the hood, and being able to do them more cheaply than the decomposition would have reduced the worst case execution time. Alas... $\endgroup$ Oct 11, 2021 at 16:01
  • $\begingroup$ If you wanted to be a bit cheeky you could technically abuse MPP to do the compound operation (via lattice surgery style cnots), but it would be inefficient since measurement is the hardest to stimulate. $\endgroup$ Oct 11, 2021 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.