I'm working on making some decoders for surface codes. I know there is a great stabilizer simulator, Stim, so I try using it.

Now, I have a question: can we get what type of error mechanisms actually happen?

We can get detection events and which observables flip by detection_events, observable_flips = sampler.sample(num_shots, separate_observables=True) as written in the getting started book. But, I cannot find a method to get where X, Y, Z errors actually occur in the circuits of each simulation shot.



1 Answer 1


As of 1.12 there's no way to be told which errors were sampled when simulating a circuit.

There is a way to do it when sampling detector error models, because their errors have much simpler structure. stim.DemSampler.sample has an argument return_errors=False that you can set to True. This is what I'd recommend using, at the moment.

In principle you could abuse HERALDED_PAULI_CHANNEL_1 to pull this information out, but it would be very finicky.

There's an open issue to fix this. There's a few reason this functionality hasn't been implemented yet. It's kind of unphysical to rely on this information (though it has its uses, e.g. bootstrapping machine learning decoders). But more seriously... the information is just kind of complicated. Just look at how much stuff is in stim.CircuitLocation:

import stim

c = stim.Circuit.generated(

loc: stim.ExplainedError = c.explain_detector_error_model_errors(
    dem_filter=stim.DetectorErrorModel("error(1) D301 D303"),

ExplainedError {
    dem_error_terms: D301[coords 6,0,13] D303[coords 4,2,13]
    CircuitErrorLocation {
        flipped_pauli_product: Z5[coords 5,1]
        Circuit location stack trace:
            (after 88 TICKs)
            at instruction #84 (a REPEAT 19 block) in the circuit
            after 11 completed iterations
            at instruction #12 (DEPOLARIZE2) in the REPEAT block
            at targets #5 to #6 of the instruction
            resolving to DEPOLARIZE2(0.001) 15[coords 4,2] 5[coords 5,1]

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.