qml.Hermitian

class Hermitian(A, wires)[source]

Bases: pennylane.operation.Observable

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

eigendecomposition

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

eigvals

Return the eigenvalues of the specified Hermitian observable.

grad_method

hash

returns an integer hash uniquely representing the operator

id

String for the ID of the operator.

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.

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'
hash

returns an integer hash uniquely representing the operator

Type

int

id

String for the ID of the operator.

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.

return_type = None
wires

Wires of this operator.

Returns

wires

Return type

Wires

compare(other)

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

diagonalizing_gates()

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

queue([context])

Append the operator to the Operator queue.

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(context=<class 'pennylane.queuing.QueuingContext'>)

Append the operator to the Operator queue.

Contents

Using PennyLane

Development

API