diff --git a/dev/gen_stim_stub_file.py b/dev/gen_stim_stub_file.py index 333a27d0e..e98ae876f 100644 --- a/dev/gen_stim_stub_file.py +++ b/dev/gen_stim_stub_file.py @@ -20,7 +20,7 @@ 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 +from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional, Sequence, Literal 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..bf591d08a 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. @@ -5497,9 +5497,9 @@ def sample_write( shots: int, *, filepath: Union[str, pathlib.Path], - format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, - obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + obs_out_format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', prepend_observables: bool = False, append_observables: bool = False, ) -> None: @@ -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. @@ -5838,7 +5838,7 @@ def convert( *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, - separate_observables: 'Literal[True]', + separate_observables: Literal[True], append_observables: bool = False, bit_packed: bool = False, ) -> Tuple[np.ndarray, np.ndarray]: @@ -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. @@ -11064,7 +11064,7 @@ def __imul__( # (in class stim.PauliString) def __init__( self, - arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, 'Literal["_", "I", "X", "Y", "Z"]']]] = None, + arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, Literal["_", "I", "X", "Y", "Z"]]]] = None, /, ) -> None: """Initializes a stim.PauliString from the given argument. @@ -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. @@ -13407,7 +13407,7 @@ def then( # (in class stim.Tableau) def to_circuit( self, - method: 'Literal["elimination", "graph_state"]' = 'elimination', + method: Literal["elimination", "graph_state"] = 'elimination', ) -> stim.Circuit: """Synthesizes a circuit that implements the tableau's 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,18 +16823,18 @@ 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, num_observables: int = 0, - separate_observables: 'Literal[True]', + separate_observables: Literal[True], ) -> Tuple[np.ndarray, np.ndarray]: pass 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..4dafff0a8 100644 --- a/doc/stim.pyi +++ b/doc/stim.pyi @@ -1,7 +1,7 @@ """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 +from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional, Sequence, Literal if TYPE_CHECKING: import io import pathlib @@ -1049,7 +1049,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 +4073,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. @@ -4333,9 +4333,9 @@ class CompiledDetectorSampler: shots: int, *, filepath: Union[str, pathlib.Path], - format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, - obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + obs_out_format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', prepend_observables: bool = False, append_observables: bool = False, ) -> None: @@ -4539,8 +4539,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. @@ -4639,7 +4639,7 @@ class CompiledMeasurementsToDetectionEventsConverter: *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, - separate_observables: 'Literal[True]', + separate_observables: Literal[True], append_observables: bool = False, bit_packed: bool = False, ) -> Tuple[np.ndarray, np.ndarray]: @@ -4731,15 +4731,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 +5834,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. @@ -8780,7 +8780,7 @@ class PauliString: """ def __init__( self, - arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, 'Literal["_", "I", "X", "Y", "Z"]']]] = None, + arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, Literal["_", "I", "X", "Y", "Z"]]]] = None, /, ) -> None: """Initializes a stim.PauliString from the given argument. @@ -9287,7 +9287,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 +9577,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 +10212,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 +10273,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. @@ -10702,7 +10702,7 @@ class Tableau: """ def to_circuit( self, - method: 'Literal["elimination", "graph_state"]' = 'elimination', + method: Literal["elimination", "graph_state"] = 'elimination', ) -> stim.Circuit: """Synthesizes a circuit that implements the tableau's Clifford operation. @@ -11069,7 +11069,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 +11121,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 +12843,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 +12989,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 +13484,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,18 +13495,18 @@ 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, num_observables: int = 0, - separate_observables: 'Literal[True]', + separate_observables: Literal[True], ) -> Tuple[np.ndarray, np.ndarray]: pass 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 +13877,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..4dafff0a8 100644 --- a/glue/python/src/stim/__init__.pyi +++ b/glue/python/src/stim/__init__.pyi @@ -1,7 +1,7 @@ """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 +from typing import overload, TYPE_CHECKING, List, Dict, Tuple, Any, Union, Iterable, Optional, Sequence, Literal if TYPE_CHECKING: import io import pathlib @@ -1049,7 +1049,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 +4073,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. @@ -4333,9 +4333,9 @@ class CompiledDetectorSampler: shots: int, *, filepath: Union[str, pathlib.Path], - format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, - obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', + obs_out_format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', prepend_observables: bool = False, append_observables: bool = False, ) -> None: @@ -4539,8 +4539,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. @@ -4639,7 +4639,7 @@ class CompiledMeasurementsToDetectionEventsConverter: *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, - separate_observables: 'Literal[True]', + separate_observables: Literal[True], append_observables: bool = False, bit_packed: bool = False, ) -> Tuple[np.ndarray, np.ndarray]: @@ -4731,15 +4731,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 +5834,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. @@ -8780,7 +8780,7 @@ class PauliString: """ def __init__( self, - arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, 'Literal["_", "I", "X", "Y", "Z"]']]] = None, + arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, Literal["_", "I", "X", "Y", "Z"]]]] = None, /, ) -> None: """Initializes a stim.PauliString from the given argument. @@ -9287,7 +9287,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 +9577,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 +10212,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 +10273,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. @@ -10702,7 +10702,7 @@ class Tableau: """ def to_circuit( self, - method: 'Literal["elimination", "graph_state"]' = 'elimination', + method: Literal["elimination", "graph_state"] = 'elimination', ) -> stim.Circuit: """Synthesizes a circuit that implements the tableau's Clifford operation. @@ -11069,7 +11069,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 +11121,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 +12843,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 +12989,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 +13484,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,18 +13495,18 @@ 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, num_observables: int = 0, - separate_observables: 'Literal[True]', + separate_observables: Literal[True], ) -> Tuple[np.ndarray, np.ndarray]: pass 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 +13877,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..c1b3a0d2a 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..0d443b165 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..0bc03b553 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_detector_sampler.pybind.cc b/src/stim/py/compiled_detector_sampler.pybind.cc index e682beca2..05bf5ff64 100644 --- a/src/stim/py/compiled_detector_sampler.pybind.cc +++ b/src/stim/py/compiled_detector_sampler.pybind.cc @@ -366,7 +366,7 @@ void stim_pybind::pybind_compiled_detector_sampler_methods( pybind11::arg("obs_out_filepath") = pybind11::none(), pybind11::arg("obs_out_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', obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, obs_out_format: 'Literal["01", "b8", "r8", "ptb64", "hits", "dets"]' = '01', prepend_observables: bool = False, append_observables: bool = False) -> None: + @signature def sample_write(self, shots: int, *, filepath: Union[str, pathlib.Path], format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', obs_out_filepath: Optional[Union[str, pathlib.Path]] = None, obs_out_format: Literal["01", "b8", "r8", "ptb64", "hits", "dets"] = '01', prepend_observables: bool = False, append_observables: bool = False) -> None: Samples detection events from the circuit and writes them to a file. Args: diff --git a/src/stim/py/compiled_measurement_sampler.pybind.cc b/src/stim/py/compiled_measurement_sampler.pybind.cc index 108550eb6..de28f27d7 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..62382c927 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..e85110c2f 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: @@ -289,7 +290,7 @@ void stim_pybind::pybind_compiled_measurements_to_detection_events_converter_met clean_doc_string(R"DOC( Converts measurement data into detection event data. @overload def convert(self, *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, append_observables: bool = False, bit_packed: bool = False) -> np.ndarray: - @overload def convert(self, *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, separate_observables: 'Literal[True]', append_observables: bool = False, bit_packed: bool = False) -> Tuple[np.ndarray, np.ndarray]: + @overload def convert(self, *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, separate_observables: Literal[True], append_observables: bool = False, bit_packed: bool = False) -> Tuple[np.ndarray, np.ndarray]: @signature def convert(self, *, measurements: np.ndarray, sweep_bits: Optional[np.ndarray] = None, separate_observables: bool = False, append_observables: bool = False, bit_packed: bool = False) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]: Args: diff --git a/src/stim/simulators/tableau_simulator.pybind.cc b/src/stim/simulators/tableau_simulator.pybind.cc index ff61ba5a8..af9c2f16d 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..147f99b84 100644 --- a/src/stim/stabilizers/pauli_string.pybind.cc +++ b/src/stim/stabilizers/pauli_string.pybind.cc @@ -567,7 +567,7 @@ void stim_pybind::pybind_pauli_string_methods(pybind11::module &m, pybind11::cla pybind11::arg("other") = pybind11::none(), pybind11::arg("pauli_indices") = pybind11::none(), clean_doc_string(R"DOC( - @signature def __init__(self, arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, 'Literal["_", "I", "X", "Y", "Z"]']]] = None, /) -> None: + @signature def __init__(self, arg: Union[None, int, str, stim.PauliString, Iterable[Union[int, Literal["_", "I", "X", "Y", "Z"]]]] = None, /) -> None: Initializes a stim.PauliString from the given argument. When given a string, the string is parsed as a pauli string. The string can @@ -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..a53df9aab 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 @@ -672,7 +672,7 @@ void stim_pybind::pybind_tableau_methods(pybind11::module &m, pybind11::class_ stim.Circuit: + @signature def to_circuit(self, method: Literal["elimination", "graph_state"] = 'elimination') -> stim.Circuit: Synthesizes a circuit that implements the tableau's Clifford operation. The circuits returned by this method are not guaranteed to be stable @@ -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