qml.labs.dla.pauli_coefficients¶
- pauli_coefficients(H)[source]¶
Computes the coefficients of one or multiple Hermitian matrices in the Pauli basis.
The coefficients are ordered lexicographically in the Pauli group,
["III", "IIX", "IIY", "IIZ", "IXI", ...]
.- Parameters:
H (tensor_like[complex]) – a Hermitian matrix of dimension
(2**n, 2**n)
or a collection of Hermitian matrices of dimension(batch, 2**n, 2**n)
.- Returns:
The coefficients of
H
in the Pauli basis with shape(4**n,)
for a single matrix input and(batch, 4**n)
for a collection of matrices. The output is real-valued.- Return type:
np.ndarray
See
pauli_decompose()
for theoretical background information.Examples
Consider the Hamiltonian \(H=\frac{1}{4} X_0 + \frac{2}{5} Z_0 X_1\) with matrix
>>> H = 1 / 4 * qml.X(0) + 2 / 5 * qml.Z(0) @ qml.X(1) >>> mat = H.matrix() >>> mat array([[ 0. +0.j, 0.4 +0.j, 0.25+0.j, 0. +0.j], [ 0.4 +0.j, 0. +0.j, 0. +0.j, 0.25+0.j], [ 0.25+0.j, 0. +0.j, 0. +0.j, -0.4 +0.j], [ 0. +0.j, 0.25+0.j, -0.4 +0.j, 0. +0.j]])
Then we can obtain the coefficients of \(H\) in the Pauli basis via
>>> from pennylane.labs.dla import pauli_coefficients >>> pauli_coefficients(mat) array([ 0. , 0. , 0. , 0. , 0.25, 0. , 0. , 0. , 0. , 0. , -0. , 0. , 0. , 0.4 , 0. , 0. ])
The function can be used on a batch of matrices:
>>> ops = [1 / 4 * qml.X(0), 1 / 2 * qml.Z(0), 3 / 5 * qml.Y(0)] >>> batch = np.stack([op.matrix() for op in ops]) >>> pauli_coefficients(batch) array([[0. , 0.25, 0. , 0. ], [0. , 0. , 0. , 0.5 ], [0. , 0. , 0.6 , 0. ]])