pytket.pauli#

class pytket.pauli.Pauli#

Members:

I

X

Y

Z

__init__(self: pytket.pauli.Pauli, value: int) None#
property name#
class pytket.pauli.PauliStabiliser#

A string of Pauli letters from the alphabet {I, X, Y, Z} with a +/- 1 coefficient.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pytket.pauli.PauliStabiliser) -> None

Constructs an empty PauliStabiliser.

  1. __init__(self: pytket.pauli.PauliStabiliser, string: Sequence[pytket.pauli.Pauli], coeff: int) -> None

Constructs a PauliStabiliser with a list of Pauli terms.

property coeff#

The coefficient of the stabiliser

property string#

The list of Pauli terms

class pytket.pauli.QubitPauliString#

A string of Pauli letters from the alphabet {I, X, Y, Z}, implemented as a sparse list, indexed by qubit.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pytket.pauli.QubitPauliString) -> None

Constructs an empty QubitPauliString.

  1. __init__(self: pytket.pauli.QubitPauliString, qubit: pytket.unit_id.Qubit, pauli: pytket.pauli.Pauli) -> None

Constructs a QubitPauliString with a single Pauli term.

  1. __init__(self: pytket.pauli.QubitPauliString, qubits: Sequence[pytket.unit_id.Qubit], paulis: Sequence[pytket.pauli.Pauli]) -> None

Constructs a QubitPauliString from two matching lists of Qubits and Paulis.

  1. __init__(self: pytket.pauli.QubitPauliString, map: dict[pytket.unit_id.Qubit, pytket.pauli.Pauli]) -> None

Construct a QubitPauliString from a dictionary mapping Qubit to Pauli.

commutes_with(self: pytket.pauli.QubitPauliString, other: pytket.pauli.QubitPauliString) bool#
Returns:

True if the two strings commute, else False

compress(self: pytket.pauli.QubitPauliString) None#

Removes I terms to compress the sparse representation.

dot_state(*args, **kwargs)#

Overloaded function.

  1. dot_state(self: pytket.pauli.QubitPauliString, state: numpy.ndarray[numpy.complex128[m, 1]]) -> numpy.ndarray[numpy.complex128[m, 1]]

Performs the dot product of the state with the pauli string. Maps the qubits of the statevector with sequentially-indexed qubits in the default register, with Qubit(0) being the most significant qubit.

Parameters:

state – statevector for qubits Qubit(0) to Qubit(n-1)

Returns:

dot product of operator with state

  1. dot_state(self: pytket.pauli.QubitPauliString, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket.unit_id.Qubit]) -> numpy.ndarray[numpy.complex128[m, 1]]

Performs the dot product of the state with the pauli string. Maps the qubits of the statevector according to the ordered list qubits, with qubits[0] being the most significant qubit.

Parameters:
  • state – statevector

  • qubits – order of qubits in state from most to least significant

Returns:

dot product of operator with state

static from_list(arg0: list) pytket.pauli.QubitPauliString#

Construct a new QubitPauliString instance from a JSON serializable list representation.

state_expectation(*args, **kwargs)#

Overloaded function.

  1. state_expectation(self: pytket.pauli.QubitPauliString, state: numpy.ndarray[numpy.complex128[m, 1]]) -> complex

Calculates the expectation value of the state with the pauli string. Maps the qubits of the statevector with sequentially-indexed qubits in the default register, with Qubit(0) being the most significant qubit.

Parameters:

state – statevector for qubits Qubit(0) to Qubit(n-1)

Returns:

expectation value with respect to state

  1. state_expectation(self: pytket.pauli.QubitPauliString, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket.unit_id.Qubit]) -> complex

Calculates the expectation value of the state with the pauli string. Maps the qubits of the statevector according to the ordered list qubits, with qubits[0] being the most significant qubit.

Parameters:
  • state – statevector

  • qubits – order of qubits in state from most to least significant

Returns:

expectation value with respect to state

to_list(self: pytket.pauli.QubitPauliString) list#

A JSON-serializable representation of the QubitPauliString.

Returns:

a list of Qubit-to-Pauli entries, represented as dicts.

to_sparse_matrix(*args, **kwargs)#

Overloaded function.

  1. to_sparse_matrix(self: pytket.pauli.QubitPauliString) -> scipy.sparse.csc_matrix[numpy.complex128]

Represents the sparse string as a dense string (without padding for extra qubits) and generates the matrix for the tensor. Uses the ILO-BE convention, so Qubit("a", 0) is more significant that Qubit("a", 1) and Qubit("b") for indexing into the matrix.

Returns:

a sparse matrix corresponding to the operator

  1. to_sparse_matrix(self: pytket.pauli.QubitPauliString, n_qubits: int) -> scipy.sparse.csc_matrix[numpy.complex128]

Represents the sparse string as a dense string over n_qubits qubits (sequentially indexed from 0 in the default register) and generates the matrix for the tensor. Uses the ILO-BE convention, so Qubit(0) is the most significant bit for indexing into the matrix.

Parameters:

n_qubits – the number of qubits in the full operator

Returns:

a sparse matrix corresponding to the operator

  1. to_sparse_matrix(self: pytket.pauli.QubitPauliString, qubits: Sequence[pytket.unit_id.Qubit]) -> scipy.sparse.csc_matrix[numpy.complex128]

Represents the sparse string as a dense string and generates the matrix for the tensor. Orders qubits according to qubits (padding with identities if they are not in the sparse string), so qubits[0] is the most significant bit for indexing into the matrix.

Parameters:

qubits – the ordered list of qubits in the full operator

Returns:

a sparse matrix corresponding to the operator

property map#
Returns:

the QubitPauliString’s underlying dict mapping Qubit to Pauli

class pytket.pauli.QubitPauliTensor#

A tensor formed by Pauli terms, consisting of a sparse map from Qubit to Pauli (implemented as a QubitPauliString) and a complex coefficient.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: pytket.pauli.QubitPauliTensor, coeff: complex = 1.0) -> None

Constructs an empty QubitPauliTensor, representing the identity.

  1. __init__(self: pytket.pauli.QubitPauliTensor, qubit: pytket.unit_id.Qubit, pauli: pytket.pauli.Pauli, coeff: complex = 1.0) -> None

Constructs a QubitPauliTensor with a single Pauli term.

  1. __init__(self: pytket.pauli.QubitPauliTensor, qubits: Sequence[pytket.unit_id.Qubit], paulis: Sequence[pytket.pauli.Pauli], coeff: complex = 1.0) -> None

Constructs a QubitPauliTensor from two matching lists of Qubits and Paulis.

  1. __init__(self: pytket.pauli.QubitPauliTensor, map: dict[pytket.unit_id.Qubit, pytket.pauli.Pauli], coeff: complex = 1.0) -> None

Construct a QubitPauliTensor from a dictionary mapping Qubit to Pauli.

  1. __init__(self: pytket.pauli.QubitPauliTensor, string: pytket.pauli.QubitPauliString, coeff: complex = 1.0) -> None

Construct a QubitPauliTensor from a QubitPauliString.

commutes_with(self: pytket.pauli.QubitPauliTensor, other: pytket.pauli.QubitPauliTensor) bool#
Returns:

True if the two tensors commute, else False

compress(self: pytket.pauli.QubitPauliTensor) None#

Removes I terms to compress the sparse representation.

dot_state(*args, **kwargs)#

Overloaded function.

  1. dot_state(self: pytket.pauli.QubitPauliTensor, state: numpy.ndarray[numpy.complex128[m, 1]]) -> numpy.ndarray[numpy.complex128[m, 1]]

Performs the dot product of the state with the pauli tensor. Maps the qubits of the statevector with sequentially-indexed qubits in the default register, with Qubit(0) being the most significant qubit.

Parameters:

state – statevector for qubits Qubit(0) to Qubit(n-1)

Returns:

dot product of operator with state

  1. dot_state(self: pytket.pauli.QubitPauliTensor, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket.unit_id.Qubit]) -> numpy.ndarray[numpy.complex128[m, 1]]

Performs the dot product of the state with the pauli tensor. Maps the qubits of the statevector according to the ordered list qubits, with qubits[0] being the most significant qubit.

Parameters:
  • state – statevector

  • qubits – order of qubits in state from most to least significant

Returns:

dot product of operator with state

state_expectation(*args, **kwargs)#

Overloaded function.

  1. state_expectation(self: pytket.pauli.QubitPauliTensor, state: numpy.ndarray[numpy.complex128[m, 1]]) -> complex

Calculates the expectation value of the state with the pauli operator. Maps the qubits of the statevector with sequentially-indexed qubits in the default register, with Qubit(0) being the most significant qubit.

Parameters:

state – statevector for qubits Qubit(0) to Qubit(n-1)

Returns:

expectation value with respect to state

  1. state_expectation(self: pytket.pauli.QubitPauliTensor, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket.unit_id.Qubit]) -> complex

Calculates the expectation value of the state with the pauli operator. Maps the qubits of the statevector according to the ordered list qubits, with qubits[0] being the most significant qubit.

Parameters:
  • state – statevector

  • qubits – order of qubits in state from most to least significant

Returns:

expectation value with respect to state

to_sparse_matrix(*args, **kwargs)#

Overloaded function.

  1. to_sparse_matrix(self: pytket.pauli.QubitPauliTensor) -> scipy.sparse.csc_matrix[numpy.complex128]

Represents the sparse string as a dense string (without padding for extra qubits) and generates the matrix for the tensor. Uses the ILO-BE convention, so Qubit("a", 0) is more significant that Qubit("a", 1) and Qubit("b") for indexing into the matrix.

Returns:

a sparse matrix corresponding to the tensor

  1. to_sparse_matrix(self: pytket.pauli.QubitPauliTensor, n_qubits: int) -> scipy.sparse.csc_matrix[numpy.complex128]

Represents the sparse string as a dense string over n_qubits qubits (sequentially indexed from 0 in the default register) and generates the matrix for the tensor. Uses the ILO-BE convention, so Qubit(0) is the most significant bit for indexing into the matrix.

Parameters:

n_qubits – the number of qubits in the full operator

Returns:

a sparse matrix corresponding to the operator

  1. to_sparse_matrix(self: pytket.pauli.QubitPauliTensor, qubits: Sequence[pytket.unit_id.Qubit]) -> scipy.sparse.csc_matrix[numpy.complex128]

Represents the sparse string as a dense string and generates the matrix for the tensor. Orders qubits according to qubits (padding with identities if they are not in the sparse string), so qubits[0] is the most significant bit for indexing into the matrix.

Parameters:

qubits – the ordered list of qubits in the full operator

Returns:

a sparse matrix corresponding to the operator

property coeff#

The global coefficient of the tensor

property string#

The QubitPauliTensor’s underlying QubitPauliString

pytket.pauli.pauli_string_mult(qubitpaulistring1: pytket.pauli.QubitPauliString, qubitpaulistring2: pytket.pauli.QubitPauliString) tuple[pytket.pauli.QubitPauliString, complex]#
Returns:

the product of two QubitPauliString objects as a pair (QubitPauliString, complex)