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.
__init__(self: pytket._tket.pauli.PauliStabiliser) -> None
Constructs an empty PauliStabiliser.
__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.
__init__(self: pytket._tket.pauli.QubitPauliString) -> None
Constructs an empty QubitPauliString.
__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.
__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.
__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
toPauli
.
- 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.
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)
toQubit(n-1)
- Returns:
dot product of operator with state
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.
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)
toQubit(n-1)
- Returns:
expectation value with respect to state
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.
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 thatQubit("a", 1)
andQubit("b")
for indexing into the matrix.- Returns:
a sparse matrix corresponding to the operator
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
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
- class pytket._tket.pauli.QubitPauliTensor¶
A tensor formed by Pauli terms, consisting of a sparse map from
Qubit
toPauli
(implemented as aQubitPauliString
) and a complex coefficient.- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: pytket._tket.pauli.QubitPauliTensor, coeff: complex = 1.0) -> None
Constructs an empty QubitPauliTensor, representing the identity.
__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.
__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.
__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
toPauli
.__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.
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)
toQubit(n-1)
- Returns:
dot product of operator with state
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.
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)
toQubit(n-1)
- Returns:
expectation value with respect to state
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.
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 thatQubit("a", 1)
andQubit("b")
for indexing into the matrix.- Returns:
a sparse matrix corresponding to the tensor
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
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)