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
Print and plot results
[19]:
def print_results(samples):
# Print samples as CSV data.
print(sinter.CSV_HEADER)
for sample in samples:
print(sample.to_csv_line())
def plot_results(samples):
# Render a matplotlib plot of the data.
fig, axis = plt.subplots(1, 2, sharey=True, figsize=(10, 5))
sinter.plot_error_rate(
ax=axis[0],
stats=samples,
group_func=lambda stat: f"Rotated Surface Code d={stat.json_metadata['d']}",
filter_func=lambda stat: stat.decoder == 'bposd',
x_func=lambda stat: stat.json_metadata['p'],
)
sinter.plot_error_rate(
ax=axis[1],
stats=samples,
group_func=lambda stat: f"Rotated Surface Code d={stat.json_metadata['d']}",
filter_func=lambda stat: stat.decoder == 'belief_find',
x_func=lambda stat: stat.json_metadata['p'],
)
axis[0].set_ylabel('Logical Error Rate')
axis[0].set_title('BPOSD')
axis[1].set_title('Belief Find')
for ax in axis:
ax.loglog()
ax.grid()
ax.set_xlabel('Physical Error Rate')
ax.legend()
# Save to file and also open in a window.
fig.savefig('plot.png')
plt.show()
[20]:
print_results(samples)
shots, errors, discards, seconds,decoder,strong_id,json_metadata,custom_counts
20000, 1, 0, 54.5,bposd,0303a22be9c90e4634d6ed94e1115e4012a95cd8a1b9979245877e9feaf1effc,"{""d"":5,""p"":0.001,""rounds"":5}",
20000, 18, 0, 22.8,bposd,bcd97b8394ac1d9f7f140a7a9737f5779c2b2029334c730707b1a9f71f2ce583,"{""d"":5,""p"":0.002,""rounds"":5}",
20000, 63, 0, 30.7,bposd,a6afccb7294493f5ebb587a4c0f1846a65cb089d9735ad505939fff73351089c,"{""d"":5,""p"":0.003,""rounds"":5}",
18368, 105, 0, 41.3,bposd,13b5f4352a9615f6f77853cf7cde4f2081e5fd2292112fcb79b062c3c1e6f657,"{""d"":5,""p"":0.004,""rounds"":5}",
20000, 0, 0, 206.5,bposd,0e10ed2d206f476850b002e6e2c1e74f86e5ab874b0fb9cb7b34979d21f7660d,"{""d"":7,""p"":0.001,""rounds"":7}",
20000, 10, 0, 250.1,bposd,3e4aa306938156ae3b36d57877a5854dceafb973cb156e5c8b757172e03a8ee6,"{""d"":7,""p"":0.002,""rounds"":7}",
20000, 23, 0, 133.1,bposd,2ade9d8daba30a86b93fd4ba88d12fdceae161879ecddac2ccdda4f0de034575,"{""d"":7,""p"":0.003,""rounds"":7}",
9116, 104, 0, 239.6,bposd,2167ca65e894a55566d979b99d3d74149cf1ee07a075da17bd3b5e4b2bb8c544,"{""d"":5,""p"":0.005,""rounds"":5}",
4295, 116, 0, 50.2,bposd,bed63f50f4d7ba8e0597e23b551b7d57494a852bbe36fcf19478e86249666ae2,"{""d"":5,""p"":0.007,""rounds"":5}",
4829, 103, 0, 47.0,bposd,4c35c74393dc4dfd76332ee60075ad2fd4a294a28dc55d67cc9b83d73aa92628,"{""d"":5,""p"":0.006,""rounds"":5}",
2257, 101, 0, 54.2,bposd,da266b16bf536e37877f77be7803e9ce2def18dbf636a86609f5b27b8fcb51a8,"{""d"":5,""p"":0.008,""rounds"":5}",
2158, 118, 0, 18.6,bposd,3f20e95edaf2a47925d135cb521ef2af88e5f44b572ebc573668f77bbfecf5f7,"{""d"":5,""p"":0.009000000000000001,""rounds"":5}",
12153, 104, 0, 460.4,bposd,32687c26b51d4eba5daf11f8b6de1df715afdfc954e0f7fc30d34dab946b9a3f,"{""d"":7,""p"":0.005,""rounds"":7}",
6910, 117, 0, 444.3,bposd,b2a97cc8d2b1ab06782780b3a7ca2014773f328bd511823fc5ded160ac7149bc,"{""d"":7,""p"":0.006,""rounds"":7}",
3852, 108, 0, 81.0,bposd,734dddc5425841a2c8f167af36b2d427dcf29f3d659e1558ced5caef27f37333,"{""d"":7,""p"":0.007,""rounds"":7}",
2777, 124, 0, 80.6,bposd,bc0ee88c6e911af19f954d8f88861f41cbc5d588aa3ed3c3da4e92429de41474,"{""d"":7,""p"":0.008,""rounds"":7}",
1447, 106, 0, 78.5,bposd,27c988a457e547e6865d65103af65353ced739851a4b36947fa59744f1b70b35,"{""d"":7,""p"":0.009000000000000001,""rounds"":7}",
15851, 102, 0, 3228.9,bposd,b265715279732a7732131d3c8332c0c062bb5419c215c7fd93abdcdd039ee904,"{""d"":9,""p"":0.005,""rounds"":9}",
2211, 106, 0, 324.7,bposd,de667c4675f8aac5229a1a4ac7a2f6ae7801c872453da54212d527915eea0e74,"{""d"":9,""p"":0.008,""rounds"":9}",
6688, 109, 0, 692.1,bposd,ebc0c8ec7c8f3e5b1716668472ab41413edefd9d34b1a8318313485b87b8d359,"{""d"":9,""p"":0.006,""rounds"":9}",
1488, 115, 0, 316.1,bposd,4037ce31d75ec9e31fab94344cdcf95e95f5a97bd667f871d0f036916a7b3b28,"{""d"":9,""p"":0.009000000000000001,""rounds"":9}",
3111, 108, 0, 327.5,bposd,67e16e633865eded239743cf0c12b6abb373dfc8baa6661cfbaf9c36934e72ef,"{""d"":9,""p"":0.007,""rounds"":9}",
20000, 0, 0, 62.2,bposd,a7aa4615be3f2b481539401ad605f48e4732cfd3127e391afc9e04b5c3a53649,"{""d"":9,""p"":0.001,""rounds"":9}",
20000, 1, 0, 86.6,bposd,91c94630943a7f4076f7055b2781138b5a948f6864223573c2c6c10adaa4ff8f,"{""d"":9,""p"":0.002,""rounds"":9}",
20000, 10, 0, 90.3,bposd,92988a19b036274bc5ddd25ca94664acb578668f2740a26f13e273d87fd50d08,"{""d"":9,""p"":0.003,""rounds"":9}",
10000, 34, 0, 18.1,bposd,f4933e808158b01006b0e325f3f231cc1d542e8bb63b15c509c7e7305fb1dc9a,"{""d"":7,""p"":0.004,""rounds"":7}",
10000, 28, 0, 39.5,bposd,85ff2f9d9c63dcaac9d02e860ec1e6040cc289a3f738e410f8fe00606d381e01,"{""d"":9,""p"":0.004,""rounds"":9}",
20000, 4, 0, 4.63,belief_find,f90f70d60fa9beeee341f8969140c3901765bb9acc52e3d3c95e57a888f45f5e,"{""d"":5,""p"":0.001,""rounds"":5}",
18815, 101, 0, 6.61,belief_find,1c5757a5030537229bbf1bcb5abad20e3bfbddec3ebdad0f7fffe62a6461ce23,"{""d"":5,""p"":0.003,""rounds"":5}",
5519, 107, 0, 3.11,belief_find,cbe1f8f1afa6a80b58ffa3f65a3300af2bf787f9424f9fb129de30e040e9204d,"{""d"":5,""p"":0.005,""rounds"":5}",
20000, 1, 0, 17.8,belief_find,ea71f1193f8060a70b018df6e25b44c84bee3e8b38deddf3cc40d5df8e7a72af,"{""d"":7,""p"":0.001,""rounds"":7}",
20000, 104, 0, 37.2,belief_find,73fb9b8e29f3dc2f33b5b2f2a95315cf5749378e816f34e389c11169190bfee3,"{""d"":7,""p"":0.003,""rounds"":7}",
20000, 2, 0, 52.9,belief_find,a5078030d4bf4132a97b02357d99db68c75cfb610d8e5dcef182dd937faf6044,"{""d"":9,""p"":0.001,""rounds"":9}",
17913, 108, 0, 88.7,belief_find,f6e3eef02fb0802cdfe9b6eb430c7510e949ef4888b1dc8a5bc707a7c8c88878,"{""d"":9,""p"":0.003,""rounds"":9}",
4769, 107, 0, 15.0,belief_find,3bf4d88d7244d9bcc941fc8d65937564c1bb7c925ac7d5cf566e19246465701f,"{""d"":7,""p"":0.005,""rounds"":7}",
3258, 112, 0, 35.2,belief_find,91d48873c47ea346a3fbcae4fb6c395024980e5d0fefcfe332c3382431630d59,"{""d"":9,""p"":0.005,""rounds"":9}",
1980, 103, 0, 1.55,belief_find,eb07130ce3cb5b71bcdf2de3d67e40477be50f4f4d337c26886ac6449ea4f635,"{""d"":5,""p"":0.007,""rounds"":5}",
1550, 109, 0, 7.55,belief_find,67fb5eb2a748ae75dfc579d14c198e78521548d400d275a622afc475ccc61ad0,"{""d"":7,""p"":0.007,""rounds"":7}",
1192, 100, 0, 21.1,belief_find,c6837da57704b033e10f01c530517e6ed30bf74f6962ff11683a328fa6f44890,"{""d"":9,""p"":0.007,""rounds"":9}",
1364, 104, 0, 1.41,belief_find,cfb0d0fcb1485b110b6711cdc05444de3a9c8446dd1450006446761cb11a1028,"{""d"":5,""p"":0.009000000000000001,""rounds"":5}",
679, 101, 0, 4.45,belief_find,6bab7c20c5ac19b7668a69d882a18494225191102316125848c8926ca7869219,"{""d"":7,""p"":0.009000000000000001,""rounds"":7}",
627, 122, 0, 14.7,belief_find,4c6b04d440614b8336cdfe3241c2118cdebdd2e51ab4cd69a3b6a24dee2825a3,"{""d"":9,""p"":0.009000000000000001,""rounds"":9}",
[21]:
plot_results(samples)
[ ]: