pytket.pauli¶
This module gives basic Pauli data structures in tket.
- enum pytket.pauli.Pauli(value)¶
Valid values are as follows:
- I = Pauli.I¶
- X = Pauli.X¶
- Y = Pauli.Y¶
- Z = Pauli.Z¶
- class pytket.pauli.PauliStabiliser¶
A string of Pauli letters from the alphabet {I, X, Y, Z} with a +/- 1 coefficient.
- __init__(self) None ¶
- __init__(self, string: collections.abc.Sequence[pytket.pauli.Pauli], coeff: int) None
Overloaded function.
__init__(self) -> None
Constructs an empty PauliStabiliser.
__init__(self, string: collections.abc.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__(self) None ¶
- __init__(self, qubit: pytket.unit_id.Qubit, pauli: pytket.pauli.Pauli) None
- __init__(self, qubits: collections.abc.Sequence[pytket.unit_id.Qubit], paulis: collections.abc.Sequence[pytket.pauli.Pauli]) None
- __init__(self, map: collections.abc.Mapping[pytket.unit_id.Qubit, pytket.pauli.Pauli]) None
Overloaded function.
__init__(self) -> None
Constructs an empty QubitPauliString.
__init__(self, qubit: pytket.unit_id.Qubit, pauli: pytket.pauli.Pauli) -> None
Constructs a QubitPauliString with a single Pauli term.
__init__(self, qubits: collections.abc.Sequence[pytket.unit_id.Qubit], paulis: collections.abc.Sequence[pytket.pauli.Pauli]) -> None
Constructs a QubitPauliString from two matching lists of Qubits and Paulis.
__init__(self, map: collections.abc.Mapping[pytket.unit_id.Qubit, pytket.pauli.Pauli]) -> None
Construct a QubitPauliString from a dictionary mapping
Qubit
toPauli
.
- commutes_with(self, other: pytket.pauli.QubitPauliString) bool ¶
- Returns:
True if the two strings commute, else False
- dot_state(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) numpy.ndarray[dtype=complex128, shape=(*), order='C'] ¶
- dot_state(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) numpy.ndarray[dtype=complex128, shape=(*), order='C']
Overloaded function.
dot_state(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) -> numpy.ndarray[dtype=complex128, shape=(*), order='C']
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, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) -> numpy.ndarray[dtype=complex128, shape=(*), order='C']
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
- from_list(arg: list, /) pytket.pauli.QubitPauliString ¶
Construct a new QubitPauliString instance from a JSON serializable list representation.
- state_expectation(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) complex ¶
- state_expectation(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) complex
Overloaded function.
state_expectation(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) -> 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, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.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) list ¶
A JSON-serializable representation of the QubitPauliString.
- Returns:
a list of
Qubit
-to-Pauli
entries, represented as dicts.
- to_sparse_matrix(self) scipy.sparse.csc_matrix[complex] ¶
- to_sparse_matrix(self, n_qubits: int) scipy.sparse.csc_matrix[complex]
- to_sparse_matrix(self, qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) scipy.sparse.csc_matrix[complex]
Overloaded function.
to_sparse_matrix(self) -> scipy.sparse.csc_matrix[complex]
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, n_qubits: int) -> scipy.sparse.csc_matrix[complex]
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, qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) -> scipy.sparse.csc_matrix[complex]
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.pauli.QubitPauliTensor¶
A tensor formed by Pauli terms, consisting of a sparse map from
Qubit
toPauli
(implemented as aQubitPauliString
) and a complex coefficient.- __init__(self, coeff: complex = 1.0) None ¶
- __init__(self, qubit: pytket.unit_id.Qubit, pauli: pytket.pauli.Pauli, coeff: complex = 1.0) None
- __init__(self, qubits: collections.abc.Sequence[pytket.unit_id.Qubit], paulis: collections.abc.Sequence[pytket.pauli.Pauli], coeff: complex = 1.0) None
- __init__(self, map: collections.abc.Mapping[pytket.unit_id.Qubit, pytket.pauli.Pauli], coeff: complex = 1.0) None
- __init__(self, string: pytket.pauli.QubitPauliString, coeff: complex = 1.0) None
Overloaded function.
__init__(self, coeff: complex = 1.0) -> None
Constructs an empty QubitPauliTensor, representing the identity.
__init__(self, qubit: pytket.unit_id.Qubit, pauli: pytket.pauli.Pauli, coeff: complex = 1.0) -> None
Constructs a QubitPauliTensor with a single Pauli term.
__init__(self, qubits: collections.abc.Sequence[pytket.unit_id.Qubit], paulis: collections.abc.Sequence[pytket.pauli.Pauli], coeff: complex = 1.0) -> None
Constructs a QubitPauliTensor from two matching lists of Qubits and Paulis.
__init__(self, map: collections.abc.Mapping[pytket.unit_id.Qubit, pytket.pauli.Pauli], coeff: complex = 1.0) -> None
Construct a QubitPauliTensor from a dictionary mapping
Qubit
toPauli
.__init__(self, string: pytket.pauli.QubitPauliString, coeff: complex = 1.0) -> None
Construct a QubitPauliTensor from a QubitPauliString.
- property coeff¶
The global coefficient of the tensor
- commutes_with(self, other: pytket.pauli.QubitPauliTensor) bool ¶
- Returns:
True if the two tensors commute, else False
- dot_state(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) numpy.ndarray[dtype=complex128, shape=(*), order='C'] ¶
- dot_state(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) numpy.ndarray[dtype=complex128, shape=(*), order='C']
Overloaded function.
dot_state(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) -> numpy.ndarray[dtype=complex128, shape=(*), order='C']
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, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) -> numpy.ndarray[dtype=complex128, shape=(*), order='C']
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(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) complex ¶
- state_expectation(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) complex
Overloaded function.
state_expectation(self, state: numpy.ndarray[dtype=complex128, shape=(*), order='C']) -> 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, state: numpy.ndarray[dtype=complex128, shape=(*), order='C'], qubits: collections.abc.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
- property string¶
The QubitPauliTensor’s underlying
QubitPauliString
- to_sparse_matrix(self) scipy.sparse.csc_matrix[complex] ¶
- to_sparse_matrix(self, n_qubits: int) scipy.sparse.csc_matrix[complex]
- to_sparse_matrix(self, qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) scipy.sparse.csc_matrix[complex]
Overloaded function.
to_sparse_matrix(self) -> scipy.sparse.csc_matrix[complex]
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, n_qubits: int) -> scipy.sparse.csc_matrix[complex]
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, qubits: collections.abc.Sequence[pytket.unit_id.Qubit]) -> scipy.sparse.csc_matrix[complex]
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