qml.Projector

class Projector(basis_state, wires)[source]

Bases: pennylane.operation.Observable

Observable corresponding to the computational basis state projector \(P=\ket{i}\bra{i}\).

The expectation of this observable returns the value

\[|\langle \psi | i \rangle |^2\]

corresponding to the probability of measuring the quantum state in the \(i\) -th eigenstate of the specified \(n\) qubits.

For example, the projector \(\ket{11}\bra{11}\) , or in integer notation \(\ket{3}\bra{3}\), is created by basis_state=np.array([1, 1]).

Details:

  • Number of wires: Any

  • Number of parameters: 1

  • Gradient recipe: None

Parameters
  • basis_state (tensor-like) – binary input of shape (n, )

  • wires (Iterable) – wires that the projector acts on

eigvals

Eigenvalues of an instantiated observable.

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.

eigvals

Eigenvalues of an instantiated observable.

The order of the eigenvalues needs to match the order of the computational basis vectors when the observable is diagonalized using diagonalizing_gates. This is a requirement for using qubit observables in quantum functions.

Example:

>>> U = qml.PauliZ(wires=1)
>>> U.eigvals
>>> array([1, -1])
Returns

eigvals representation

Return type

array

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 Projector observable.

queue()

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 Projector observable.

Returns

list containing the gates diagonalizing the projector observable

Return type

list

queue()

Append the operator to the Operator queue.

Contents

Using PennyLane

Development

API