pytket.pauli

class pytket._tket.pauli.Pauli

Members:

I

X

Y

Z

__init__(self: pytket._tket.pauli.Pauli, value: int) None
property name
class pytket._tket.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._tket.pauli.PauliStabiliser) -> None

Constructs an empty PauliStabiliser.

  1. __init__(self: pytket._tket.pauli.PauliStabiliser, string: Sequence[pytket._tket.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._tket.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._tket.pauli.QubitPauliString) -> None

Constructs an empty QubitPauliString.

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

Constructs a QubitPauliString with a single Pauli term.

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

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

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

Construct a QubitPauliString from a dictionary mapping Qubit to Pauli.

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

True if the two strings commute, else False

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

Removes I terms to compress the sparse representation.

dot_state(*args, **kwargs)

Overloaded function.

  1. dot_state(self: pytket._tket.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._tket.pauli.QubitPauliString, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket._tket.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._tket.pauli.QubitPauliString

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

state_expectation(*args, **kwargs)

Overloaded function.

  1. state_expectation(self: pytket._tket.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._tket.pauli.QubitPauliString, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket._tket.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._tket.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._tket.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._tket.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._tket.pauli.QubitPauliString, qubits: Sequence[pytket._tket.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

the QubitPauliString’s underlying dict mapping Qubit to Pauli

Type:

return

class pytket._tket.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._tket.pauli.QubitPauliTensor, coeff: complex = 1.0) -> None

Constructs an empty QubitPauliTensor, representing the identity.

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

Constructs a QubitPauliTensor with a single Pauli term.

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

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

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

Construct a QubitPauliTensor from a dictionary mapping Qubit to Pauli.

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

Construct a QubitPauliTensor from a QubitPauliString.

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

True if the two tensors commute, else False

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

Removes I terms to compress the sparse representation.

dot_state(*args, **kwargs)

Overloaded function.

  1. dot_state(self: pytket._tket.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._tket.pauli.QubitPauliTensor, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket._tket.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._tket.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._tket.pauli.QubitPauliTensor, state: numpy.ndarray[numpy.complex128[m, 1]], qubits: Sequence[pytket._tket.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._tket.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._tket.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._tket.pauli.QubitPauliTensor, qubits: Sequence[pytket._tket.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._tket.pauli.pauli_string_mult(qubitpaulistring1: pytket._tket.pauli.QubitPauliString, qubitpaulistring2: pytket._tket.pauli.QubitPauliString) tuple[pytket._tket.pauli.QubitPauliString, complex]
Returns:

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