braket.quantum_information.pauli_string module

class braket.quantum_information.pauli_string.PauliString(pauli_string: str | PauliString)[source]

Bases: object

A lightweight representation of a Pauli string with its phase.

Initializes a PauliString.

Parameters:

pauli_string (Union[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: bool = False) TensorProduct[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.

Returns:

TensorProduct – The tensor product of the unsigned factors in the Pauli string.

weight_n_substrings(weight: int) tuple[PauliString, ...][source]

Returns every substring of this Pauli string with exactly weight nontrivial 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.

Returns:

tuple[PauliString, …] – A tuple of weight-n Pauli substrings.

eigenstate(signs: str | list[int] | tuple[int, ...] | None = None) Circuit[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 (Optional[Union[str, list[int], tuple[int, ...]]]) – 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.

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: PauliString, inplace: bool = False) PauliString[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 -XYZ with argument ZYX, then YIY is the result. In-place computation is off by default.

Parameters:
  • other (PauliString) – The right multiplicand.

  • inplace (bool) – If True, self is updated to hold the product.

Returns:

PauliString – The resultant circuit from right multiplying self with other.

Raises:

ValueError – If the lengths of the Pauli strings being multiplied differ.

power(n: int, inplace: bool = False) PauliString[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 self if True

Returns:

PauliString – If n is positive, result from self-multiplication n times. If zero, identity. If negative, self-multiplication from trivial inverse (recall Pauli operators are involutory).

Raises:

ValueError – If n isn’t a plain Python int.

to_circuit() Circuit[source]

Returns circuit represented by this PauliString.

Returns:

Circuit – The circuit for this PauliString.