paulie.common.pauli_string_bitarray.PauliString#

class paulie.common.pauli_string_bitarray.PauliString(n=None, pauli_str=None, bits=None)#

Bases: object

Representation of a Pauli string as a bitarray.

adjoint_map(other)#

Compute the adjoint map \(\mathrm{ad}_{A}(B) = [A, B]\).

Parameters:

other – Pauli string to adjoint map with self.

Returns:

None if the commutator is zero (i.e., if A and B commute).

Otherwise, returns a PauliString proportional to the commutator.

Return type:

PauliString|None

Raises:

ValueError – If the length of self is not equal to the length of other.

commutes_with(other)#

Check if this Pauli string commutes with another.

Parameters:

other – Pauli string to commutes.

Returns:

True if they commute, False if they anticommute.

Return type:

bool

Raises:

ValueError – If the length of self is not equal to the length of other.

complex_conj()#

Get the complex conjugate of the Pauli string.

Returns:

Complex conjugate of the Pauli string.

Return type:

tuple[complex, Self]

copy()#

Copy Pauli string.

Returns:

Copy of self.

Return type:

PauliString

create_instance(n=None, pauli_str=None)#

Create a Pauli string instance.

Parameters:
  • n (int, optional) – Length of the Pauli string.

  • pauli_str (str, optional) – String representation of a Pauli string.

Returns:

Instance of a Pauli string.

Return type:

PauliString

expand(n)#

Expand the Pauli string by tensoring it with identity operators at the end.

Parameters:

n (int) – New Pauli string length.

Returns:

Pauli string of expanded size.

Return type:

PauliString

gen_all_pauli_strings()#

Generate a list of Pauli strings that commute with this string.

Yields:

Commutant of the Pauli string.

get_anti_commutants(generators=None)#

Get a list of Pauli strings that anticommute with this string.

Parameters:

generators (list[PauliString], optional) – Collection of Pauli strings on which anticommutant is searched. If None, then the search area is all Pauli strings of the same size.

Returns:

List of Pauli strings that anticommute with this string.

Return type:

list[PauliString]

get_commutants(generators=None)#

Get a list of Pauli strings that commute with this string.

Parameters:

generators (list[PauliString], optional) – Collection of Pauli strings on which commutant is searched. If None, then the search area is all Pauli strings of the same size.

Returns:

List of Pauli strings that commute with this string.

Return type:

list[PauliString]

get_count_non_trivially()#

Get the count of non-identity operators in the Pauli string.

Returns:

Count of non-identity operators.

Return type:

int

get_diagonal_index()#

Get index in diagonal matrix decomposition vector.

Returns:

Index in diagonal matrix decomposition vector.

Return type:

int

get_index()#

Get index in matrix decomposition vector.

Returns:

Index in matrix decomposition vector.

Return type:

int

get_matrix()#

Get the matrix representation of the Pauli string.

Returns:

Matrix representation for the Pauli string.

Return type:

numpy.ndarray

get_nested(generators=None)#

Get pairs of Pauli strings whose commutator is proportional to self.

Parameters:

generators (list[PauliString], optional) – Collection of Pauli strings on which commutant is to be searched. If not specified, then the search area is all Pauli strings of the same size.

Returns:

List of pairs of Pauli strings whose commutator is proportional to self.

Return type:

list[tuple[PauliString, PauliString]]

get_substring(start, length=1)#

Get a substring of Paulis inside the Pauli string.

Parameters:
  • start (int) – Starting index of the substring.

  • length (int, optional) – Length of the substring. Default is 1.

Returns:

Substring of the Pauli string.

Return type:

PauliString

get_weight_in_matrix(b_matrix)#

Get weight in matrix decomposition vector.

Parameters:

b_matrix (numpy.ndarray) – Matrix decomposition vector.

Returns:

Weight in matrix decomposition vector.

Return type:

complex

Raises:

ValueError – Incorrect matrix size.

inc()#

Pauli string increment operator.

Returns:

Pauli string whose bit representation is greater than 1.

is_identity()#

Check if this Pauli string is the identity.

Returns:

True if self is the identity.

Return type:

bool

multiply(other)#

Proportional multiplication operator of two Pauli strings.

Parameters:

other – Pauli string to multiply.

Returns:

Pauli string proportional to the multiplication of self with other.

Return type:

PauliString

Raises:

ValueError – If the length of self is not equal to the length of other.

set_substring(start, pauli_string)#

Set substring starting at position start.

Parameters:
  • start (int) – Starting index of the substring.

  • pauli_string (str|PauliString) – Pauli string to substitute.

Returns:

None

sign(other)#

Calculates the phase of the product of two Pauli strings: self * other. The product is defined as P1 * P2 = phase * P3. This method returns the phase.

This implementation uses the correct symplectic product formalism, which can be found in various literature, including the supplemental material of the paper referenced in the related GitHub issue. See also: arxiv.org:2405.19287

Parameters:

other (PauliString) – Pauli string to multiply with.

Returns:

Complex phase of the product (1, -1, 1j, or -1j).

Return type:

complex

Raises:

ValueError – If the length of self is not equal to the length of other.

tensor(other)#

Tensor product of this Pauli string with another.

Parameters:

other – Pauli string to tensor product.

Returns:

Result of the tensor product of self with other.

Return type:

PauliString