sinter 1.15.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sinter might be problematic. Click here for more details.

Files changed (62) hide show
  1. sinter/__init__.py +47 -0
  2. sinter/_collection/__init__.py +10 -0
  3. sinter/_collection/_collection.py +480 -0
  4. sinter/_collection/_collection_manager.py +581 -0
  5. sinter/_collection/_collection_manager_test.py +287 -0
  6. sinter/_collection/_collection_test.py +317 -0
  7. sinter/_collection/_collection_worker_loop.py +35 -0
  8. sinter/_collection/_collection_worker_state.py +259 -0
  9. sinter/_collection/_collection_worker_test.py +222 -0
  10. sinter/_collection/_mux_sampler.py +56 -0
  11. sinter/_collection/_printer.py +65 -0
  12. sinter/_collection/_sampler_ramp_throttled.py +66 -0
  13. sinter/_collection/_sampler_ramp_throttled_test.py +144 -0
  14. sinter/_command/__init__.py +0 -0
  15. sinter/_command/_main.py +39 -0
  16. sinter/_command/_main_collect.py +350 -0
  17. sinter/_command/_main_collect_test.py +482 -0
  18. sinter/_command/_main_combine.py +84 -0
  19. sinter/_command/_main_combine_test.py +153 -0
  20. sinter/_command/_main_plot.py +817 -0
  21. sinter/_command/_main_plot_test.py +445 -0
  22. sinter/_command/_main_predict.py +75 -0
  23. sinter/_command/_main_predict_test.py +36 -0
  24. sinter/_data/__init__.py +20 -0
  25. sinter/_data/_anon_task_stats.py +89 -0
  26. sinter/_data/_anon_task_stats_test.py +35 -0
  27. sinter/_data/_collection_options.py +106 -0
  28. sinter/_data/_collection_options_test.py +24 -0
  29. sinter/_data/_csv_out.py +74 -0
  30. sinter/_data/_existing_data.py +173 -0
  31. sinter/_data/_existing_data_test.py +41 -0
  32. sinter/_data/_task.py +311 -0
  33. sinter/_data/_task_stats.py +244 -0
  34. sinter/_data/_task_stats_test.py +140 -0
  35. sinter/_data/_task_test.py +38 -0
  36. sinter/_decoding/__init__.py +16 -0
  37. sinter/_decoding/_decoding.py +419 -0
  38. sinter/_decoding/_decoding_all_built_in_decoders.py +25 -0
  39. sinter/_decoding/_decoding_decoder_class.py +161 -0
  40. sinter/_decoding/_decoding_fusion_blossom.py +193 -0
  41. sinter/_decoding/_decoding_mwpf.py +302 -0
  42. sinter/_decoding/_decoding_pymatching.py +81 -0
  43. sinter/_decoding/_decoding_test.py +480 -0
  44. sinter/_decoding/_decoding_vacuous.py +38 -0
  45. sinter/_decoding/_perfectionist_sampler.py +38 -0
  46. sinter/_decoding/_sampler.py +72 -0
  47. sinter/_decoding/_stim_then_decode_sampler.py +222 -0
  48. sinter/_decoding/_stim_then_decode_sampler_test.py +192 -0
  49. sinter/_plotting.py +619 -0
  50. sinter/_plotting_test.py +108 -0
  51. sinter/_predict.py +381 -0
  52. sinter/_predict_test.py +227 -0
  53. sinter/_probability_util.py +519 -0
  54. sinter/_probability_util_test.py +281 -0
  55. sinter-1.15.0.data/data/README.md +332 -0
  56. sinter-1.15.0.data/data/readme_example_plot.png +0 -0
  57. sinter-1.15.0.data/data/requirements.txt +4 -0
  58. sinter-1.15.0.dist-info/METADATA +354 -0
  59. sinter-1.15.0.dist-info/RECORD +62 -0
  60. sinter-1.15.0.dist-info/WHEEL +5 -0
  61. sinter-1.15.0.dist-info/entry_points.txt +2 -0
  62. sinter-1.15.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,227 @@
1
+ import pathlib
2
+
3
+ import numpy as np
4
+ import stim
5
+ import tempfile
6
+
7
+ import sinter
8
+
9
+
10
+ def test_predict_on_disk_no_postselect():
11
+ with tempfile.TemporaryDirectory() as tmp_dir:
12
+ tmp_dir = pathlib.Path(tmp_dir)
13
+ dem_path = tmp_dir / 'dem'
14
+ dets_path = tmp_dir / 'dets'
15
+ obs_out_path = tmp_dir / 'obs'
16
+
17
+ with open(dem_path, 'w') as f:
18
+ print("""
19
+ error(0.1) D0 L0
20
+ detector(0, 0, 0, 1) D0
21
+ """, file=f)
22
+ with open(dets_path, 'w') as f:
23
+ print("0", file=f)
24
+ print("1", file=f)
25
+
26
+ sinter.predict_on_disk(
27
+ decoder='pymatching',
28
+ dem_path=dem_path,
29
+ dets_path=dets_path,
30
+ dets_format='01',
31
+ obs_out_path=obs_out_path,
32
+ obs_out_format='01',
33
+ postselect_detectors_with_non_zero_4th_coord=False,
34
+ discards_out_path=None,
35
+ discards_out_format=None,
36
+ )
37
+
38
+ with open(obs_out_path) as f:
39
+ assert f.read() == '0\n1\n'
40
+
41
+
42
+ def test_predict_on_disk_yes_postselect():
43
+ with tempfile.TemporaryDirectory() as tmp_dir:
44
+ tmp_dir = pathlib.Path(tmp_dir)
45
+ dem_path = tmp_dir / 'dem'
46
+ dets_path = tmp_dir / 'dets'
47
+ obs_out_path = tmp_dir / 'obs'
48
+ discards_out_path = tmp_dir / 'discards'
49
+
50
+ with open(dem_path, 'w') as f:
51
+ print("""
52
+ error(0.1) D0 L0
53
+ detector(0, 0, 0, 1) D0
54
+ """, file=f)
55
+ with open(dets_path, 'w') as f:
56
+ print("0", file=f)
57
+ print("1", file=f)
58
+
59
+ sinter.predict_on_disk(
60
+ decoder='pymatching',
61
+ dem_path=dem_path,
62
+ dets_path=dets_path,
63
+ dets_format='01',
64
+ obs_out_path=obs_out_path,
65
+ obs_out_format='01',
66
+ postselect_detectors_with_non_zero_4th_coord=True,
67
+ discards_out_path=discards_out_path,
68
+ discards_out_format='01',
69
+ )
70
+
71
+ with open(obs_out_path) as f:
72
+ assert f.read() == '0\n'
73
+ with open(discards_out_path) as f:
74
+ assert f.read() == '0\n1\n'
75
+
76
+
77
+ def test_predict_discards_bit_packed_none_postselected():
78
+ dem = stim.DetectorErrorModel("""
79
+ error(0.1) D0 L0
80
+ """)
81
+ actual = sinter.predict_discards_bit_packed(
82
+ dem=dem,
83
+ dets_bit_packed=np.packbits(np.array([
84
+ [False],
85
+ [True],
86
+ ], dtype=np.bool_), bitorder='little', axis=1),
87
+ postselect_detectors_with_non_zero_4th_coord=True,
88
+ )
89
+ np.testing.assert_array_equal(
90
+ actual,
91
+ [False, False],
92
+ )
93
+
94
+
95
+ def test_predict_discards_bit_packed_some_postselected():
96
+ dem = stim.DetectorErrorModel("""
97
+ error(0.1) D0 L0
98
+ detector(0, 0, 0, 1) D0
99
+ """)
100
+ actual = sinter.predict_discards_bit_packed(
101
+ dem=dem,
102
+ dets_bit_packed=np.packbits(np.array([
103
+ [False],
104
+ [True],
105
+ ], dtype=np.bool_), bitorder='little', axis=1),
106
+ postselect_detectors_with_non_zero_4th_coord=True,
107
+ )
108
+ np.testing.assert_array_equal(
109
+ actual,
110
+ [False, True],
111
+ )
112
+
113
+
114
+ def test_predict_observables_bit_packed():
115
+ dem = stim.DetectorErrorModel("""
116
+ error(0.1) D0 L0
117
+ """)
118
+
119
+ actual = sinter.predict_observables_bit_packed(
120
+ dem=dem,
121
+ dets_bit_packed=np.packbits(np.array([
122
+ [False],
123
+ [True],
124
+ ], dtype=np.bool_), bitorder='little', axis=1),
125
+ decoder='pymatching',
126
+ )
127
+ np.testing.assert_array_equal(
128
+ np.unpackbits(actual, bitorder='little', count=1, axis=1),
129
+ [
130
+ [False],
131
+ [True],
132
+ ],
133
+ )
134
+
135
+
136
+ def test_predict_observables():
137
+ dem = stim.DetectorErrorModel("""
138
+ error(0.1) D0 L0
139
+ """)
140
+
141
+ actual = sinter.predict_observables(
142
+ dem=dem,
143
+ dets=np.packbits(np.array([
144
+ [False],
145
+ [True],
146
+ ], dtype=np.bool_), bitorder='little', axis=1),
147
+ decoder='pymatching',
148
+ bit_pack_result=True,
149
+ )
150
+ np.testing.assert_array_equal(
151
+ np.unpackbits(actual, bitorder='little', count=1, axis=1),
152
+ [
153
+ [False],
154
+ [True],
155
+ ],
156
+ )
157
+
158
+ actual = sinter.predict_observables(
159
+ dem=dem,
160
+ dets=np.array([
161
+ [False],
162
+ [True],
163
+ ], dtype=np.bool_),
164
+ decoder='pymatching',
165
+ bit_pack_result=True,
166
+ )
167
+ np.testing.assert_array_equal(
168
+ np.unpackbits(actual, bitorder='little', count=1, axis=1),
169
+ [
170
+ [False],
171
+ [True],
172
+ ],
173
+ )
174
+
175
+ actual = sinter.predict_observables(
176
+ dem=dem,
177
+ dets=np.packbits(np.array([
178
+ [False],
179
+ [True],
180
+ ], dtype=np.bool_), bitorder='little', axis=1),
181
+ decoder='pymatching',
182
+ bit_pack_result=False,
183
+ )
184
+ np.testing.assert_array_equal(
185
+ actual,
186
+ [[False], [True]],
187
+ )
188
+
189
+ actual = sinter.predict_observables(
190
+ dem=dem,
191
+ dets=np.array([
192
+ [False],
193
+ [True],
194
+ ], dtype=np.bool_),
195
+ decoder='pymatching',
196
+ bit_pack_result=False,
197
+ )
198
+ np.testing.assert_array_equal(
199
+ actual,
200
+ [[False], [True]],
201
+ )
202
+
203
+ actual = sinter.predict_observables(
204
+ dem=dem,
205
+ dets=np.packbits(np.array([
206
+ [False],
207
+ [True],
208
+ ], dtype=np.bool_), bitorder='little', axis=1),
209
+ decoder='pymatching',
210
+ )
211
+ np.testing.assert_array_equal(
212
+ actual,
213
+ [[False], [True]],
214
+ )
215
+
216
+ actual = sinter.predict_observables(
217
+ dem=dem,
218
+ dets=np.array([
219
+ [False],
220
+ [True],
221
+ ], dtype=np.bool_),
222
+ decoder='pymatching',
223
+ )
224
+ np.testing.assert_array_equal(
225
+ actual,
226
+ [[False], [True]],
227
+ )