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 = PauliSentence({
        PauliWord({0:'X', 1:'Y'}): 1.23,
        PauliWord({2:'Z', 0:'Y'}): -0.45j
    })
>>> ps
1.23 * X(0) @ Y(1)
+ (-0-0.45j) * Z(2) @ Y(0)

wires

Track wires of the PauliSentence.

wires

Track wires of 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.

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.