String

class zixy.qubit.pauli.String(qubits: int | Qubits | None = None, source: SpecT | None = None)[source]

Bases: String[QubitPauliArray, None | Sequence[PauliMatrix] | dict[int, PauliMatrix] | str, PauliMatrix]

A Pauli string.

A single qubit-based Pauli string that may be an owning instance referencing a single element in a Rust-bound data object, or a view on an element in another collection.

__eq__(other: object) bool

Return whether self and other are equal.

__getitem__(i: int) PauliMatrix[source]

Return the element of the string at index i.

__imul__(rhs: String) Self[source]

In-place multiplication of self by rhs.

__init__(qubits: int | Qubits | None = None, source: SpecT | None = None)[source]

Initialize the string.

Parameters:
  • qubits – The qubit register or qubit count.

  • source – The string specifier to use for default qubits and initial value.

__mul__(rhs: CoeffT | String) Term[CoeffT] | Term[ComplexSign][source]
Overloads:
  • self, rhs (String) → Term[ComplexSign]

  • self, rhs (CoeffT) → Term[CoeffT]

Multiplication of self by rhs.

__repr__() str[source]

Return a string representation of self.

__rmul__(lhs: CoeffT) Term[ImplT, SpecT, CoeffT]

Return the product of lhs and self.

__setitem__(i: int, pauli: PauliMatrix | str) None[source]

Set the element of the string at index i.

aliases(other: Cmpnt[ImplT, SpecT]) bool

Determine whether self is a view of the same component as other.

clear() None

Set the value of the component to zero.

Note

This method operates in-place.

clone() Self

Return a deep copy of self.

commutes_with(rhs: String) bool[source]

Check whether self commutes with rhs.

count(elem: ElemT) int[source]

Return the number of occurrences of elem in the string.

Parameters:

elem – The element to count.

Returns:

The number of occurrences of elem in the string.

classmethod from_str(source: str, qubits: int | Qubits | None = None) String[source]

Create a new instance of cls by parsing an input string.

Parameters:
  • source – Input string to parse.

  • qubits – Space of qubits or a number of qubits. If None, infer from the max qubit index in the input string.

Returns:

A new instance containing the Pauli string in the source.

get_dict() dict[int, PauliMatrix][source]

Get the string as a dictionary of its elements.

get_list() list[ElemT][source]

Get the string as a list of its elements.

get_tuple() tuple[ElemT, ...][source]

Get the string as a tuple of its elements.

impl_type

alias of QubitPauliArray

imul_get_phase(rhs: String) ComplexSign[source]

In-place multiplication of self by rhs, returning the phase.

See also

imul_ignore_phase() for in-place multiplication that ignores the phase.

imul_ignore_phase(rhs: String) None[source]

In-place multiplication of self by rhs, ignoring the scalar phase.

into(t: type[OutT]) OutT

Clone self into a new related container of type t.

Parameters:

t – Type of the new container to create.

Returns:

A new instance of t containing the same data as self.

is_diagonal() bool[source]

Check whether the string is diagonal (only \(I\) and \(Z\)).

is_identity() bool[source]

Check whether the string is identity (\(II...I\)).

is_owning() bool

Check if self is owning (i.e. not a view).

phase_of_mul(rhs: String) ComplexSign[source]

Get the phase resulting from the multiplication of self and rhs.

property qubits: Qubits

Get the qubits corresponding to self.

set(source: None | Sequence[PauliMatrix] | dict[int, PauliMatrix] | str | String[QubitPauliArray, None | Sequence[PauliMatrix] | dict[int, PauliMatrix] | str, PauliMatrix]) None[source]

Set the value of the string.

Parameters:

source – Specification for the new value.

Note

This method operates in-place.

set_mul(lhs: String, rhs: String) ComplexSign[source]

Set self to the product of lhs and rhs, and return the phase.

Parameters:
  • lhs – Left hand side of the product.

  • rhs – Right hand side of the product.

Returns:

The phase factor of the multiplication.

to_sparse_matrix(big_endian: bool = False) Any[source]

Return self as a sparse matrix.

Parameters:

big_endian – Whether to use big-endian basis ordering.

Returns:

The sparse matrix representation of self.