Sinter integration

To enable circuit level noise decoding, the BPOSD and BeliefFind decoders are integrated with the Sinter module of Stim. Sinter is a software tool/library for doing fast monte carlo sampling of quantum error correction circuits. This notebook shows how to obtain a threshold using the BPOSD and BeliefFind decoders.

Generate the circuits

We’ll use the surface code circuits which are built-in to stim.

[12]:
import sinter
import stim
import numpy as np
from ldpc.sinter_decoders import SinterBeliefFindDecoder, SinterBpOsdDecoder
from matplotlib import pyplot as plt
import numpy as np

def generate_example_tasks():
    for p in np.arange(0.001, 0.01, 0.002):
        for d in [5, 7, 9]:
            sc_circuit = stim.Circuit.generated(
                rounds=d,
                distance=d,
                after_clifford_depolarization=p,
                after_reset_flip_probability=p,
                before_measure_flip_probability=p,
                before_round_data_depolarization=p,
                code_task=f'surface_code:rotated_memory_z',
            )
            yield sinter.Task(
                circuit=sc_circuit,
                json_metadata={
                    'p': p,
                    'd': d,
                    'rounds': d,
                },
            )


Run simulations

In the function sinter.collect we pass the SinterBpOsdDecoder and SinterBeliefFindDecoder. For details on which parameters these decoders accept take a look at ldpc/sinter_decoders

[13]:
def run_simulation():
    samples = sinter.collect(
        num_workers=10,
        max_shots=20_000,
        max_errors=100,
        tasks=generate_example_tasks(),
        decoders=['bposd', 'belief_find'],
        custom_decoders={'bposd': SinterBpOsdDecoder(
            max_iter=5,
            bp_method="ms",
            ms_scaling_factor=0.625,
            schedule="parallel",
            osd_method="osd0"),
            "belief_find": SinterBeliefFindDecoder(max_iter=5,
                                                   bp_method="ms",
                                                   ms_scaling_factor=0.625,
                                                   schedule="parallel")},

        print_progress=True,
        save_resume_filepath=f'bposd_surface_code.csv',
    )
    return(samples)
[14]:
samples=run_simulation()
Starting 10 workers...
Running...
    belief_find processes=1  ~core_mins_left=None    (initializing...) {d=7,p=0.001,rounds=7}
          bposd processes=1  ~core_mins_left=None    (initializing...) {d=9,p=0.001,rounds=9}
    belief_find processes=1  ~core_mins_left=None    (initializing...) {d=9,p=0.001,rounds=9}
          bposd processes=1  ~core_mins_left=None    (initializing...) {d=5,p=0.003,rounds=5}
    belief_find processes=1  ~core_mins_left=None    (initializing...) {d=5,p=0.003,rounds=5}
          bposd processes=1  ~core_mins_left=None    (initializing...) {d=7,p=0.003,rounds=7}
    belief_find processes=1  ~core_mins_left=None    (initializing...) {d=7,p=0.003,rounds=7}
          bposd processes=1  ~core_mins_left=None    (initializing...) {d=9,p=0.003,rounds=9}
    belief_find processes=1  ~core_mins_left=None    (initializing...) {d=9,p=0.003,rounds=9}
          bposd processes=1  ~core_mins_left=None    (initializing...) {d=5,p=0.005,rounds=5}
Done collecting