Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor stim_pybind::PyPaulString -> stim::FlexPauliString #675

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 34 additions & 76 deletions doc/python_api_reference_vDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -8029,90 +8029,48 @@ def __imul__(
# stim.PauliString.__init__

# (in class stim.PauliString)
@staticmethod
def __init__(
*args,
**kwargs,
):
"""Overloaded function.

1. __init__(self: stim.PauliString, num_qubits: int) -> None

Creates an identity Pauli string over the given number of qubits.

Examples:
>>> import stim
>>> p = stim.PauliString(5)
>>> print(p)
+_____

Args:
num_qubits: The number of qubits the Pauli string acts on.


2. __init__(self: stim.PauliString, text: str) -> None

Creates a stim.PauliString from a text string.

The string can optionally start with a sign ('+', '-', 'i', '+i', or '-i').
The rest of the string should be characters from '_IXYZ' where
'_' and 'I' mean identity, 'X' means Pauli X, 'Y' means Pauli Y, and 'Z' means
Pauli Z.

Examples:
>>> import stim
>>> print(stim.PauliString("YZ"))
+YZ
>>> print(stim.PauliString("+IXYZ"))
+_XYZ
>>> print(stim.PauliString("-___X_"))
-___X_
>>> print(stim.PauliString("iX"))
+iX

Args:
text: A text description of the Pauli string's contents, such as "+XXX" or
"-_YX" or "-iZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZY".

Returns:
The created stim.PauliString.

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.

3. __init__(self: stim.PauliString, copy: stim.PauliString) -> None
When given a string, the string is parsed as a pauli string. The string can
optionally start with a sign ('+', '-', 'i', '+i', or '-i'). The rest of the
string should be characters from '_IXYZ' where '_' and 'I' mean identity, 'X'
means Pauli X, 'Y' means Pauli Y, and 'Z' means Pauli Z.

Creates a copy of a stim.PauliString.
Arguments:
arg [position-only]: This can be a variety of types, including:
None (default): initializes an empty Pauli string.
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: 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
>>> a = stim.PauliString("YZ")
>>> b = stim.PauliString(a)
>>> b is a
False
>>> b == a
True

Args:
copy: The pauli string to make a copy of.
>>> stim.PauliString("-XYZ")
stim.PauliString("-XYZ")

>>> stim.PauliString()
stim.PauliString("+")

4. __init__(self: stim.PauliString, pauli_indices: List[int]) -> None
>>> stim.PauliString(5)
stim.PauliString("+_____")

Creates a stim.PauliString from a list of integer pauli indices.
>>> stim.PauliString(stim.PauliString("XX"))
stim.PauliString("+XX")

The indexing scheme that is used is:
0 -> I
1 -> X
2 -> Y
3 -> Z
>>> stim.PauliString([0, 1, 3, 2])
stim.PauliString("+_XZY")

Examples:
>>> import stim
>>> stim.PauliString([0, 1, 2, 3, 0, 3])
stim.PauliString("+_XYZ_Z")

Args:
pauli_indices: A sequence of integers from 0 to 3 (inclusive) indicating
paulis.
>>> stim.PauliString("X" for _ in range(4))
stim.PauliString("+XXXX")
"""
```

Expand Down Expand Up @@ -8482,19 +8440,19 @@ def after(

# (in class stim.PauliString)
@overload
def after(
def before(
self,
operation: Union[stim.Circuit, stim.CircuitInstruction],
) -> stim.PauliString:
pass
@overload
def after(
def before(
self,
operation: stim.Tableau,
targets: Iterable[int],
) -> stim.PauliString:
pass
def after(
def before(
self,
operation: Union[stim.Circuit, stim.Tableau, stim.CircuitInstruction],
targets: Optional[Iterable[int]] = None,
Expand Down Expand Up @@ -8658,7 +8616,7 @@ def from_numpy(
# (in class stim.PauliString)
@staticmethod
def from_unitary_matrix(
matrix: Iterable[Iterable[float]],
matrix: Iterable[Iterable[Union[int, float, complex]]],
*,
endian: str = 'little',
unsigned: bool = False,
Expand Down
110 changes: 34 additions & 76 deletions doc/stim.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6155,90 +6155,48 @@ class PauliString:
Returns:
The mutated Pauli string.
"""
@staticmethod
def __init__(
*args,
**kwargs,
):
"""Overloaded function.

1. __init__(self: stim.PauliString, num_qubits: int) -> None

Creates an identity Pauli string over the given number of qubits.

Examples:
>>> import stim
>>> p = stim.PauliString(5)
>>> print(p)
+_____

Args:
num_qubits: The number of qubits the Pauli string acts on.


2. __init__(self: stim.PauliString, text: str) -> None

Creates a stim.PauliString from a text string.

The string can optionally start with a sign ('+', '-', 'i', '+i', or '-i').
The rest of the string should be characters from '_IXYZ' where
'_' and 'I' mean identity, 'X' means Pauli X, 'Y' means Pauli Y, and 'Z' means
Pauli Z.

Examples:
>>> import stim
>>> print(stim.PauliString("YZ"))
+YZ
>>> print(stim.PauliString("+IXYZ"))
+_XYZ
>>> print(stim.PauliString("-___X_"))
-___X_
>>> print(stim.PauliString("iX"))
+iX

Args:
text: A text description of the Pauli string's contents, such as "+XXX" or
"-_YX" or "-iZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZY".

Returns:
The created stim.PauliString.

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.

3. __init__(self: stim.PauliString, copy: stim.PauliString) -> None
When given a string, the string is parsed as a pauli string. The string can
optionally start with a sign ('+', '-', 'i', '+i', or '-i'). The rest of the
string should be characters from '_IXYZ' where '_' and 'I' mean identity, 'X'
means Pauli X, 'Y' means Pauli Y, and 'Z' means Pauli Z.

Creates a copy of a stim.PauliString.
Arguments:
arg [position-only]: This can be a variety of types, including:
None (default): initializes an empty Pauli string.
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: 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
>>> a = stim.PauliString("YZ")
>>> b = stim.PauliString(a)
>>> b is a
False
>>> b == a
True

Args:
copy: The pauli string to make a copy of.

>>> stim.PauliString("-XYZ")
stim.PauliString("-XYZ")

4. __init__(self: stim.PauliString, pauli_indices: List[int]) -> None
>>> stim.PauliString()
stim.PauliString("+")

Creates a stim.PauliString from a list of integer pauli indices.
>>> stim.PauliString(5)
stim.PauliString("+_____")

The indexing scheme that is used is:
0 -> I
1 -> X
2 -> Y
3 -> Z
>>> stim.PauliString(stim.PauliString("XX"))
stim.PauliString("+XX")

Examples:
>>> import stim
>>> stim.PauliString([0, 1, 2, 3, 0, 3])
stim.PauliString("+_XYZ_Z")
>>> stim.PauliString([0, 1, 3, 2])
stim.PauliString("+_XZY")

Args:
pauli_indices: A sequence of integers from 0 to 3 (inclusive) indicating
paulis.
>>> stim.PauliString("X" for _ in range(4))
stim.PauliString("+XXXX")
"""
def __itruediv__(
self,
Expand Down Expand Up @@ -6517,19 +6475,19 @@ class PauliString:
string before the operation.
"""
@overload
def after(
def before(
self,
operation: Union[stim.Circuit, stim.CircuitInstruction],
) -> stim.PauliString:
pass
@overload
def after(
def before(
self,
operation: stim.Tableau,
targets: Iterable[int],
) -> stim.PauliString:
pass
def after(
def before(
self,
operation: Union[stim.Circuit, stim.Tableau, stim.CircuitInstruction],
targets: Optional[Iterable[int]] = None,
Expand Down Expand Up @@ -6671,7 +6629,7 @@ class PauliString:
"""
@staticmethod
def from_unitary_matrix(
matrix: Iterable[Iterable[float]],
matrix: Iterable[Iterable[Union[int, float, complex]]],
*,
endian: str = 'little',
unsigned: bool = False,
Expand Down
1 change: 1 addition & 0 deletions file_lists/source_files_no_main
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ src/stim/simulators/sparse_rev_frame_tracker.cc
src/stim/simulators/transform_without_feedback.cc
src/stim/simulators/vector_simulator.cc
src/stim/stabilizers/conversions.cc
src/stim/stabilizers/flex_pauli_string.cc
1 change: 1 addition & 0 deletions file_lists/test_files
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ src/stim/simulators/tableau_simulator.test.cc
src/stim/simulators/transform_without_feedback.test.cc
src/stim/simulators/vector_simulator.test.cc
src/stim/stabilizers/conversions.test.cc
src/stim/stabilizers/flex_pauli_string.test.cc
src/stim/stabilizers/pauli_string.test.cc
src/stim/stabilizers/pauli_string_iter.test.cc
src/stim/stabilizers/tableau.test.cc
Expand Down
Loading