qml.pauli.PauliSentence¶
-
class
PauliSentence
[source]¶ Bases:
dict
Dictionary representing a linear combination of Pauli words, with the keys as PauliWord instances and the values correspond to coefficients.
>>> ps = qml.pauli.PauliSentence({ qml.pauli.PauliWord({0:'X', 1:'Y'}): 1.23, qml.pauli.PauliWord({2:'Z', 0:'Y'}): -0.45j }) >>> ps 1.23 * X(0) @ Y(1) + (-0-0.45j) * Z(2) @ Y(0)
Attributes
Methods
hamiltonian
([wire_order])Returns a native PennyLane
Hamiltonian
representing the PauliSentence.map_wires
(wire_map)Return a new PauliSentence with the wires mapped.
operation
([wire_order])Returns a native PennyLane
Operation
representing the PauliSentence.simplify
([tol])Remove any PauliWords in the PauliSentence with coefficients less than the threshold tolerance.
to_mat
(wire_order[, format])Returns the matrix representation.
-
hamiltonian
(wire_order=None)[source]¶ Returns a native PennyLane
Hamiltonian
representing the PauliSentence.
-
operation
(wire_order=None)[source]¶ Returns a native PennyLane
Operation
representing the PauliSentence.
-
simplify
(tol=1e-08)[source]¶ Remove any PauliWords in the PauliSentence with coefficients less than the threshold tolerance.
-
to_mat
(wire_order, format='dense')[source]¶ Returns the matrix representation.
- Keyword Arguments
wire_order (iterable or None) – The order of qubits in the tensor product.
format (str) – The format of the matrix (“dense” by default), if not a dense matrix, then the format for the sparse representation of the matrix.
- Returns
Matrix representation of the PauliSentence.
- Return type
(Union[NumpyArray, ScipySparseArray])
- Rasies:
ValueError: Can’t get the matrix of an empty PauliSentence.
-