From 6c052726aaa5d8703753ada0fae051db46527065 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 30 Nov 2023 00:14:50 -0800 Subject: [PATCH] tweak type --- doc/python_api_reference_vDev.md | 10 +++++++--- doc/stim.pyi | 10 +++++++--- glue/python/src/stim/__init__.pyi | 10 +++++++--- src/stim/stabilizers/pauli_string.pybind.cc | 10 +++++++--- src/stim/stabilizers/pauli_string_pybind_test.py | 1 + 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/doc/python_api_reference_vDev.md b/doc/python_api_reference_vDev.md index 7ccca5f2f..f2d98c685 100644 --- a/doc/python_api_reference_vDev.md +++ b/doc/python_api_reference_vDev.md @@ -8031,7 +8031,7 @@ def __imul__( # (in class stim.PauliString) def __init__( self, - arg: Union[None, int, str, stim.PauliString, Iterable[int]] = 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. @@ -8047,8 +8047,9 @@ def __init__( int: initializes an identity Pauli string of the given length. str: initializes by parsing the given text. stim.PauliString: initializes a copy of the given Pauli string. - Iterable[int]: initializes by interpreting each integer as a Pauli - using the convention 0=I, 1=X, 2=Y, 3=Z. + Iterable: initializes by interpreting each item as a Pauli. + Each item can be a single-qubit Pauli string (like "X"), + or an integer. Integers use the convention 0=I, 1=X, 2=Y, 3=Z. Examples: >>> import stim @@ -8067,6 +8068,9 @@ def __init__( >>> stim.PauliString([0, 1, 3, 2]) stim.PauliString("+_XZY") + + >>> stim.PauliString("X" for _ in range(4)) + stim.PauliString("+XXXX") """ ``` diff --git a/doc/stim.pyi b/doc/stim.pyi index 5f72b06ae..12b668a23 100644 --- a/doc/stim.pyi +++ b/doc/stim.pyi @@ -6157,7 +6157,7 @@ class PauliString: """ def __init__( self, - arg: Union[None, int, str, stim.PauliString, Iterable[int]] = 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. @@ -6173,8 +6173,9 @@ class PauliString: int: initializes an identity Pauli string of the given length. str: initializes by parsing the given text. stim.PauliString: initializes a copy of the given Pauli string. - Iterable[int]: initializes by interpreting each integer as a Pauli - using the convention 0=I, 1=X, 2=Y, 3=Z. + Iterable: initializes by interpreting each item as a Pauli. + Each item can be a single-qubit Pauli string (like "X"), + or an integer. Integers use the convention 0=I, 1=X, 2=Y, 3=Z. Examples: >>> import stim @@ -6193,6 +6194,9 @@ class PauliString: >>> stim.PauliString([0, 1, 3, 2]) stim.PauliString("+_XZY") + + >>> stim.PauliString("X" for _ in range(4)) + stim.PauliString("+XXXX") """ def __itruediv__( self, diff --git a/glue/python/src/stim/__init__.pyi b/glue/python/src/stim/__init__.pyi index 5f72b06ae..12b668a23 100644 --- a/glue/python/src/stim/__init__.pyi +++ b/glue/python/src/stim/__init__.pyi @@ -6157,7 +6157,7 @@ class PauliString: """ def __init__( self, - arg: Union[None, int, str, stim.PauliString, Iterable[int]] = 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. @@ -6173,8 +6173,9 @@ class PauliString: int: initializes an identity Pauli string of the given length. str: initializes by parsing the given text. stim.PauliString: initializes a copy of the given Pauli string. - Iterable[int]: initializes by interpreting each integer as a Pauli - using the convention 0=I, 1=X, 2=Y, 3=Z. + Iterable: initializes by interpreting each item as a Pauli. + Each item can be a single-qubit Pauli string (like "X"), + or an integer. Integers use the convention 0=I, 1=X, 2=Y, 3=Z. Examples: >>> import stim @@ -6193,6 +6194,9 @@ class PauliString: >>> stim.PauliString([0, 1, 3, 2]) stim.PauliString("+_XZY") + + >>> stim.PauliString("X" for _ in range(4)) + stim.PauliString("+XXXX") """ def __itruediv__( self, diff --git a/src/stim/stabilizers/pauli_string.pybind.cc b/src/stim/stabilizers/pauli_string.pybind.cc index 120cb051a..265ce9643 100644 --- a/src/stim/stabilizers/pauli_string.pybind.cc +++ b/src/stim/stabilizers/pauli_string.pybind.cc @@ -404,7 +404,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[int]] = 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 @@ -418,8 +418,9 @@ void stim_pybind::pybind_pauli_string_methods(pybind11::module &m, pybind11::cla int: initializes an identity Pauli string of the given length. str: initializes by parsing the given text. stim.PauliString: initializes a copy of the given Pauli string. - Iterable[int]: initializes by interpreting each integer as a Pauli - using the convention 0=I, 1=X, 2=Y, 3=Z. + Iterable: initializes by interpreting each item as a Pauli. + Each item can be a single-qubit Pauli string (like "X"), + or an integer. Integers use the convention 0=I, 1=X, 2=Y, 3=Z. Examples: >>> import stim @@ -438,6 +439,9 @@ void stim_pybind::pybind_pauli_string_methods(pybind11::module &m, pybind11::cla >>> stim.PauliString([0, 1, 3, 2]) stim.PauliString("+_XZY") + + >>> stim.PauliString("X" for _ in range(4)) + stim.PauliString("+XXXX") )DOC") .data()); diff --git a/src/stim/stabilizers/pauli_string_pybind_test.py b/src/stim/stabilizers/pauli_string_pybind_test.py index a01b22632..2b178749e 100644 --- a/src/stim/stabilizers/pauli_string_pybind_test.py +++ b/src/stim/stabilizers/pauli_string_pybind_test.py @@ -884,6 +884,7 @@ def test_backwards_compatibility_init(): assert stim.PauliString([1, 2, 3]) == stim.PauliString("+XYZ") assert stim.PauliString("XYZ") == stim.PauliString("+XYZ") assert stim.PauliString(stim.PauliString("XYZ")) == stim.PauliString("+XYZ") + assert stim.PauliString("X" for _ in range(4)) == stim.PauliString("+XXXX") # These keywords have been removed from the documentation and the .pyi, but # their functionality needs to be maintained for backwards compatibility.