PauliString
- class braket.quantum_information.pauli_string.PauliString(pauli_string)[source]
Bases:
objectA lightweight representation of a Pauli string with its phase.
- Parameters:
pauli_string (
str|PauliString)
Initializes a
PauliString.- Parameters:
pauli_string (str | PauliString) – The representation of the pauli word, either a string or another PauliString object. A valid string consists of an optional phase, specified by an optional sign +/- followed by an uppercase string in {I, X, Y, Z}. Example valid strings are: XYZ, +YIZY, -YX
- Raises:
ValueError – If the Pauli String is empty.
- property phase: int
The phase of the Pauli string.
Can be one of +/-1
- Type:
int
- property qubit_count: int
The number of qubits this Pauli string acts on.
- Type:
int
- to_unsigned_observable(include_trivial=False)[source]
Returns the observable corresponding to the unsigned part of the Pauli string.
For example, for a Pauli string -XYZ, the corresponding observable is X ⊗ Y ⊗ Z.
- Parameters:
include_trivial (bool) – Whether to include explicit identity factors in the observable. Default: False.
- Return type:
- Returns:
TensorProduct – The tensor product of the unsigned factors in the Pauli string.
- weight_n_substrings(weight)[source]
Returns every substring of this Pauli string with exactly
weightnontrivial factors.The number of substrings is equal to \(\binom{n}{w}\), where :math`n` is the number of nontrivial (non-identity) factors in the Pauli string and :math`w` is
weight.- Parameters:
weight (int) – The number of non-identity factors in the substrings.
- Return type:
tuple[PauliString,...]- Returns:
tuple[PauliString, …] – A tuple of weight-n Pauli substrings.
- eigenstate(signs=None)[source]
Returns the eigenstate of this Pauli string with the given factor signs.
The resulting eigenstate has each qubit in the +1 eigenstate of its corresponding signed Pauli operator. For example, a Pauli string +XYZ and signs ++- has factors +X, +Y and -Z, with the corresponding qubits in states
|+⟩,|i⟩, and|1⟩respectively (the global phase of the Pauli string is ignored).- Parameters:
signs (str | list[int] | tuple[int, ...] | None) – The sign of each factor of the eigenstate, specified either as a string of “+” and “_”, or as a list or tuple of +/-1. The length of signs must be equal to the length of the Pauli string. If not specified, it is assumed to be all +. Default: None.
- Return type:
- Returns:
Circuit – A circuit that prepares the desired eigenstate of the Pauli string.
- Raises:
ValueError – If the length of signs is not equal to that of the Pauli string or the signs are invalid.
- dot(other, inplace=False)[source]
Right multiplies this Pauli string with the argument.
Returns the result of multiplying the current circuit by the argument on its right. For example, if called on
-XYZwith argumentZYX, thenYIYis the result. In-place computation is off by default.- Parameters:
other (PauliString) – The right multiplicand.
inplace (bool) – If
True,selfis updated to hold the product.
- Return type:
- Returns:
PauliString – The resultant circuit from right multiplying
selfwithother.- Raises:
ValueError – If the lengths of the Pauli strings being multiplied differ.
- power(n, inplace=False)[source]
Composes Pauli string with itself n times.
- Parameters:
n (int) – The number of times to self-multiply. Can be any integer value.
inplace (bool) – Update
selfifTrue
- Return type:
- Returns:
PauliString – If
nis positive, result from self-multiplicationntimes. If zero, identity. If negative, self-multiplication from trivial inverse (recall Pauli operators are involutory).- Raises:
ValueError – If
nisn’t a plain Pythonint.
- to_circuit()[source]
Returns circuit represented by this
PauliString.- Return type:
- Returns:
Circuit – The circuit for this
PauliString.