Skip to content

Commit 7c26e1c

Browse files
Strilancm-mcewen
andcommitted
Add custom samplers, better collection, and better plotting to sinter (#804)
- Add `sinter.Sampler` and `sinter.CompiledSampler` classes - They can go anywhere a Decoder would go, but they are responsible for all parts of the sampling instead of only prediction - Add a new default sampler `perfectionist`, which discards anything with detection events and predicts the observables are not flipped - Improved layout of the progress printouts when collect is running - Sinter decoders can now flag that they want to discard shots by adding an extra byte to the returned observable data, with 0 meaning keep and not-0 meaning discard - Change how `sinter collect` distributes work - Workers are now distributed as widely as possible, instead of all on one task - Workers are now never switched between tasks until their current task is done - Add `sinter plot --point_label_func` argument for drawing text next to data points - Augment `sinter plot --group_func` to support dictionaries with special keys controlling precise grouping behaviors - If group_func returns a dict with a `"color"` key, all items with the same `"color"` value are drawn with the same color - If group_func returns a dict with a `"linestyle"` key, all items with the same `"linestyle"` value are drawn with the same linestyle - If group_func returns a dict with a `"marker"` key, all items with the same `"marker"` value are drawn with the same marker - If group_func returns a dict with a `"label"` key, this forces the label shown in the legend - If group_func returns a dict with an `"order"` key, this takes priority for ordering the legend - `sinter collect --processes` is no longer required (defaults to `"auto"`) - `sinter plot --show` is no longer required (defaults to showing, unless `--out` is specified, unless `--show` is specified) - Group some of sinter's code into private subpackages - Show traditional error bars instead of a filled region for high/low fit when only one data point is present - Add `sinter plot --preprocess_stats_func` - Add `sinter.TaskStats.with_edits` - Add safety error when adding stats that have equal strong ids but differing identifying information (json_metadata or decoder) Some of the sampler design is adapted from @inmzhang's design in #735 Fixes #774 Fixes #682 Fixes #392 --------- Co-authored-by: Matt McEwen <[email protected]>
1 parent 64cf7e1 commit 7c26e1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3000
-1188
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ jobs:
165165
- run: mv dist/* output/stim
166166
- run: mv glue/cirq/dist/* output/stimcirq
167167
- run: mv glue/sample/dist/* output/sinter
168-
- uses: actions/upload-artifact@v3
168+
- uses: actions/upload-artifact@v4.4.0
169169
with:
170170
name: dist
171171
path: |
@@ -185,7 +185,7 @@ jobs:
185185
if: github.ref == 'refs/heads/main'
186186
runs-on: ubuntu-latest
187187
steps:
188-
- uses: actions/download-artifact@v2
188+
- uses: actions/download-artifact@v4.1.7
189189
with:
190190
name: dist
191191
path: dist

dev/gen_sinter_api_reference.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ def main():
4848
```
4949
'''.strip())
5050

51+
replace_rules = []
52+
for package in ['stim', 'sinter']:
53+
p = __import__(package)
54+
for name in dir(p):
55+
x = getattr(p, name)
56+
if isinstance(x, type) and 'class' in str(x):
57+
desired_name = f'{package}.{name}'
58+
if '._' in str(x):
59+
bad_name = str(x).split("'")[1]
60+
replace_rules.append((bad_name, desired_name))
61+
lonely_name = desired_name.split(".")[-1]
62+
for q in ['"', "'"]:
63+
replace_rules.append(('ForwardRef(' + q + lonely_name + q + ')', desired_name))
64+
replace_rules.append(('ForwardRef(' + q + desired_name + q + ')', desired_name))
65+
replace_rules.append((q + desired_name + q, desired_name))
66+
replace_rules.append((q + lonely_name + q, desired_name))
67+
replace_rules.append(('ForwardRef(' + desired_name + ')', desired_name))
68+
replace_rules.append(('ForwardRef(' + lonely_name + ')', desired_name))
69+
5170
for obj in objects:
5271
print()
5372
print(f'<a name="{obj.full_name}"></a>')
@@ -58,7 +77,10 @@ def main():
5877
print(f'# (in class {".".join(obj.full_name.split(".")[:-1])})')
5978
else:
6079
print(f'# (at top-level in the sinter module)')
61-
print('\n'.join(obj.lines))
80+
for line in obj.lines:
81+
for a, b in replace_rules:
82+
line = line.replace(a, b)
83+
print(line)
6284
print("```")
6385

6486

dev/util_gen_stub_file.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dataclasses
2-
import sys
32
import types
43
from typing import Any
54
from typing import Optional, Iterator, List
@@ -9,6 +8,7 @@
98

109
keep = {
1110
"__add__",
11+
"__radd__",
1212
"__eq__",
1313
"__call__",
1414
"__ge__",
@@ -224,17 +224,6 @@ def print_doc(*, full_name: str, parent: object, obj: object, level: int) -> Opt
224224
text += '@abc.abstractmethod\n'
225225
sig_name = f'{term_name}{inspect.signature(obj)}'
226226
text += "\n".join(splay_signature(f"def {sig_name}:"))
227-
text = text.replace('''ForwardRef('sinter.TaskStats')''', 'sinter.TaskStats')
228-
text = text.replace('''ForwardRef('sinter.Task')''', 'sinter.Task')
229-
text = text.replace('''ForwardRef('sinter.Progress')''', 'sinter.Progress')
230-
text = text.replace('''ForwardRef('sinter.Decoder')''', 'sinter.Decoder')
231-
text = text.replace("'AnonTaskStats'", "sinter.AnonTaskStats")
232-
text = text.replace('sinter._decoding_decoder_class.CompiledDecoder', 'sinter.CompiledDecoder')
233-
text = text.replace("'AnonTaskStats'", "sinter.AnonTaskStats")
234-
text = text.replace("'stim.Circuit'", "stim.Circuit")
235-
text = text.replace("'stim.DetectorErrorModel'", "stim.DetectorErrorModel")
236-
text = text.replace("'sinter.CollectionOptions'", "sinter.CollectionOptions")
237-
text = text.replace("'sinter.Fit'", 'sinter.Fit')
238227

239228
# Replace default value lambdas with their source.
240229
if 'lambda' in str(text):

doc/python_api_reference_vDev.md

+1
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ def diagram(
16101610
*,
16111611
tick: Union[None, int, range] = None,
16121612
filter_coords: Iterable[Union[Iterable[float], stim.DemTarget]] = ((),),
1613+
rows: int | None = None,
16131614
) -> 'stim._DiagramHelper':
16141615
"""Returns a diagram of the circuit, from a variety of options.
16151616

0 commit comments

Comments
 (0)