Skip to content

Commit ab5917a

Browse files
authored
Fix stim.Circuit.append's documented signature claiming arg= is required (#970)
Also move the examples section to the end of the docstring Fixes #967
1 parent 61b53a1 commit ab5917a

File tree

4 files changed

+88
-88
lines changed

4 files changed

+88
-88
lines changed

doc/python_api_reference_vDev.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ def append(
841841
self,
842842
name: str,
843843
targets: Union[int, stim.GateTarget, stim.PauliString, Iterable[Union[int, stim.GateTarget, stim.PauliString]]],
844-
arg: Union[float, Iterable[float]],
844+
arg: Union[float, Iterable[float], None] = None,
845845
*,
846846
tag: str = "",
847847
) -> None:
@@ -864,27 +864,6 @@ def append(
864864

865865
Note: `stim.Circuit.append_operation` is an alias of `stim.Circuit.append`.
866866

867-
Examples:
868-
>>> import stim
869-
>>> c = stim.Circuit()
870-
>>> c.append("X", 0)
871-
>>> c.append("H", [0, 1])
872-
>>> c.append("M", [0, stim.target_inv(1)])
873-
>>> c.append("CNOT", [stim.target_rec(-1), 0])
874-
>>> c.append("X_ERROR", [0], 0.125)
875-
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
876-
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
877-
>>> print(repr(c))
878-
stim.Circuit('''
879-
X 0
880-
H 0 1
881-
M 0 !1
882-
CX rec[-1] 0
883-
X_ERROR(0.125) 0
884-
E(0.25) X0 Y2
885-
MPP X1*Y2 Z3
886-
''')
887-
888867
Args:
889868
name: The name of the operation's gate (e.g. "H" or "M" or "CNOT").
890869

@@ -916,6 +895,27 @@ def append(
916895
`cirq.append`) will default to a single 0.0 argument for gates that
917896
take exactly one argument.
918897
tag: A customizable string attached to the instruction.
898+
899+
Examples:
900+
>>> import stim
901+
>>> c = stim.Circuit()
902+
>>> c.append("X", 0)
903+
>>> c.append("H", [0, 1])
904+
>>> c.append("M", [0, stim.target_inv(1)])
905+
>>> c.append("CNOT", [stim.target_rec(-1), 0])
906+
>>> c.append("X_ERROR", [0], 0.125)
907+
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
908+
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
909+
>>> print(repr(c))
910+
stim.Circuit('''
911+
X 0
912+
H 0 1
913+
M 0 !1
914+
CX rec[-1] 0
915+
X_ERROR(0.125) 0
916+
E(0.25) X0 Y2
917+
MPP X1*Y2 Z3
918+
''')
919919
"""
920920
```
921921

doc/stim.pyi

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class Circuit:
302302
self,
303303
name: str,
304304
targets: Union[int, stim.GateTarget, stim.PauliString, Iterable[Union[int, stim.GateTarget, stim.PauliString]]],
305-
arg: Union[float, Iterable[float]],
305+
arg: Union[float, Iterable[float], None] = None,
306306
*,
307307
tag: str = "",
308308
) -> None:
@@ -325,27 +325,6 @@ class Circuit:
325325
326326
Note: `stim.Circuit.append_operation` is an alias of `stim.Circuit.append`.
327327
328-
Examples:
329-
>>> import stim
330-
>>> c = stim.Circuit()
331-
>>> c.append("X", 0)
332-
>>> c.append("H", [0, 1])
333-
>>> c.append("M", [0, stim.target_inv(1)])
334-
>>> c.append("CNOT", [stim.target_rec(-1), 0])
335-
>>> c.append("X_ERROR", [0], 0.125)
336-
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
337-
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
338-
>>> print(repr(c))
339-
stim.Circuit('''
340-
X 0
341-
H 0 1
342-
M 0 !1
343-
CX rec[-1] 0
344-
X_ERROR(0.125) 0
345-
E(0.25) X0 Y2
346-
MPP X1*Y2 Z3
347-
''')
348-
349328
Args:
350329
name: The name of the operation's gate (e.g. "H" or "M" or "CNOT").
351330
@@ -377,6 +356,27 @@ class Circuit:
377356
`cirq.append`) will default to a single 0.0 argument for gates that
378357
take exactly one argument.
379358
tag: A customizable string attached to the instruction.
359+
360+
Examples:
361+
>>> import stim
362+
>>> c = stim.Circuit()
363+
>>> c.append("X", 0)
364+
>>> c.append("H", [0, 1])
365+
>>> c.append("M", [0, stim.target_inv(1)])
366+
>>> c.append("CNOT", [stim.target_rec(-1), 0])
367+
>>> c.append("X_ERROR", [0], 0.125)
368+
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
369+
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
370+
>>> print(repr(c))
371+
stim.Circuit('''
372+
X 0
373+
H 0 1
374+
M 0 !1
375+
CX rec[-1] 0
376+
X_ERROR(0.125) 0
377+
E(0.25) X0 Y2
378+
MPP X1*Y2 Z3
379+
''')
380380
"""
381381
def append_from_stim_program_text(
382382
self,

glue/python/src/stim/__init__.pyi

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class Circuit:
302302
self,
303303
name: str,
304304
targets: Union[int, stim.GateTarget, stim.PauliString, Iterable[Union[int, stim.GateTarget, stim.PauliString]]],
305-
arg: Union[float, Iterable[float]],
305+
arg: Union[float, Iterable[float], None] = None,
306306
*,
307307
tag: str = "",
308308
) -> None:
@@ -325,27 +325,6 @@ class Circuit:
325325
326326
Note: `stim.Circuit.append_operation` is an alias of `stim.Circuit.append`.
327327
328-
Examples:
329-
>>> import stim
330-
>>> c = stim.Circuit()
331-
>>> c.append("X", 0)
332-
>>> c.append("H", [0, 1])
333-
>>> c.append("M", [0, stim.target_inv(1)])
334-
>>> c.append("CNOT", [stim.target_rec(-1), 0])
335-
>>> c.append("X_ERROR", [0], 0.125)
336-
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
337-
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
338-
>>> print(repr(c))
339-
stim.Circuit('''
340-
X 0
341-
H 0 1
342-
M 0 !1
343-
CX rec[-1] 0
344-
X_ERROR(0.125) 0
345-
E(0.25) X0 Y2
346-
MPP X1*Y2 Z3
347-
''')
348-
349328
Args:
350329
name: The name of the operation's gate (e.g. "H" or "M" or "CNOT").
351330
@@ -377,6 +356,27 @@ class Circuit:
377356
`cirq.append`) will default to a single 0.0 argument for gates that
378357
take exactly one argument.
379358
tag: A customizable string attached to the instruction.
359+
360+
Examples:
361+
>>> import stim
362+
>>> c = stim.Circuit()
363+
>>> c.append("X", 0)
364+
>>> c.append("H", [0, 1])
365+
>>> c.append("M", [0, stim.target_inv(1)])
366+
>>> c.append("CNOT", [stim.target_rec(-1), 0])
367+
>>> c.append("X_ERROR", [0], 0.125)
368+
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
369+
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
370+
>>> print(repr(c))
371+
stim.Circuit('''
372+
X 0
373+
H 0 1
374+
M 0 !1
375+
CX rec[-1] 0
376+
X_ERROR(0.125) 0
377+
E(0.25) X0 Y2
378+
MPP X1*Y2 Z3
379+
''')
380380
"""
381381
def append_from_stim_program_text(
382382
self,

src/stim/circuit/circuit.pybind.cc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,33 +1090,12 @@ void stim_pybind::pybind_circuit_methods(pybind11::module &, pybind11::class_<Ci
10901090
pybind11::arg("tag") = "",
10911091
k == 0 ? "[DEPRECATED] use stim.Circuit.append instead"
10921092
: clean_doc_string(R"DOC(
1093-
@overload def append(self, name: str, targets: Union[int, stim.GateTarget, stim.PauliString, Iterable[Union[int, stim.GateTarget, stim.PauliString]]], arg: Union[float, Iterable[float]], *, tag: str = "") -> None:
1093+
@overload def append(self, name: str, targets: Union[int, stim.GateTarget, stim.PauliString, Iterable[Union[int, stim.GateTarget, stim.PauliString]]], arg: Union[float, Iterable[float], None] = None, *, tag: str = "") -> None:
10941094
@overload def append(self, name: Union[stim.CircuitInstruction, stim.CircuitRepeatBlock, stim.Circuit]) -> None:
10951095
Appends an operation into the circuit.
10961096
10971097
Note: `stim.Circuit.append_operation` is an alias of `stim.Circuit.append`.
10981098
1099-
Examples:
1100-
>>> import stim
1101-
>>> c = stim.Circuit()
1102-
>>> c.append("X", 0)
1103-
>>> c.append("H", [0, 1])
1104-
>>> c.append("M", [0, stim.target_inv(1)])
1105-
>>> c.append("CNOT", [stim.target_rec(-1), 0])
1106-
>>> c.append("X_ERROR", [0], 0.125)
1107-
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
1108-
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
1109-
>>> print(repr(c))
1110-
stim.Circuit('''
1111-
X 0
1112-
H 0 1
1113-
M 0 !1
1114-
CX rec[-1] 0
1115-
X_ERROR(0.125) 0
1116-
E(0.25) X0 Y2
1117-
MPP X1*Y2 Z3
1118-
''')
1119-
11201099
Args:
11211100
name: The name of the operation's gate (e.g. "H" or "M" or "CNOT").
11221101
@@ -1148,6 +1127,27 @@ void stim_pybind::pybind_circuit_methods(pybind11::module &, pybind11::class_<Ci
11481127
`cirq.append`) will default to a single 0.0 argument for gates that
11491128
take exactly one argument.
11501129
tag: A customizable string attached to the instruction.
1130+
1131+
Examples:
1132+
>>> import stim
1133+
>>> c = stim.Circuit()
1134+
>>> c.append("X", 0)
1135+
>>> c.append("H", [0, 1])
1136+
>>> c.append("M", [0, stim.target_inv(1)])
1137+
>>> c.append("CNOT", [stim.target_rec(-1), 0])
1138+
>>> c.append("X_ERROR", [0], 0.125)
1139+
>>> c.append("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(2)], 0.25)
1140+
>>> c.append("MPP", [stim.PauliString("X1*Y2"), stim.GateTarget("Z3")])
1141+
>>> print(repr(c))
1142+
stim.Circuit('''
1143+
X 0
1144+
H 0 1
1145+
M 0 !1
1146+
CX rec[-1] 0
1147+
X_ERROR(0.125) 0
1148+
E(0.25) X0 Y2
1149+
MPP X1*Y2 Z3
1150+
''')
11511151
)DOC")
11521152
.data());
11531153
}

0 commit comments

Comments
 (0)