loom.eka.utilities.pauli_binary_vector_rep

Copyright (c) Entropica Labs Pte Ltd 2025.

Use, distribution and reproduction of this program in its source or compiled form is prohibited without the express written consent of Entropica Labs Pte Ltd.

class loom.eka.utilities.pauli_binary_vector_rep.PauliOp[source]

Bases: ABC

Abstract PauliOp class, parent of SignedPauliOp and UnsignedPauliOp.

Parameters:
  • DTYPE (np.dtype) – The type of numpy arrays used as bit arrays.

  • array (np.ndarray) – The array representation of the Pauli operator.

DTYPE

alias of int8

array: ndarray
property is_trivial: bool

Checks if the Pauli operator is identity.

property nqubits: int

The number of qubits that the Pauli operator acts on.

property x: array

The array representing the X-component of the Pauli operator in binary representation.

property z: array

The array representing the Z-component of the Pauli operator in binary representation.

class loom.eka.utilities.pauli_binary_vector_rep.SignedPauliOp(array, validated=False)[source]

Bases: PauliOp

A class describing a SignedPauliOp, a PauliOp operator with a sign that is + or -.

Parameters:

array (np.ndarray | Sequence) – The array representation of the SignedPauliOp.

Initialization of the SignedPauliOp via a numpy array.

Parameters:

array (np.ndarray | Sequence) – The array representation of the SignedPauliOp

as_sparse_string()[source]

Return the Pauli operator as a sparse Pauli string.

Returns:

The Pauli operator as a sparse Pauli string.

Return type:

str

copy()[source]

Returns a deep copy of the SignedPauliOp object.

Returns:

Deep copy of the SignedPauliOp object

Return type:

SignedPauliOp

classmethod from_sparse_string(pauli_str, nqubits=None)[source]

Create a SignedPauliOp from a sparse Pauli string, like “+X2Z5Y7”

Parameters:
  • pauli_str (str) – The sparse Pauli string to create the SignedPauliOp from. It is not case sensitive.

  • nqubits (int | None) – The total number of qubits the Pauli operator acts on. Since SignedPauliOp is a dense representation, all qubits with index starting from 0 until nqubits-1 will be described by the array. The number of qubits should be greater than the maximum index in the Pauli string. If None, the number of qubits is inferred from the maximum index in the Pauli string.

Returns:

The SignedPauliOp created from the Pauli string.

Return type:

SignedPauliOp

Raises:

ValueError – If the first character of the Pauli string is not ‘+’ or ‘-‘. If there are invalid elements in the Pauli string. If the indices in the Pauli string are not unique. If the number of qubits is not greater than the maximum index in the Pauli string.

classmethod from_string(pauli_str)[source]

Create a SignedPauliOp from a Pauli string, like “+IXZZY”

Parameters:

pauli_str (str) – The Pauli string to create the SignedPauliOp from.

Returns:

The SignedPauliOp created from the Pauli string.

Return type:

SignedPauliOp

Raises:

ValueError – If the first character of the Pauli string is not ‘+’ or ‘-‘.

classmethod identity(nqubits, negative=False)[source]

Create an identity operator acting on nqubits. Can be used to create a negative identity operator as well.

Parameters:
  • nqubits (int) – The number of qubits the identity operator should act on.

  • negative (bool) – If True, return a negative identity operator.

Returns:

The identity operator acting on nqubits.

Return type:

SignedPauliOp

property is_minus_identity: bool

Check if the Pauli operator is a minus identity operator. Returns True if the Pauli operator is a minus identity operator, False otherwise.

multiply_with_anticommuting_operator(other)[source]

Multiply two Pauli operators that anti-commute by including a factor of i. For 2 Pauli operators A and B that anti-commute, A.multiply_with_anticommuting_operator(B) returns the SignedPauliOp i * A * B.

Parameters:

other (SignedPauliOp) – The other Pauli operator to multiply with.

Returns:

The product of the two Pauli operators with a factor of i.

Return type:

SignedPauliOp

reindexed(qubit_map, nqubits=None)[source]

Return a copy of the operator with the qubits reindexed according to the qubit map.

Parameters:
  • qubit_map (list[int]) – The mapping of the new qubit indices to the old qubit indices.

  • nqubits (int | None) – The total number of qubits the Pauli operator acts on. If None, the number of qubits is inferred from the maximum index in the qubit map.

Returns:

The Pauli operator with the reindexed qubits.

Return type:

SignedPauliOp

property sign: int8

The sign of the Pauli operator, either 0 or 1.

with_flipped_sign()[source]

Return a copy of the operator with the sign flipped.

Returns:

The Pauli operator with the sign flipped.

Return type:

SignedPauliOp

class loom.eka.utilities.pauli_binary_vector_rep.UnsignedPauliOp(array, validated=False)[source]

Bases: PauliOp

A class describing an UnsignedPauliOp, a Pauli operator without a sign.

Initialization of the UnsignedPauliOp via a numpy array.

Parameters:

array (np.ndarray | Sequence) – The array representation of the UnsignedPauliOp

copy()[source]

Returns a deep copy of the UnsignedPauliOp object.

Return type:

UnsignedPauliOp

classmethod from_string(pauli_str)[source]

Create an UnsignedPauliOp from a Pauli string, like “IXZZY”

Parameters:

pauli_str (str) – The Pauli string to create the UnsignedPauliOp from.

Returns:

The UnsignedPauliOp created from the Pauli string.

Return type:

UnsignedPauliOp

loom.eka.utilities.pauli_binary_vector_rep.pauliops_anti_commute(op1, op2)[source]

Given two pauli strings, find their anti-commutation value. A value of 0 means that they commute and a value of 1 means that they anti-commute.

Parameters:
  • op1 (PauliOp) – One of the Pauli operators.

  • op2 (PauliOp) – The other Pauli operator.

Returns:

The anti-commutation value of the two Pauli operators. 0 if they commute, 1 if they anti-commute.

Return type:

int