# How to use stim to implement a specific circuit

I'm doing a QEC job, and I want to apply an error like $$U_{err}(\theta) = \prod_j e^{-i\frac{\theta_j}{2}P_j} = \prod_j (I\cos(\frac{\theta_j}{2}) - iP_j\sin(\frac{\theta_j}{2}))$$, where $$\theta_j$$ is some given value, and $$P_j$$ is some Pauli operator. I know that only when $$\theta_j = 0$$ or $$\theta_j = \pm \pi/2$$, then $$U_err$$ is Clifford. I just want to have a function like

def error(Theta, Pauli):
error_circuit = stim.Circuit()

TODO!!!

return error_circuit


to help me to get $$U_{err}$$, but I don't know how.

For multi-term Pauli errors you can append a correlated error to the circuit:

circuit.append(
"CORRELATED_ERROR",
[stim.target_x(2), stim.target_y(3), stim.target_z(5)],
probability,
)


For Clifford errors, you will need to simulate the circuit by driving a tableau simulator or flip simulator, and probabilistically choosing to do a Clifford gate or not when you want the error. Stim circuits don't have any probabilistic-Clifford instructions.