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)

wires

Track wires of the PauliSentence.

wires

Track wires of the PauliSentence.

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, buffer_size])

Returns the matrix representation.

hamiltonian(wire_order=None)[source]

Returns a native PennyLane Hamiltonian representing the PauliSentence.

map_wires(wire_map)[source]

Return a new PauliSentence with the wires mapped.

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=None, format='dense', buffer_size=None)[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. It is “dense” by default. Use “csr” for sparse.

  • buffer_size (int or None) – The maximum allowed memory in bytes to store intermediate results in the calculation of sparse matrices. It defaults to 2 ** 30 bytes that make 1GB of memory. In general, larger buffers allow faster computations.

Returns

Matrix representation of the Pauli sentence.

Return type

(Union[NumpyArray, ScipySparseArray])

Rasies:

ValueError: Can’t get the matrix of an empty PauliSentence.