diff --git a/dev/gen_stim_stub_file.py b/dev/gen_stim_stub_file.py index 333a27d0e..278891416 100644 --- a/dev/gen_stim_stub_file.py +++ b/dev/gen_stim_stub_file.py @@ -20,7 +20,11 @@ def main(): """Stim {version}: a fast quantum stabilizer circuit library.""" # (This is a stubs file describing the classes and methods in stim.) from __future__ import annotations -from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional +try: + from typing import Literal +except ImportError: + pass +from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional, Sequence if TYPE_CHECKING: import io import pathlib diff --git a/doc/python_api_reference_vDev.md b/doc/python_api_reference_vDev.md index cfef6f0be..386c0e0ee 100644 --- a/doc/python_api_reference_vDev.md +++ b/doc/python_api_reference_vDev.md @@ -1664,7 +1664,7 @@ def detector_error_model( # (in class stim.Circuit) def diagram( self, - type: str = 'timeline-text', + type: 'Literal["timeline-text", "timeline-svg", "timeline-svg-html", "timeline-3d", "timeline-3d-html", "detslice-text", "detslice-svg", "detslice-svg-html", "matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html", "timeslice-svg", "timeslice-svg-html", "detslice-with-ops-svg", "detslice-with-ops-svg-html", "interactive", "interactive-html"]' = 'timeline-text', *, tick: Union[None, int, range] = None, filter_coords: Iterable[Union[Iterable[float], stim.DemTarget]] = ((),), @@ -5230,13 +5230,13 @@ def sample_write( shots: int, *, det_out_file: Union[None, str, pathlib.Path], - det_out_format: str = "01", + det_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', obs_out_file: Union[None, str, pathlib.Path], - obs_out_format: str = "01", + obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', err_out_file: Union[None, str, pathlib.Path] = None, - err_out_format: str = "01", + err_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', replay_err_in_file: Union[None, str, pathlib.Path] = None, - replay_err_in_format: str = "01", + replay_err_in_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Samples the detector error model and writes the results to disk. @@ -5710,8 +5710,8 @@ def sample_write( self, shots: int, *, - filepath: str, - format: str = '01', + filepath: Union[str, pathlib.Path], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Samples measurements from the circuit and writes them to a file. @@ -5937,15 +5937,15 @@ def convert( def convert_file( self, *, - measurements_filepath: str, - measurements_format: str = '01', - sweep_bits_filepath: str = None, - sweep_bits_format: str = '01', - detection_events_filepath: str, - detection_events_format: str = '01', + measurements_filepath: Union[str, pathlib.Path], + measurements_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + sweep_bits_filepath: Optional[Union[str, pathlib.Path]] = None, + sweep_bits_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + detection_events_filepath: Union[str, pathlib.Path], + detection_events_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', append_observables: bool = False, - obs_out_filepath: str = None, - obs_out_format: str = '01', + obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, + obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Reads measurement data from a file and writes detection events to another file. @@ -7425,7 +7425,7 @@ def copy( # (in class stim.DetectorErrorModel) def diagram( self, - type: str, + type: 'Literal["matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html"]' = 'matchgraph-svg', ) -> Any: """Returns a diagram of the circuit, from a variety of options. @@ -11684,7 +11684,7 @@ def from_numpy( def from_unitary_matrix( matrix: Iterable[Iterable[Union[int, float, complex]]], *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', unsigned: bool = False, ) -> stim.PauliString: """Creates a stim.PauliString from the unitary matrix of a Pauli group member. @@ -12023,7 +12023,7 @@ def to_tableau( def to_unitary_matrix( self, *, - endian: str, + endian: 'Literal["little", "big"]', ) -> np.ndarray[np.complex64]: """Converts the pauli string into a unitary matrix. @@ -12826,7 +12826,7 @@ def from_stabilizers( def from_state_vector( state_vector: Iterable[float], *, - endian: str, + endian: 'Literal["little", "big"]', ) -> stim.Tableau: """Creates a tableau representing the stabilizer state of the given state vector. @@ -12894,7 +12894,7 @@ def from_state_vector( def from_unitary_matrix( matrix: Iterable[Iterable[float]], *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> stim.Tableau: """Creates a tableau from the unitary matrix of a Clifford operation. @@ -13802,7 +13802,7 @@ def to_stabilizers( def to_state_vector( self, *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> np.ndarray[np.complex64]: """Returns the state vector produced by applying the tableau to the |0..0> state. @@ -13861,7 +13861,7 @@ def to_state_vector( def to_unitary_matrix( self, *, - endian: str, + endian: 'Literal["little", "big"]', ) -> np.ndarray[np.complex64]: """Converts the tableau into a unitary matrix. @@ -16003,7 +16003,7 @@ def set_state_from_state_vector( self, state_vector: Iterable[float], *, - endian: str, + endian: 'Literal["little", "big"]', ) -> None: """Sets the simulator's state to a superposition specified by an amplitude vector. @@ -16184,7 +16184,7 @@ def sqrt_y_dag( def state_vector( self, *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> np.ndarray[np.complex64]: """Returns a wavefunction for the simulator's current state. @@ -16812,7 +16812,7 @@ def main( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -16823,7 +16823,7 @@ def read_shot_data_file( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -16834,7 +16834,7 @@ def read_shot_data_file( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -17296,7 +17296,7 @@ def write_shot_data_file( *, data: np.ndarray, path: Union[str, pathlib.Path], - format: str, + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, diff --git a/doc/stim.pyi b/doc/stim.pyi index 24f22b1b9..b243adc28 100644 --- a/doc/stim.pyi +++ b/doc/stim.pyi @@ -1,7 +1,11 @@ """Stim (Development Version): a fast quantum stabilizer circuit library.""" # (This is a stubs file describing the classes and methods in stim.) from __future__ import annotations -from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional +try: + from typing import Literal +except ImportError: + pass +from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional, Sequence if TYPE_CHECKING: import io import pathlib @@ -1049,7 +1053,7 @@ class Circuit: """ def diagram( self, - type: str = 'timeline-text', + type: 'Literal["timeline-text", "timeline-svg", "timeline-svg-html", "timeline-3d", "timeline-3d-html", "detslice-text", "detslice-svg", "detslice-svg-html", "matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html", "timeslice-svg", "timeslice-svg-html", "detslice-with-ops-svg", "detslice-with-ops-svg-html", "interactive", "interactive-html"]' = 'timeline-text', *, tick: Union[None, int, range] = None, filter_coords: Iterable[Union[Iterable[float], stim.DemTarget]] = ((),), @@ -4073,13 +4077,13 @@ class CompiledDemSampler: shots: int, *, det_out_file: Union[None, str, pathlib.Path], - det_out_format: str = "01", + det_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', obs_out_file: Union[None, str, pathlib.Path], - obs_out_format: str = "01", + obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', err_out_file: Union[None, str, pathlib.Path] = None, - err_out_format: str = "01", + err_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', replay_err_in_file: Union[None, str, pathlib.Path] = None, - replay_err_in_format: str = "01", + replay_err_in_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Samples the detector error model and writes the results to disk. @@ -4539,8 +4543,8 @@ class CompiledMeasurementSampler: self, shots: int, *, - filepath: str, - format: str = '01', + filepath: Union[str, pathlib.Path], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Samples measurements from the circuit and writes them to a file. @@ -4731,15 +4735,15 @@ class CompiledMeasurementsToDetectionEventsConverter: def convert_file( self, *, - measurements_filepath: str, - measurements_format: str = '01', - sweep_bits_filepath: str = None, - sweep_bits_format: str = '01', - detection_events_filepath: str, - detection_events_format: str = '01', + measurements_filepath: Union[str, pathlib.Path], + measurements_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + sweep_bits_filepath: Optional[Union[str, pathlib.Path]] = None, + sweep_bits_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + detection_events_filepath: Union[str, pathlib.Path], + detection_events_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', append_observables: bool = False, - obs_out_filepath: str = None, - obs_out_format: str = '01', + obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, + obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Reads measurement data from a file and writes detection events to another file. @@ -5834,7 +5838,7 @@ class DetectorErrorModel: """ def diagram( self, - type: str, + type: 'Literal["matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html"]' = 'matchgraph-svg', ) -> Any: """Returns a diagram of the circuit, from a variety of options. @@ -9287,7 +9291,7 @@ class PauliString: def from_unitary_matrix( matrix: Iterable[Iterable[Union[int, float, complex]]], *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', unsigned: bool = False, ) -> stim.PauliString: """Creates a stim.PauliString from the unitary matrix of a Pauli group member. @@ -9577,7 +9581,7 @@ class PauliString: def to_unitary_matrix( self, *, - endian: str, + endian: 'Literal["little", "big"]', ) -> np.ndarray[np.complex64]: """Converts the pauli string into a unitary matrix. @@ -10212,7 +10216,7 @@ class Tableau: def from_state_vector( state_vector: Iterable[float], *, - endian: str, + endian: 'Literal["little", "big"]', ) -> stim.Tableau: """Creates a tableau representing the stabilizer state of the given state vector. @@ -10273,7 +10277,7 @@ class Tableau: def from_unitary_matrix( matrix: Iterable[Iterable[float]], *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> stim.Tableau: """Creates a tableau from the unitary matrix of a Clifford operation. @@ -11069,7 +11073,7 @@ class Tableau: def to_state_vector( self, *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> np.ndarray[np.complex64]: """Returns the state vector produced by applying the tableau to the |0..0> state. @@ -11121,7 +11125,7 @@ class Tableau: def to_unitary_matrix( self, *, - endian: str, + endian: 'Literal["little", "big"]', ) -> np.ndarray[np.complex64]: """Converts the tableau into a unitary matrix. @@ -12843,7 +12847,7 @@ class TableauSimulator: self, state_vector: Iterable[float], *, - endian: str, + endian: 'Literal["little", "big"]', ) -> None: """Sets the simulator's state to a superposition specified by an amplitude vector. @@ -12989,7 +12993,7 @@ class TableauSimulator: def state_vector( self, *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> np.ndarray[np.complex64]: """Returns a wavefunction for the simulator's current state. @@ -13484,7 +13488,7 @@ def main( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -13495,7 +13499,7 @@ def read_shot_data_file( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -13506,7 +13510,7 @@ def read_shot_data_file( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -13877,7 +13881,7 @@ def write_shot_data_file( *, data: np.ndarray, path: Union[str, pathlib.Path], - format: str, + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, diff --git a/glue/python/src/stim/__init__.pyi b/glue/python/src/stim/__init__.pyi index 24f22b1b9..b243adc28 100644 --- a/glue/python/src/stim/__init__.pyi +++ b/glue/python/src/stim/__init__.pyi @@ -1,7 +1,11 @@ """Stim (Development Version): a fast quantum stabilizer circuit library.""" # (This is a stubs file describing the classes and methods in stim.) from __future__ import annotations -from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional +try: + from typing import Literal +except ImportError: + pass +from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional, Sequence if TYPE_CHECKING: import io import pathlib @@ -1049,7 +1053,7 @@ class Circuit: """ def diagram( self, - type: str = 'timeline-text', + type: 'Literal["timeline-text", "timeline-svg", "timeline-svg-html", "timeline-3d", "timeline-3d-html", "detslice-text", "detslice-svg", "detslice-svg-html", "matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html", "timeslice-svg", "timeslice-svg-html", "detslice-with-ops-svg", "detslice-with-ops-svg-html", "interactive", "interactive-html"]' = 'timeline-text', *, tick: Union[None, int, range] = None, filter_coords: Iterable[Union[Iterable[float], stim.DemTarget]] = ((),), @@ -4073,13 +4077,13 @@ class CompiledDemSampler: shots: int, *, det_out_file: Union[None, str, pathlib.Path], - det_out_format: str = "01", + det_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', obs_out_file: Union[None, str, pathlib.Path], - obs_out_format: str = "01", + obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', err_out_file: Union[None, str, pathlib.Path] = None, - err_out_format: str = "01", + err_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', replay_err_in_file: Union[None, str, pathlib.Path] = None, - replay_err_in_format: str = "01", + replay_err_in_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Samples the detector error model and writes the results to disk. @@ -4539,8 +4543,8 @@ class CompiledMeasurementSampler: self, shots: int, *, - filepath: str, - format: str = '01', + filepath: Union[str, pathlib.Path], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Samples measurements from the circuit and writes them to a file. @@ -4731,15 +4735,15 @@ class CompiledMeasurementsToDetectionEventsConverter: def convert_file( self, *, - measurements_filepath: str, - measurements_format: str = '01', - sweep_bits_filepath: str = None, - sweep_bits_format: str = '01', - detection_events_filepath: str, - detection_events_format: str = '01', + measurements_filepath: Union[str, pathlib.Path], + measurements_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + sweep_bits_filepath: Optional[Union[str, pathlib.Path]] = None, + sweep_bits_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + detection_events_filepath: Union[str, pathlib.Path], + detection_events_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', append_observables: bool = False, - obs_out_filepath: str = None, - obs_out_format: str = '01', + obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, + obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', ) -> None: """Reads measurement data from a file and writes detection events to another file. @@ -5834,7 +5838,7 @@ class DetectorErrorModel: """ def diagram( self, - type: str, + type: 'Literal["matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html"]' = 'matchgraph-svg', ) -> Any: """Returns a diagram of the circuit, from a variety of options. @@ -9287,7 +9291,7 @@ class PauliString: def from_unitary_matrix( matrix: Iterable[Iterable[Union[int, float, complex]]], *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', unsigned: bool = False, ) -> stim.PauliString: """Creates a stim.PauliString from the unitary matrix of a Pauli group member. @@ -9577,7 +9581,7 @@ class PauliString: def to_unitary_matrix( self, *, - endian: str, + endian: 'Literal["little", "big"]', ) -> np.ndarray[np.complex64]: """Converts the pauli string into a unitary matrix. @@ -10212,7 +10216,7 @@ class Tableau: def from_state_vector( state_vector: Iterable[float], *, - endian: str, + endian: 'Literal["little", "big"]', ) -> stim.Tableau: """Creates a tableau representing the stabilizer state of the given state vector. @@ -10273,7 +10277,7 @@ class Tableau: def from_unitary_matrix( matrix: Iterable[Iterable[float]], *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> stim.Tableau: """Creates a tableau from the unitary matrix of a Clifford operation. @@ -11069,7 +11073,7 @@ class Tableau: def to_state_vector( self, *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> np.ndarray[np.complex64]: """Returns the state vector produced by applying the tableau to the |0..0> state. @@ -11121,7 +11125,7 @@ class Tableau: def to_unitary_matrix( self, *, - endian: str, + endian: 'Literal["little", "big"]', ) -> np.ndarray[np.complex64]: """Converts the tableau into a unitary matrix. @@ -12843,7 +12847,7 @@ class TableauSimulator: self, state_vector: Iterable[float], *, - endian: str, + endian: 'Literal["little", "big"]', ) -> None: """Sets the simulator's state to a superposition specified by an amplitude vector. @@ -12989,7 +12993,7 @@ class TableauSimulator: def state_vector( self, *, - endian: str = 'little', + endian: 'Literal["little", "big"]' = 'little', ) -> np.ndarray[np.complex64]: """Returns a wavefunction for the simulator's current state. @@ -13484,7 +13488,7 @@ def main( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -13495,7 +13499,7 @@ def read_shot_data_file( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -13506,7 +13510,7 @@ def read_shot_data_file( def read_shot_data_file( *, path: Union[str, pathlib.Path], - format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, @@ -13877,7 +13881,7 @@ def write_shot_data_file( *, data: np.ndarray, path: Union[str, pathlib.Path], - format: str, + format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, diff --git a/src/stim/circuit/circuit.pybind.cc b/src/stim/circuit/circuit.pybind.cc index bd9674638..28c10681c 100644 --- a/src/stim/circuit/circuit.pybind.cc +++ b/src/stim/circuit/circuit.pybind.cc @@ -2462,7 +2462,7 @@ void stim_pybind::pybind_circuit_methods(pybind11::module &, pybind11::class_ 'stim._DiagramHelper': + @signature def diagram(self, type: 'Literal["timeline-text", "timeline-svg", "timeline-svg-html", "timeline-3d", "timeline-3d-html", "detslice-text", "detslice-svg", "detslice-svg-html", "matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html", "timeslice-svg", "timeslice-svg-html", "detslice-with-ops-svg", "detslice-with-ops-svg-html", "interactive", "interactive-html"]' = 'timeline-text', *, tick: Union[None, int, range] = None, filter_coords: Iterable[Union[Iterable[float], stim.DemTarget]] = ((),), rows: int | None = None) -> 'stim._DiagramHelper': Returns a diagram of the circuit, from a variety of options. Args: diff --git a/src/stim/dem/detector_error_model.pybind.cc b/src/stim/dem/detector_error_model.pybind.cc index 1f1a3fc91..daa488dc6 100644 --- a/src/stim/dem/detector_error_model.pybind.cc +++ b/src/stim/dem/detector_error_model.pybind.cc @@ -1155,7 +1155,7 @@ void stim_pybind::pybind_detector_error_model_methods( &dem_diagram, pybind11::arg("type"), clean_doc_string(R"DOC( - @signature def diagram(self, type: str) -> Any: + @signature def diagram(self, type: 'Literal["matchgraph-svg", "matchgraph-svg-html", "matchgraph-3d", "matchgraph-3d-html"]' = 'matchgraph-svg') -> Any: Returns a diagram of the circuit, from a variety of options. Args: diff --git a/src/stim/io/read_write.pybind.cc b/src/stim/io/read_write.pybind.cc index d3ca5bec3..bc88549d4 100644 --- a/src/stim/io/read_write.pybind.cc +++ b/src/stim/io/read_write.pybind.cc @@ -196,9 +196,9 @@ void stim_pybind::pybind_read_write(pybind11::module &m) { pybind11::arg("bit_pack") = false, // Legacy argument for backwards compat. clean_doc_string(R"DOC( Reads shot data, such as measurement samples, from a file. - @overload def read_shot_data_file(*, path: Union[str, pathlib.Path], format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0) -> np.ndarray: - @overload def read_shot_data_file(*, path: Union[str, pathlib.Path], format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, separate_observables: 'Literal[True]') -> Tuple[np.ndarray, np.ndarray]: - @signature def read_shot_data_file(*, path: Union[str, pathlib.Path], format: Union[str, 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]'], bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, separate_observables: bool = False) -> Union[Tuple[np.ndarray, np.ndarray], np.ndarray]: + @overload def read_shot_data_file(*, path: Union[str, pathlib.Path], format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0) -> np.ndarray: + @overload def read_shot_data_file(*, path: Union[str, pathlib.Path], format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, separate_observables: 'Literal[True]') -> Tuple[np.ndarray, np.ndarray]: + @signature def read_shot_data_file(*, path: Union[str, pathlib.Path], format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', bit_packed: bool = False, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0, separate_observables: bool = False) -> Union[Tuple[np.ndarray, np.ndarray], np.ndarray]: Args: path: The path to the file to read the data from. @@ -282,7 +282,7 @@ void stim_pybind::pybind_read_write(pybind11::module &m) { pybind11::arg("num_observables") = pybind11::none(), clean_doc_string(R"DOC( Writes shot data, such as measurement samples, to a file. - @signature def write_shot_data_file(*, data: np.ndarray, path: Union[str, pathlib.Path], format: str, num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0) -> None: + @signature def write_shot_data_file(*, data: np.ndarray, path: Union[str, pathlib.Path], format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]', num_measurements: int = 0, num_detectors: int = 0, num_observables: int = 0) -> None: Args: data: The data to write to the file. This must be a numpy array. The dtype diff --git a/src/stim/py/compiled_measurement_sampler.pybind.cc b/src/stim/py/compiled_measurement_sampler.pybind.cc index 108550eb6..c5b7f9b00 100644 --- a/src/stim/py/compiled_measurement_sampler.pybind.cc +++ b/src/stim/py/compiled_measurement_sampler.pybind.cc @@ -249,6 +249,7 @@ void stim_pybind::pybind_compiled_measurement_sampler_methods( pybind11::arg("filepath"), pybind11::arg("format") = "01", clean_doc_string(R"DOC( + @signature def sample_write(self, shots: int, *, filepath: Union[str, pathlib.Path], format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01') -> None: Samples measurements from the circuit and writes them to a file. Examples: diff --git a/src/stim/simulators/dem_sampler.pybind.cc b/src/stim/simulators/dem_sampler.pybind.cc index 3b89a66df..01076599c 100644 --- a/src/stim/simulators/dem_sampler.pybind.cc +++ b/src/stim/simulators/dem_sampler.pybind.cc @@ -308,7 +308,7 @@ void stim_pybind::pybind_dem_sampler_methods(pybind11::module &m, pybind11::clas pybind11::arg("replay_err_in_file") = pybind11::none(), pybind11::arg("replay_err_in_format") = "01", clean_doc_string(R"DOC( - @signature def sample_write(self, shots: int, *, det_out_file: Union[None, str, pathlib.Path], det_out_format: str = "01", obs_out_file: Union[None, str, pathlib.Path], obs_out_format: str = "01", err_out_file: Union[None, str, pathlib.Path] = None, err_out_format: str = "01", replay_err_in_file: Union[None, str, pathlib.Path] = None, replay_err_in_format: str = "01") -> None: + @signature def sample_write(self, shots: int, *, det_out_file: Union[None, str, pathlib.Path], det_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', obs_out_file: Union[None, str, pathlib.Path], obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', err_out_file: Union[None, str, pathlib.Path] = None, err_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', replay_err_in_file: Union[None, str, pathlib.Path] = None, replay_err_in_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01') -> None: Samples the detector error model and writes the results to disk. Args: diff --git a/src/stim/simulators/measurements_to_detection_events.pybind.cc b/src/stim/simulators/measurements_to_detection_events.pybind.cc index 05e907ccb..20612c51e 100644 --- a/src/stim/simulators/measurements_to_detection_events.pybind.cc +++ b/src/stim/simulators/measurements_to_detection_events.pybind.cc @@ -221,6 +221,7 @@ void stim_pybind::pybind_compiled_measurements_to_detection_events_converter_met pybind11::arg("obs_out_filepath") = nullptr, pybind11::arg("obs_out_format") = "01", clean_doc_string(R"DOC( + @signature def convert_file(self, *, measurements_filepath: Union[str, pathlib.Path], measurements_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', sweep_bits_filepath: Optional[Union[str, pathlib.Path]] = None, sweep_bits_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', detection_events_filepath: Union[str, pathlib.Path], detection_events_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', append_observables: bool = False, obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01') -> None: Reads measurement data from a file and writes detection events to another file. Args: diff --git a/src/stim/simulators/tableau_simulator.pybind.cc b/src/stim/simulators/tableau_simulator.pybind.cc index ff61ba5a8..9ba66e83f 100644 --- a/src/stim/simulators/tableau_simulator.pybind.cc +++ b/src/stim/simulators/tableau_simulator.pybind.cc @@ -270,7 +270,7 @@ void stim_pybind::pybind_tableau_simulator_methods( pybind11::kw_only(), pybind11::arg("endian") = "little", clean_doc_string(R"DOC( - @signature def state_vector(self, *, endian: str = 'little') -> np.ndarray[np.complex64]: + @signature def state_vector(self, *, endian: 'Literal["little", "big"]' = 'little') -> np.ndarray[np.complex64]: Returns a wavefunction for the simulator's current state. This function takes O(n * 2**n) time and O(2**n) space, where n is the number of @@ -2483,7 +2483,7 @@ void stim_pybind::pybind_tableau_simulator_methods( pybind11::kw_only(), pybind11::arg("endian"), clean_doc_string(R"DOC( - @signature def set_state_from_state_vector(self, state_vector: Iterable[float], *, endian: str) -> None: + @signature def set_state_from_state_vector(self, state_vector: Iterable[float], *, endian: 'Literal["little", "big"]') -> None: Sets the simulator's state to a superposition specified by an amplitude vector. Args: diff --git a/src/stim/stabilizers/pauli_string.pybind.cc b/src/stim/stabilizers/pauli_string.pybind.cc index b16f21a42..1bf8aa358 100644 --- a/src/stim/stabilizers/pauli_string.pybind.cc +++ b/src/stim/stabilizers/pauli_string.pybind.cc @@ -726,7 +726,7 @@ void stim_pybind::pybind_pauli_string_methods(pybind11::module &m, pybind11::cla pybind11::kw_only(), pybind11::arg("endian"), clean_doc_string(R"DOC( - @signature def to_unitary_matrix(self, *, endian: str) -> np.ndarray[np.complex64]: + @signature def to_unitary_matrix(self, *, endian: 'Literal["little", "big"]') -> np.ndarray[np.complex64]: Converts the pauli string into a unitary matrix. Args: @@ -758,7 +758,7 @@ void stim_pybind::pybind_pauli_string_methods(pybind11::module &m, pybind11::cla pybind11::arg("endian") = "little", pybind11::arg("unsigned") = false, clean_doc_string(R"DOC( - @signature def from_unitary_matrix(matrix: Iterable[Iterable[Union[int, float, complex]]], *, endian: str = 'little', unsigned: bool = False) -> stim.PauliString: + @signature def from_unitary_matrix(matrix: Iterable[Iterable[Union[int, float, complex]]], *, endian: 'Literal["little", "big"]' = 'little', unsigned: bool = False) -> stim.PauliString: Creates a stim.PauliString from the unitary matrix of a Pauli group member. Args: diff --git a/src/stim/stabilizers/tableau.pybind.cc b/src/stim/stabilizers/tableau.pybind.cc index d5bb30c74..b54ce5406 100644 --- a/src/stim/stabilizers/tableau.pybind.cc +++ b/src/stim/stabilizers/tableau.pybind.cc @@ -271,7 +271,7 @@ void stim_pybind::pybind_tableau_methods(pybind11::module &m, pybind11::class_ np.ndarray[np.complex64]: + @signature def to_unitary_matrix(self, *, endian: 'Literal["little", "big"]') -> np.ndarray[np.complex64]: Converts the tableau into a unitary matrix. For an n-qubit tableau, this method performs O(n 4^n) work. It uses the state @@ -1742,7 +1742,7 @@ void stim_pybind::pybind_tableau_methods(pybind11::module &m, pybind11::class_ stim.Tableau: + @signature def from_unitary_matrix(matrix: Iterable[Iterable[float]], *, endian: 'Literal["little", "big"]' = 'little') -> stim.Tableau: Creates a tableau from the unitary matrix of a Clifford operation. Args: @@ -2142,7 +2142,7 @@ void stim_pybind::pybind_tableau_methods(pybind11::module &m, pybind11::class_ stim.Tableau: + @signature def from_state_vector(state_vector: Iterable[float], *, endian: 'Literal["little", "big"]') -> stim.Tableau: Creates a tableau representing the stabilizer state of the given state vector. Args: @@ -2233,7 +2233,7 @@ void stim_pybind::pybind_tableau_methods(pybind11::module &m, pybind11::class_ np.ndarray[np.complex64]: + @signature def to_state_vector(self, *, endian: 'Literal["little", "big"]' = 'little') -> np.ndarray[np.complex64]: Returns the state vector produced by applying the tableau to the |0..0> state. This function takes O(n * 2**n) time and O(2**n) space, where n is the number of