I want to use Stim to calculate logical error rates with circuits that involve post-selection on measurement outcomes. Is it possible to do so with Stim and if yes, how do I go about it?

To provide context, I want to calculate thresholds for codes where syndrome measurement, and logical gate, circuits involve entanglement purification. An example of such a circuit is found in Nickerson, et al. Freely Scalable Quantum Technologies Using Cells of 5-to-50 Qubits with Very Lossy and Noisy Photonic Links. Phys. Rev. X 4, 041041 (2014). Open access: preprint.

Nickerson et al. implement surface code stabilizer measurements by using a purified GHZ state as a resource state. In the image below, schematic (a) shows the usual surface code stabilizer measurement circuit and schematic (b) shows the GHZ state-based approach.

enter image description here

Construction of the purified GHZ state involves post-selection, as shown in the schematic below,

enter image description here

(All images in this post are from Nickerson, et al. Freely Scalable Quantum Technologies Using Cells of 5-to-50 Qubits with Very Lossy and Noisy Photonic Links. Phys. Rev. X 4, 041041 (2014).)


1 Answer 1


For simple cases, what you should do is just take a lot of samples, compute which ones were postselected, and discard them. This will work fine as long as the discard rate is not too high (e.g. less than 95%) and the circuit doesn't change in response to postselections. This strategy is what sinter does. sinter collect takes an optional --postselected_detectors_predicate argument which will discard any shots with detection events from any detector satisfying the predicate. It's what I used for "Cleaner magic states with hook injection".

For complex cases, you will run into the issue that Stim's detection event sampler doesn't support classically controlled non-Pauli gates. For example, consider a 15-to-1 magic state factory where each of the 15 inputs is a postselected injection that succeeds 50% of the time. In practice you would repeatedly attempt to prepare each input until you had all 15, which is pretty quick. But "repeat until it works" requires things like saying "reset all the qubits if there was a detection event". That's a classically controlled non-Pauli gate.

One thing you could do to deal with a complex case is to characterize the behaviors of the individual pieces with postselection, and then replace those pieces with mocks that produce outputs that follow the characterization. For example, figure out the postselected error rate of the magic state injection, and then replace them with unconditional preparation of a logical state with that error rate.

If you really need it to be complicated and perfect... you can use Stim's tableau simulator to do classically controlled Cliffords. You can drive that simulator with python, so the only limit on functionality is your imagination and your programming ability. I don't really recommend this route, as it will be very time consuming. The actual sampling rate in the end will be a thousand times slower. Maybe ten thousand times slower. You'll have to do the conversion from measurements to detection events yourself. You'll have to figure out some way to explain to a decoder what you are doing. There will be a lot of work to stray outside the golden path, because you'll need to do a lot of path building.


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.