qrunch.quantum.operators.pauli.strings
Efficient representation of a Pauli string.
Functions
|
Multiply a list of Pauli strings, left to right. |
Classes
Class for efficiently describing a hermitian Pauli string. |
|
Class for describing Stabilizer of Pauli strings. |
- class PauliPythonString
Bases:
objectClass for efficiently describing a hermitian Pauli string.
It is enforced that no indices can be overlapping for x, y, or z, i.e., expressions of the form:
\[X(1) Y(3) X(2) Z(5).\]- __init__(x_indices: tuple[int, ...] = (), y_indices: tuple[int, ...] = (), z_indices: tuple[int, ...] = ()) None
Initialize a Pauli string.
- Parameters:
x_indices (tuple[int, ...]) – Tuple holding which indices the X operators act on.. Defaults to ().
y_indices (tuple[int, ...]) – Tuple holding which indices the Y operators act on.. Defaults to ().
z_indices (tuple[int, ...]) – Tuple holding which indices the Z operators act on.. Defaults to ().
- Return type:
None
- property as_ints: tuple[int, int, int]
Get the x-mask, y-mask and z-mask defining the Pauli string as integers.
- commutative_sign(other: PauliPythonString) int
Return the sign when commuting the Pauli string with and other.
- Parameters:
other (PauliPythonString)
- Return type:
int
- classmethod from_sorted_and_disjoint_sets(x_indices: tuple[int, ...], y_indices: tuple[int, ...], z_indices: tuple[int, ...]) PauliPythonString
Construct a PauliString assuming the indices are already valid.
Sorted: Each of x_indices, y_indices, and z_indices is in strictly ascending order (no need to sort internally).
Disjoint: No index appears in more than one of the three tuples.
No duplicates: No index is repeated within a tuple.
This constructor bypasses all duplicate/overlap/sortedness checks for speed, and should only be used in performance-critical code where the caller can guarantee these invariants (e.g., after generating indices in canonical order).
- Parameters:
x_indices (tuple[int, ...]) – Sorted tuple of qubit indices acted on by X.
y_indices (tuple[int, ...]) – Sorted tuple of qubit indices acted on by Y.
z_indices (tuple[int, ...]) – Sorted tuple of qubit indices acted on by Z.
- Return type:
- classmethod from_stabilizer(stabilizer: StaPythonbilizer) PauliPythonString
Return the Pauli string corresponding to the given stabilizer.
- Parameters:
stabilizer (StaPythonbilizer)
- Return type:
- classmethod from_z_indices(z_indices: tuple[int, ...]) PauliPythonString
Construct a PauliString assuming only sorted z_indices.
This constructor bypasses all duplicate/overlap/sortedness checks for speed, and should only be used in performance-critical code where the caller can guarantee these invariants (e.g., after generating indices in canonical order).
- Parameters:
z_indices (tuple[int, ...]) – Sorted tuple of qubit indices acted on by Z.
- Return type:
- is_commuting(other: PauliPythonString) bool
Check if the Pauli string commutes with another.
- Parameters:
other (PauliPythonString)
- Return type:
bool
- is_diagonal() bool
Check if the Pauli string only contains diagonal (I and Z) operators.
- Return type:
bool
- is_identity() bool
Check if the Pauli string does not contain any operators.
Returns: True if no operators are present, False otherwise.
- Return type:
bool
- property max_index: int | None
Return the largest index of the Pauli string.
- property min_index: int | None
Return the largest index of the Pauli string.
- multiply(other: PauliPythonString) tuple[PauliPythonString, complex]
Multiply with other Pauli string.
- Parameters:
other (PauliPythonString)
- Return type:
tuple[PauliPythonString, complex]
- to_stabilizer(num_qubits: int | None = None) StaPythonbilizer
Get the stabilizer of the Pauli string.
- Parameters:
num_qubits (int | None) – Number of qubits in the stabilizer (must be larger than the Pauli operator working on the largest index)
- Return type:
- property x_indices: tuple[int, ...]
Get the indices of the X operators.
- property y_indices: tuple[int, ...]
Get the indices of the Y operators.
- property z_indices: tuple[int, ...]
Get the indices of the Z operators.
- class StaPythonbilizer
Bases:
objectClass for describing Stabilizer of Pauli strings.
These are used for stabilizer codes, https://en.wikipedia.org/wiki/Stabilizer_code
All fields are immutable (
frozen=True) so an instance can be safely reused.- Parameters:
z – One-hot encoding of Z operators.
x – One-hot encoding of X operators.
- __init__(z: list[int], x: list[int]) None
- Parameters:
z (list[int])
x (list[int])
- Return type:
None
- multiply(other: StaPythonbilizer) tuple[StaPythonbilizer, complex]
Multiply with other stabilizer.
- Parameters:
other (StaPythonbilizer)
- Return type:
tuple[StaPythonbilizer, complex]
- x: list[int]
- z: list[int]
- multiply_python_paulis(paulis: Iterable[PauliPythonString]) tuple[PauliPythonString, complex]
Multiply a list of Pauli strings, left to right.
This returns a tuple (product, phase) where phase is the complex phase factor and product is the resulting Pauli string such that the product of all input strings equals phase * product. In particular, phase is one of {1, -1, 1j, -1j}.
- Parameters:
paulis (Iterable[PauliPythonString]) – A list of Pauli strings.
- Return type:
tuple[PauliPythonString, complex]