# qml.pauli_decompose¶

pauli_decompose(H, hide_identity=False, wire_order=None, pauli=False)[source]

Decomposes a Hermitian matrix into a linear combination of Pauli operators.

Parameters
• H (array[complex]) – a Hermitian matrix of dimension $$2^n\times 2^n$$.

• hide_identity (bool) – does not include the Identity observable within the tensor products of the decomposition if True.

• wire_order (list[Union[int, str]]) – the ordered list of wires with respect to which the operator is represented as a matrix.

• pauli (bool) – return a PauliSentence instance if True.

Returns

the matrix decomposed as a linear combination of Pauli operators, either as a Hamiltonian or PauliSentence instance.

Return type

Union[Hamiltonian, PauliSentence]

Example:

We can use this function to compute the Pauli operator decomposition of an arbitrary Hermitian matrix:

>>> A = np.array(
... [[-2, -2+1j, -2, -2], [-2-1j,  0,  0, -1], [-2,  0, -2, -1], [-2, -1, -1,  0]])
>>> H = qml.pauli_decompose(A)
>>> print(H)
(-1.5) [I0 X1]
+ (-1.5) [X0 I1]
+ (-1.0) [I0 I1]
+ (-1.0) [I0 Z1]
+ (-1.0) [X0 X1]
+ (-0.5) [I0 Y1]
+ (-0.5) [X0 Z1]
+ (-0.5) [Z0 X1]
+ (-0.5) [Z0 Y1]
+ (1.0) [Y0 Y1]


We can return a PauliSentence instance by using the keyword argument pauli=True:

>>> ps = qml.pauli_decompose(A, pauli=True)
>>> print(ps)
-1.0 * I
+ -1.5 * X(1)
+ -0.5 * Y(1)
+ -1.0 * Z(1)
+ -1.5 * X(0)
+ -1.0 * X(0) @ X(1)
+ -0.5 * X(0) @ Z(1)
+ 1.0 * Y(0) @ Y(1)
+ -0.5 * Z(0) @ X(1)
+ -0.5 * Z(0) @ Y(1)


We can also set custom wires using the wire_order argument:

>>> ps = qml.pauli_decompose(A, pauli=True, wire_order=['a', 'b'])
>>> print(ps)
-1.0 * I
+ -1.5 * X(b)
+ -0.5 * Y(b)
+ -1.0 * Z(b)
+ -1.5 * X(a)
+ -1.0 * X(a) @ X(b)
+ -0.5 * X(a) @ Z(b)
+ 1.0 * Y(a) @ Y(b)
+ -0.5 * Z(a) @ X(b)
+ -0.5 * Z(a) @ Y(b)