1
$\begingroup$

I want to simulate a small-distance surface code with either STIM or Qiskit. I want individual control over all the qubits (including the ancillas) to induce controlled errors in my circuit. I want to also get the error syndromes and recovery operation prescribed by some sort of decoder i.e. the Minumum Weight Perfect Matching decoder. Overall, I want a dataset containing each controlled error (on the data qubits) with its error syndromes (on the ancilla qubits in a 2D grid) and the prescribed recovery operation.

What will be a good way to start tackling this problem, i.e. what combination of packages will be helpful and optimal for this thing?

$\endgroup$
2
  • $\begingroup$ Is this circuit noise, or code capacity noise? And do you want the errors as raw circuit errors, or as edges in the match graph like the decoder would use? Also, how small is small. Like, distance 9? $\endgroup$ Commented Jul 4, 2023 at 0:28
  • $\begingroup$ @CraigGidney it's circuit noise, with a distance d=3 surface code. And I'd like to have both the raw circuit errors and the edges in the match graph corresponding to that particular error. The edge graph would be prescribed by the decoder i.e. MWPM $\endgroup$ Commented Jul 5, 2023 at 3:17

1 Answer 1

2
$\begingroup$

Stim doesn't currently support recording errors when sampling from a circuit, but it does support recording errors when sampling from a detector error model via the return_errors=True argument of stim.CompiledDemSampler.sample. It can also replay errors via the recorded_errors_to_replay argument, allowing you to e.g. remove or add one error and redo a simulation.

To get samples you would make a surface code stim circuit, get the dem via stim.Circuit.detector_error_model, get the dem sampler via stim.DetectorErrorModel.compile_sampler, and collect shots+errors via stim.CompiledDemSampler.sample.

To do error correction, take the detection event data returned by the sample method and feed it to pymatching. Use pymatching.Matching.from_detector_error_model to get a decoder and then give your sampled detection event data to pymatching.Matching.decode_batch to predict the observable flip data. Whenever it predicts wrong, that's a logical error.

Interpreting the sampled errors is the hard part that requires a lot of glue coding. The error data is just a flat list of bits, with the k'th bit being set if the k'th error declared in the detector error model fired. You need to turn this list of bits into a representation that's useful for your purposes. Typically this would involve iterating through the dem's instructions (use stim.DetectorErrorModel.flattened to simplify this by inlining loops and coordinate shifting), noting what each error does, creating some dictionary mapping from the error index k to the interpreation. For example, for each error, pull out which detectors it flips and use stim.DetectorErrorModel.get_detector_coordinates to determine if it's an X type or Z type error. Note that you can sort of map back to circuit errors by using stim.Circuit.explain_detector_error_model_errors.

An example of what I've done with this kind of workflow is to count how many times an edge is associated with a logical error, and make heat maps. This sort of tells a story of where the weakest error paths are.

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks @Craig Gidney this was very helpful!! $\endgroup$ Commented Jul 10, 2023 at 13:41

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