Skip to content

Commit dccdc0d

Browse files
authored
Cleanup various minor issues in preparation for release (#949)
Autoformat the code Fixes #948 Fixes #947 Fixes #946 Fixes #935 Fixes #865 Fixes #858
1 parent 05a41f6 commit dccdc0d

Some content is hidden

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

46 files changed

+424
-323
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ build.ninja
4343
.pytest_cache
4444
node_modules
4545
MODULE.bazel.lock
46+
.ninja_lock

doc/python_api_reference_vDev.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def append(
849849
@overload
850850
def append(
851851
self,
852-
name: Union[stim.CircuitOperation, stim.CircuitRepeatBlock],
852+
name: Union[stim.CircuitInstruction, stim.CircuitRepeatBlock, stim.Circuit],
853853
) -> None:
854854
pass
855855
def append(
@@ -1102,6 +1102,9 @@ def compile_m2d_converter(
11021102
) -> stim.CompiledMeasurementsToDetectionEventsConverter:
11031103
"""Creates a measurement-to-detection-event converter for the given circuit.
11041104

1105+
The converter can efficiently compute detection events and observable flips
1106+
from raw measurement data.
1107+
11051108
The converter uses a noiseless reference sample, collected from the circuit
11061109
using stim's Tableau simulator during initialization of the converter, as a
11071110
baseline for determining what the expected value of a detector is.
@@ -2466,9 +2469,10 @@ def likeliest_error_sat_problem(
24662469
"""Makes a maxSAT problem for the circuit's likeliest undetectable logical error.
24672470

24682471
The output is a string describing the maxSAT problem in WDIMACS format
2469-
(see https://maxhs.org/docs/wdimacs.html). The optimal solution to the
2470-
problem is the highest likelihood set of error mechanisms that combine to
2471-
flip any logical observable while producing no detection events).
2472+
(see https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html). The
2473+
optimal solution to the problem is the highest likelihood set of error
2474+
mechanisms that combine to flip any logical observable while producing no
2475+
detection events).
24722476

24732477
If there are any errors with probability p > 0.5, they are inverted so
24742478
that the resulting weight ends up being positive. If there are errors
@@ -2965,11 +2969,11 @@ def shortest_error_sat_problem(
29652969
"""Makes a maxSAT problem of the circuit's distance, that other tools can solve.
29662970

29672971
The output is a string describing the maxSAT problem in WDIMACS format
2968-
(see https://maxhs.org/docs/wdimacs.html). The optimal solution to the
2969-
problem is the fault distance of the circuit (the minimum number of error
2970-
mechanisms that combine to flip any logical observable while producing no
2971-
detection events). This method ignores the probabilities of the error
2972-
mechanisms since it only cares about minimizing the number of errors
2972+
(see https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html). The
2973+
optimal solution to the problem is the fault distance of the circuit (the
2974+
minimum number of error mechanisms that combine to flip any logical observable
2975+
while producing no detection events). This method ignores the probabilities of
2976+
the error mechanisms since it only cares about minimizing the number of errors
29732977
triggered.
29742978

29752979
There are many tools that can solve maxSAT problems in WDIMACS format.
@@ -3449,7 +3453,7 @@ def to_crumble_url(
34493453
... CNOT 0 1
34503454
... S 1
34513455
... ''').to_crumble_url()
3452-
'https://algassert.com/crumble#circuit=H_0;CX_0_1;S_1'
3456+
'https://algassert.com/crumble#circuit=H_0;CX_0_1;S_1_'
34533457

34543458
>>> circuit = stim.Circuit('''
34553459
... M(0.25) 0 1 2
@@ -3459,7 +3463,7 @@ def to_crumble_url(
34593463
... ''')
34603464
>>> err = circuit.shortest_graphlike_error(canonicalize_circuit_errors=True)
34613465
>>> circuit.to_crumble_url(skip_detectors=True, mark={1: err})
3462-
'https://algassert.com/crumble#circuit=;TICK;MARKX(1)1;MARKX(1)2;MARKX(1)0;TICK;M(0.25)0_1_2;OI(0)rec[-1]'
3466+
'https://algassert.com/crumble#circuit=;TICK;MARKX(1)1;MARKX(1)2;MARKX(1)0;TICK;M(0.25)0_1_2;OI(0)rec[-1]_'
34633467
"""
34643468
```
34653469

@@ -7086,9 +7090,10 @@ def append(
70867090
"""Appends an instruction to the detector error model.
70877091

70887092
Args:
7089-
instruction: Either the name of an instruction, a stim.DemInstruction, or a
7090-
stim.DemRepeatBlock. The `parens_arguments`, `targets`, and 'tag'
7091-
arguments should be given if and only if the instruction is a name.
7093+
instruction: Either the name of an instruction, a stim.DemInstruction, a
7094+
stim.DemRepeatBlock. or a stim.DetectorErrorModel. The
7095+
`parens_arguments`, `targets`, and 'tag' arguments should be given iff
7096+
the instruction is a name.
70927097
parens_arguments: Numeric values parameterizing the instruction. The numbers
70937098
inside parentheses in a detector error model file (eg. the `0.25` in
70947099
`error(0.25) D0`). This argument can be given either a list of doubles,
@@ -7675,7 +7680,7 @@ def shortest_graphlike_error(
76757680
the race to find a solution.
76767681

76777682
Args:
7678-
ignore_ungraphlike_errors: Defaults to False. When False, an exception is
7683+
ignore_ungraphlike_errors: Defaults to True. When False, an exception is
76797684
raised if there are any errors in the model that are not graphlike. When
76807685
True, those errors are skipped as if they weren't present.
76817686

doc/stim.pyi

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class Circuit:
310310
@overload
311311
def append(
312312
self,
313-
name: Union[stim.CircuitOperation, stim.CircuitRepeatBlock],
313+
name: Union[stim.CircuitInstruction, stim.CircuitRepeatBlock, stim.Circuit],
314314
) -> None:
315315
pass
316316
def append(
@@ -538,6 +538,9 @@ class Circuit:
538538
) -> stim.CompiledMeasurementsToDetectionEventsConverter:
539539
"""Creates a measurement-to-detection-event converter for the given circuit.
540540
541+
The converter can efficiently compute detection events and observable flips
542+
from raw measurement data.
543+
541544
The converter uses a noiseless reference sample, collected from the circuit
542545
using stim's Tableau simulator during initialization of the converter, as a
543546
baseline for determining what the expected value of a detector is.
@@ -1794,9 +1797,10 @@ class Circuit:
17941797
"""Makes a maxSAT problem for the circuit's likeliest undetectable logical error.
17951798
17961799
The output is a string describing the maxSAT problem in WDIMACS format
1797-
(see https://maxhs.org/docs/wdimacs.html). The optimal solution to the
1798-
problem is the highest likelihood set of error mechanisms that combine to
1799-
flip any logical observable while producing no detection events).
1800+
(see https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html). The
1801+
optimal solution to the problem is the highest likelihood set of error
1802+
mechanisms that combine to flip any logical observable while producing no
1803+
detection events).
18001804
18011805
If there are any errors with probability p > 0.5, they are inverted so
18021806
that the resulting weight ends up being positive. If there are errors
@@ -2216,11 +2220,11 @@ class Circuit:
22162220
"""Makes a maxSAT problem of the circuit's distance, that other tools can solve.
22172221
22182222
The output is a string describing the maxSAT problem in WDIMACS format
2219-
(see https://maxhs.org/docs/wdimacs.html). The optimal solution to the
2220-
problem is the fault distance of the circuit (the minimum number of error
2221-
mechanisms that combine to flip any logical observable while producing no
2222-
detection events). This method ignores the probabilities of the error
2223-
mechanisms since it only cares about minimizing the number of errors
2223+
(see https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html). The
2224+
optimal solution to the problem is the fault distance of the circuit (the
2225+
minimum number of error mechanisms that combine to flip any logical observable
2226+
while producing no detection events). This method ignores the probabilities of
2227+
the error mechanisms since it only cares about minimizing the number of errors
22242228
triggered.
22252229
22262230
There are many tools that can solve maxSAT problems in WDIMACS format.
@@ -2672,7 +2676,7 @@ class Circuit:
26722676
... CNOT 0 1
26732677
... S 1
26742678
... ''').to_crumble_url()
2675-
'https://algassert.com/crumble#circuit=H_0;CX_0_1;S_1'
2679+
'https://algassert.com/crumble#circuit=H_0;CX_0_1;S_1_'
26762680
26772681
>>> circuit = stim.Circuit('''
26782682
... M(0.25) 0 1 2
@@ -2682,7 +2686,7 @@ class Circuit:
26822686
... ''')
26832687
>>> err = circuit.shortest_graphlike_error(canonicalize_circuit_errors=True)
26842688
>>> circuit.to_crumble_url(skip_detectors=True, mark={1: err})
2685-
'https://algassert.com/crumble#circuit=;TICK;MARKX(1)1;MARKX(1)2;MARKX(1)0;TICK;M(0.25)0_1_2;OI(0)rec[-1]'
2689+
'https://algassert.com/crumble#circuit=;TICK;MARKX(1)1;MARKX(1)2;MARKX(1)0;TICK;M(0.25)0_1_2;OI(0)rec[-1]_'
26862690
"""
26872691
def to_file(
26882692
self,
@@ -5539,9 +5543,10 @@ class DetectorErrorModel:
55395543
"""Appends an instruction to the detector error model.
55405544
55415545
Args:
5542-
instruction: Either the name of an instruction, a stim.DemInstruction, or a
5543-
stim.DemRepeatBlock. The `parens_arguments`, `targets`, and 'tag'
5544-
arguments should be given if and only if the instruction is a name.
5546+
instruction: Either the name of an instruction, a stim.DemInstruction, a
5547+
stim.DemRepeatBlock. or a stim.DetectorErrorModel. The
5548+
`parens_arguments`, `targets`, and 'tag' arguments should be given iff
5549+
the instruction is a name.
55455550
parens_arguments: Numeric values parameterizing the instruction. The numbers
55465551
inside parentheses in a detector error model file (eg. the `0.25` in
55475552
`error(0.25) D0`). This argument can be given either a list of doubles,
@@ -6037,7 +6042,7 @@ class DetectorErrorModel:
60376042
the race to find a solution.
60386043
60396044
Args:
6040-
ignore_ungraphlike_errors: Defaults to False. When False, an exception is
6045+
ignore_ungraphlike_errors: Defaults to True. When False, an exception is
60416046
raised if there are any errors in the model that are not graphlike. When
60426047
True, those errors are skipped as if they weren't present.
60436048

glue/python/src/stim/__init__.pyi

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class Circuit:
310310
@overload
311311
def append(
312312
self,
313-
name: Union[stim.CircuitOperation, stim.CircuitRepeatBlock],
313+
name: Union[stim.CircuitInstruction, stim.CircuitRepeatBlock, stim.Circuit],
314314
) -> None:
315315
pass
316316
def append(
@@ -538,6 +538,9 @@ class Circuit:
538538
) -> stim.CompiledMeasurementsToDetectionEventsConverter:
539539
"""Creates a measurement-to-detection-event converter for the given circuit.
540540
541+
The converter can efficiently compute detection events and observable flips
542+
from raw measurement data.
543+
541544
The converter uses a noiseless reference sample, collected from the circuit
542545
using stim's Tableau simulator during initialization of the converter, as a
543546
baseline for determining what the expected value of a detector is.
@@ -1794,9 +1797,10 @@ class Circuit:
17941797
"""Makes a maxSAT problem for the circuit's likeliest undetectable logical error.
17951798
17961799
The output is a string describing the maxSAT problem in WDIMACS format
1797-
(see https://maxhs.org/docs/wdimacs.html). The optimal solution to the
1798-
problem is the highest likelihood set of error mechanisms that combine to
1799-
flip any logical observable while producing no detection events).
1800+
(see https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html). The
1801+
optimal solution to the problem is the highest likelihood set of error
1802+
mechanisms that combine to flip any logical observable while producing no
1803+
detection events).
18001804
18011805
If there are any errors with probability p > 0.5, they are inverted so
18021806
that the resulting weight ends up being positive. If there are errors
@@ -2216,11 +2220,11 @@ class Circuit:
22162220
"""Makes a maxSAT problem of the circuit's distance, that other tools can solve.
22172221
22182222
The output is a string describing the maxSAT problem in WDIMACS format
2219-
(see https://maxhs.org/docs/wdimacs.html). The optimal solution to the
2220-
problem is the fault distance of the circuit (the minimum number of error
2221-
mechanisms that combine to flip any logical observable while producing no
2222-
detection events). This method ignores the probabilities of the error
2223-
mechanisms since it only cares about minimizing the number of errors
2223+
(see https://jix.github.io/varisat/manual/0.2.0/formats/dimacs.html). The
2224+
optimal solution to the problem is the fault distance of the circuit (the
2225+
minimum number of error mechanisms that combine to flip any logical observable
2226+
while producing no detection events). This method ignores the probabilities of
2227+
the error mechanisms since it only cares about minimizing the number of errors
22242228
triggered.
22252229
22262230
There are many tools that can solve maxSAT problems in WDIMACS format.
@@ -2672,7 +2676,7 @@ class Circuit:
26722676
... CNOT 0 1
26732677
... S 1
26742678
... ''').to_crumble_url()
2675-
'https://algassert.com/crumble#circuit=H_0;CX_0_1;S_1'
2679+
'https://algassert.com/crumble#circuit=H_0;CX_0_1;S_1_'
26762680
26772681
>>> circuit = stim.Circuit('''
26782682
... M(0.25) 0 1 2
@@ -2682,7 +2686,7 @@ class Circuit:
26822686
... ''')
26832687
>>> err = circuit.shortest_graphlike_error(canonicalize_circuit_errors=True)
26842688
>>> circuit.to_crumble_url(skip_detectors=True, mark={1: err})
2685-
'https://algassert.com/crumble#circuit=;TICK;MARKX(1)1;MARKX(1)2;MARKX(1)0;TICK;M(0.25)0_1_2;OI(0)rec[-1]'
2689+
'https://algassert.com/crumble#circuit=;TICK;MARKX(1)1;MARKX(1)2;MARKX(1)0;TICK;M(0.25)0_1_2;OI(0)rec[-1]_'
26862690
"""
26872691
def to_file(
26882692
self,
@@ -5539,9 +5543,10 @@ class DetectorErrorModel:
55395543
"""Appends an instruction to the detector error model.
55405544
55415545
Args:
5542-
instruction: Either the name of an instruction, a stim.DemInstruction, or a
5543-
stim.DemRepeatBlock. The `parens_arguments`, `targets`, and 'tag'
5544-
arguments should be given if and only if the instruction is a name.
5546+
instruction: Either the name of an instruction, a stim.DemInstruction, a
5547+
stim.DemRepeatBlock. or a stim.DetectorErrorModel. The
5548+
`parens_arguments`, `targets`, and 'tag' arguments should be given iff
5549+
the instruction is a name.
55455550
parens_arguments: Numeric values parameterizing the instruction. The numbers
55465551
inside parentheses in a detector error model file (eg. the `0.25` in
55475552
`error(0.25) D0`). This argument can be given either a list of doubles,
@@ -6037,7 +6042,7 @@ class DetectorErrorModel:
60376042
the race to find a solution.
60386043
60396044
Args:
6040-
ignore_ungraphlike_errors: Defaults to False. When False, an exception is
6045+
ignore_ungraphlike_errors: Defaults to True. When False, an exception is
60416046
raised if there are any errors in the model that are not graphlike. When
60426047
True, those errors are skipped as if they weren't present.
60436048

src/stim/circuit/circuit.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ void Circuit::safe_append(CircuitInstruction operation, bool block_fusion) {
331331
}
332332
}
333333

334-
void Circuit::safe_append_ua(std::string_view gate_name, const std::vector<uint32_t> &targets, double singleton_arg, std::string_view tag) {
334+
void Circuit::safe_append_ua(
335+
std::string_view gate_name, const std::vector<uint32_t> &targets, double singleton_arg, std::string_view tag) {
335336
const auto &gate = GATE_DATA.at(gate_name);
336337

337338
std::vector<GateTarget> converted;
@@ -344,7 +345,10 @@ void Circuit::safe_append_ua(std::string_view gate_name, const std::vector<uint3
344345
}
345346

346347
void Circuit::safe_append_u(
347-
std::string_view gate_name, const std::vector<uint32_t> &targets, const std::vector<double> &args, std::string_view tag) {
348+
std::string_view gate_name,
349+
const std::vector<uint32_t> &targets,
350+
const std::vector<double> &args,
351+
std::string_view tag) {
348352
const auto &gate = GATE_DATA.at(gate_name);
349353

350354
std::vector<GateTarget> converted;
@@ -806,10 +810,7 @@ Circuit Circuit::without_tags() const {
806810
Circuit result;
807811
for (CircuitInstruction inst : operations) {
808812
if (inst.gate_type == GateType::REPEAT) {
809-
result.append_repeat_block(
810-
inst.repeat_block_rep_count(),
811-
inst.repeat_block_body(*this).without_tags(),
812-
"");
813+
result.append_repeat_block(inst.repeat_block_rep_count(), inst.repeat_block_body(*this).without_tags(), "");
813814
} else {
814815
inst.tag = "";
815816
result.safe_append(inst);

src/stim/circuit/circuit.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,17 @@ struct Circuit {
108108
/// Safely adds an operation at the end of the circuit, copying its data into the circuit's jagged data as needed.
109109
void safe_append(CircuitInstruction operation, bool block_fusion = false);
110110
/// Safely adds an operation at the end of the circuit, copying its data into the circuit's jagged data as needed.
111-
void safe_append_ua(std::string_view gate_name, const std::vector<uint32_t> &targets, double singleton_arg, std::string_view tag = "");
111+
void safe_append_ua(
112+
std::string_view gate_name,
113+
const std::vector<uint32_t> &targets,
114+
double singleton_arg,
115+
std::string_view tag = "");
112116
/// Safely adds an operation at the end of the circuit, copying its data into the circuit's jagged data as needed.
113117
void safe_append_u(
114-
std::string_view gate_name, const std::vector<uint32_t> &targets, const std::vector<double> &args = {}, std::string_view tag = "");
118+
std::string_view gate_name,
119+
const std::vector<uint32_t> &targets,
120+
const std::vector<double> &args = {},
121+
std::string_view tag = "");
115122
/// Safely copies a repeat block to the end of the circuit.
116123
void append_repeat_block(uint64_t repeat_count, const Circuit &body, std::string_view tag);
117124
/// Safely moves a repeat block to the end of the circuit.

0 commit comments

Comments
 (0)