Skip to content

Commit

Permalink
reset -> clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Sep 10, 2024
1 parent 346be4d commit 18cd596
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 88 deletions.
70 changes: 37 additions & 33 deletions doc/python_api_reference_vDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ API references for stable versions are kept on the [stim github wiki](https://gi
- [`stim.FlipSimulator.__init__`](#stim.FlipSimulator.__init__)
- [`stim.FlipSimulator.batch_size`](#stim.FlipSimulator.batch_size)
- [`stim.FlipSimulator.broadcast_pauli_errors`](#stim.FlipSimulator.broadcast_pauli_errors)
- [`stim.FlipSimulator.clear`](#stim.FlipSimulator.clear)
- [`stim.FlipSimulator.copy`](#stim.FlipSimulator.copy)
- [`stim.FlipSimulator.do`](#stim.FlipSimulator.do)
- [`stim.FlipSimulator.get_detector_flips`](#stim.FlipSimulator.get_detector_flips)
Expand All @@ -198,7 +199,6 @@ API references for stable versions are kept on the [stim github wiki](https://gi
- [`stim.FlipSimulator.num_observables`](#stim.FlipSimulator.num_observables)
- [`stim.FlipSimulator.num_qubits`](#stim.FlipSimulator.num_qubits)
- [`stim.FlipSimulator.peek_pauli_flips`](#stim.FlipSimulator.peek_pauli_flips)
- [`stim.FlipSimulator.reset`](#stim.FlipSimulator.reset)
- [`stim.FlipSimulator.set_pauli_flip`](#stim.FlipSimulator.set_pauli_flip)
- [`stim.FlippedMeasurement`](#stim.FlippedMeasurement)
- [`stim.FlippedMeasurement.__init__`](#stim.FlippedMeasurement.__init__)
Expand Down Expand Up @@ -7343,6 +7343,42 @@ def broadcast_pauli_errors(
"""
```

<a name="stim.FlipSimulator.clear"></a>
```python
# stim.FlipSimulator.clear

# (in class stim.FlipSimulator)
def clear(
self,
) -> None:
"""Clears the simulator's state, so it can be reused for another simulation.
This clears the measurement flip history, clears the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flip data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Behind the scenes, this doesn't free memory or resize the simulator. So,
repeating the same simulation with calls to `clear` in between will be faster
than allocating a new simulator each time (by avoiding re-allocations).
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
>>> sim.do(stim.Circuit("M(0.1) 9"))
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.clear()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(0, 256)
"""
```

<a name="stim.FlipSimulator.copy"></a>
```python
# stim.FlipSimulator.copy
Expand Down Expand Up @@ -7856,38 +7892,6 @@ def peek_pauli_flips(
"""
```

<a name="stim.FlipSimulator.reset"></a>
```python
# stim.FlipSimulator.reset

# (in class stim.FlipSimulator)
def reset(
self,
) -> None:
"""Resets the simulator's state, so it can be reused for another simulation.
This empties the measurement flip history, empties the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flips data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
>>> sim.do(stim.Circuit("M(0.1) 9"))
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.reset()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(0, 256)
"""
```

<a name="stim.FlipSimulator.set_pauli_flip"></a>
```python
# stim.FlipSimulator.set_pauli_flip
Expand Down
54 changes: 29 additions & 25 deletions doc/stim.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5723,6 +5723,35 @@ class FlipSimulator:
>>> sim.peek_pauli_flips()
[stim.PauliString("+X_Y"), stim.PauliString("+Z_Y")]
"""
def clear(
self,
) -> None:
"""Clears the simulator's state, so it can be reused for another simulation.
This clears the measurement flip history, clears the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flip data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Behind the scenes, this doesn't free memory or resize the simulator. So,
repeating the same simulation with calls to `clear` in between will be faster
than allocating a new simulator each time (by avoiding re-allocations).
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
>>> sim.do(stim.Circuit("M(0.1) 9"))
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.clear()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(0, 256)
"""
def copy(
self,
*,
Expand Down Expand Up @@ -6166,31 +6195,6 @@ class FlipSimulator:
>>> sorted(set(str(flips))) # Should have Zs from stabilizer randomization
['+', 'Z', '_']
"""
def reset(
self,
) -> None:
"""Resets the simulator's state, so it can be reused for another simulation.
This empties the measurement flip history, empties the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flips data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
>>> sim.do(stim.Circuit("M(0.1) 9"))
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.reset()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(0, 256)
"""
def set_pauli_flip(
self,
pauli: Union[str, int],
Expand Down
54 changes: 29 additions & 25 deletions glue/python/src/stim/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5723,6 +5723,35 @@ class FlipSimulator:
>>> sim.peek_pauli_flips()
[stim.PauliString("+X_Y"), stim.PauliString("+Z_Y")]
"""
def clear(
self,
) -> None:
"""Clears the simulator's state, so it can be reused for another simulation.
This clears the measurement flip history, clears the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flip data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Behind the scenes, this doesn't free memory or resize the simulator. So,
repeating the same simulation with calls to `clear` in between will be faster
than allocating a new simulator each time (by avoiding re-allocations).
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
>>> sim.do(stim.Circuit("M(0.1) 9"))
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.clear()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(0, 256)
"""
def copy(
self,
*,
Expand Down Expand Up @@ -6166,31 +6195,6 @@ class FlipSimulator:
>>> sorted(set(str(flips))) # Should have Zs from stabilizer randomization
['+', 'Z', '_']
"""
def reset(
self,
) -> None:
"""Resets the simulator's state, so it can be reused for another simulation.
This empties the measurement flip history, empties the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flips data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
>>> sim.do(stim.Circuit("M(0.1) 9"))
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.reset()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
(0, 256)
"""
def set_pauli_flip(
self,
pauli: Union[str, int],
Expand Down
14 changes: 9 additions & 5 deletions src/stim/simulators/frame_simulator.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -956,18 +956,22 @@ void stim_pybind::pybind_frame_simulator_methods(
.data());

c.def(
"reset",
"clear",
[](FrameSimulator<MAX_BITWORD_WIDTH> &self) {
self.reset_all();
},
clean_doc_string(R"DOC(
Resets the simulator's state, so it can be reused for another simulation.
Clears the simulator's state, so it can be reused for another simulation.
This empties the measurement flip history, empties the detector flip history,
This clears the measurement flip history, clears the detector flip history,
and zeroes the observable flip state. It also resets all qubits to |0>. If
stabilizer randomization is disabled, this zeros all pauli flips data. Otherwise
stabilizer randomization is disabled, this zeros all pauli flip data. Otherwise
it randomizes all pauli flips to be I or Z with equal probability.
Behind the scenes, this doesn't free memory or resize the simulator. So,
repeating the same simulation with calls to `clear` in between will be faster
than allocating a new simulator each time (by avoiding re-allocations).
Examples:
>>> import stim
>>> sim = stim.FlipSimulator(batch_size=256)
Expand All @@ -977,7 +981,7 @@ void stim_pybind::pybind_frame_simulator_methods(
>>> sim.get_measurement_flips().shape
(1, 256)
>>> sim.reset()
>>> sim.clear()
>>> sim.num_qubits
10
>>> sim.get_measurement_flips().shape
Expand Down

0 comments on commit 18cd596

Please sign in to comment.