# qml.Hermitian¶

class Hermitian(A, wires)[source]

An arbitrary Hermitian observable.

For a Hermitian matrix $$A$$, the expectation command returns the value

$\braket{A} = \braketT{\psi}{\cdots \otimes I\otimes A\otimes I\cdots}{\psi}$

where $$A$$ acts on the requested wires.

If acting on $$N$$ wires, then the matrix $$A$$ must be of size $$2^N\times 2^N$$.

Details:

• Number of wires: Any

• Number of parameters: 1

• Gradient recipe: None

Parameters
• A (array) – square hermitian matrix

• wires (Sequence[int] or int) – the wire(s) the operation acts on

 do_check_domain eigendecomposition Return the eigendecomposition of the matrix specified by the Hermitian observable. eigvals Return the eigenvalues of the specified Hermitian observable. grad_method matrix Matrix representation of an instantiated operator in the computational basis. name String for the name of the operator. num_params num_wires par_domain parameters Current parameter values. return_type wires Wires of this operator.
do_check_domain = True
eigendecomposition

Return the eigendecomposition of the matrix specified by the Hermitian observable.

This method uses pre-stored eigenvalues for standard observables where possible and stores the corresponding eigenvectors from the eigendecomposition.

It transforms the input operator according to the wires specified.

Returns

dictionary containing the eigenvalues and the eigenvectors of the Hermitian observable

Return type

dict[str, array]

eigvals

Return the eigenvalues of the specified Hermitian observable.

This method uses pre-stored eigenvalues for standard observables where possible and stores the corresponding eigenvectors from the eigendecomposition.

Returns

array containing the eigenvalues of the Hermitian observable

Return type

array

grad_method = 'F'
matrix

Matrix representation of an instantiated operator in the computational basis.

Example:

>>> U = qml.RY(0.5, wires=1)
>>> U.matrix
>>> array([[ 0.96891242+0.j, -0.24740396+0.j],
[ 0.24740396+0.j,  0.96891242+0.j]])

Returns

matrix representation

Return type

array

name

String for the name of the operator.

num_params = 1
num_wires = -1
par_domain = 'A'
parameters

Current parameter values.

Fixed parameters are returned as is, free parameters represented by Variable instances are replaced by their current numerical value.

Returns

parameter values

Return type

list[Any]

return_type = None
wires

Wires of this operator.

Returns

wires

Return type

Wires

 check_domain(p[, flattened]) Check the validity of a parameter. compare(other) Compares with another Hamiltonian, Tensor, or Observable, to determine if they are equivalent. Return the gate set that diagonalizes a circuit according to the specified Hermitian observable. Append the operator to the Operator queue.
check_domain(p, flattened=False)

Check the validity of a parameter.

Variable instances can represent any real scalars (but not arrays).

Parameters
• p (Number, array, Variable) – parameter to check

• flattened (bool) – True means p is an element of a flattened parameter sequence (affects the handling of ‘A’ parameters)

Raises
• TypeError – parameter is not an element of the expected domain

• ValueError – parameter is an element of an unknown domain

Returns

p

Return type

Number, array, Variable

compare(other)

Compares with another Hamiltonian, Tensor, or Observable, to determine if they are equivalent.

Observables/Hamiltonians are equivalent if they represent the same operator (their matrix representations are equal), and they are defined on the same wires.

Warning

The compare method does not check if the matrix representation of a Hermitian observable is equal to an equivalent observable expressed in terms of Pauli matrices. To do so would require the matrix form of Hamiltonians and Tensors be calculated, which would drastically increase runtime.

Returns

True if equivalent.

Return type

(bool)

Examples

>>> ob1 = qml.PauliX(0) @ qml.Identity(1)
>>> ob2 = qml.Hamiltonian([1], [qml.PauliX(0)])
>>> ob1.compare(ob2)
True
>>> ob1 = qml.PauliX(0)
>>> ob2 = qml.Hermitian(np.array([[0, 1], [1, 0]]), 0)
>>> ob1.compare(ob2)
False

diagonalizing_gates()[source]

Return the gate set that diagonalizes a circuit according to the specified Hermitian observable.

This method uses pre-stored eigenvalues for standard observables where possible and stores the corresponding eigenvectors from the eigendecomposition.

Returns

list containing the gates diagonalizing the Hermitian observable

Return type

list

queue()

Append the operator to the Operator queue.