qrunch.quantum.operators.pauli.strings
Efficient representation of a Pauli string.
Classes
Class for efficiently describing a hermitian Pauli string. |
|
Class for describing Stabilizer of Pauli strings. |
- class PauliString
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: PauliString) int
Return the sign when commuting the Pauli string with and other.
- Parameters:
other (PauliString)
- Return type:
int
- classmethod from_sorted_and_disjoint_sets(x_indices: tuple[int, ...], y_indices: tuple[int, ...], z_indices: tuple[int, ...]) PauliString
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: Stabilizer) PauliString
Return the Pauli string corresponding to the given stabilizer.
- Parameters:
stabilizer (Stabilizer)
- Return type:
- classmethod from_z_indices(z_indices: tuple[int, ...]) PauliString
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: PauliString) bool
Check if the Pauli string commutes with another.
- Parameters:
other (PauliString)
- 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: PauliString) tuple[PauliString, complex]
Multiply with other Pauli string.
- Parameters:
other (PauliString)
- Return type:
tuple[PauliString, complex]
- to_stabilizer(num_qubits: int | None = None) Stabilizer
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 Stabilizer
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: Stabilizer) tuple[Stabilizer, complex]
Multiply with other stabilizer.
- Parameters:
other (Stabilizer)
- Return type:
tuple[Stabilizer, complex]
- x: list[int]
- z: list[int]