Stim generates multiple (say N many) noisy samples by first collecting one reference sample, then running a Pauli frame simulator N times to track which errors may flip which measurements and eventually combining the N flip patterns with the same reference sample N times to produce N noisy samples. The reference sample is collected by simulating the circuit with no errors.

A relevant StackExchange answer also includes:

For example, on thousand qubit circuits with millions of measurements, Stim can take a few seconds to produce its reference sample. But then it starts spitting out thousands of circuit samples per second. What it's doing is pretending noiseless runs always produce the reference sample, except it's perturbed by the noise in the circuit. A key thing here is that the distinction between different choices of reference sample is removed by adding a 50/50 Z error after every reset and measurement. The set of noiseless samples forms a group and you sample uniformly from that group via these 50/50 Z errors.

Why can Stim pretend that noiseless runs always produce the reference sample and so add a 50/50 Z error after every reset and measurement to make up for the randomness of outcomes when sampling the noiseless circuit N many times? After a measurement for example, it may be that adding this occasional 50/50 Z error accounts for the probability of having either of two eigenstates as the post-measurement states. What if, the probabilities were not 50/50 though?

Thank you!


1 Answer 1


I'll try to give an intuitive idea for where it comes from.

What if, the probabilities were not 50/50 though?

There isn't a case where the probabilities aren't 50/50. If your system is in a stabilizer state, a Pauli product measurement will either commute with the stabilizers (in which case the measurement has a deterministic outcome) or anticommutes with the stabilizers (in which case the measurement is 50/50 random). Stim only supports gates that produce stabilizer states. All the non-50/50 noise channels are layered on top of this 50/50-only foundation, while ensuring they don't break it.

You can think of the 50/50 randomness of a measurement that anticommutes with the stabilizers as coming from the fact that you can apply the any one of the stabilizers to the state, as an operation, without changing the state. But if the measurement anticommutes with the stabilizers, this application would flip the measurement. It's isomorphic to the single qubit case: if you know the Z observable, you are completely uncertain about the X observable, and one way to see that is to notice that applying Z has no effect on the state but applying Z gate right before an X basis measurement would invert its result. You can see this isomorphism must hold because for any anti-commuting pair of Pauli products $A, B$ (e.g. one being the measured observable and the other being a stabilizer of the state), you can find a Clifford operation C such that $CAC^\dagger = X_1$ and $CBC^\dagger = Z_1$. Conjugating everything by a unitary just corresponds to doing analysis in a different basis, so this proves the general case must behave identical to the simple single qubit case.

In a simulation, this "flip that changes the measurement without changing the state" gives a natural way to randomize measurements that anticommute with the stabilizers without changing the state. Just keep randomly applying the stabilizers as operations, and any simulation that would have been incorrectly deterministic will become random. And it will become random in the correct way, where measurements that are individually random but correlated as a group will end up correctly individually random but correlated as a group. Even better, you don't need to keep randomly applying the stabilizers; after you've done a stabilizer once it's randomized and although you could keep randomizing it you don't need to. Flipping a coin twice doesn't make it more random. Anyways, this means the natural place to randomize the stabilizers is one time at the very beginning of their life. Stabilizers always start life by being prepared by a reset gate making a specific state or a measurement collapsing the system to a specific state. At those locations, the new stabilizer is a single-qubit Z observable on the qubit being reset or measured. And thus, you get the randomly applied Z gates.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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