# qml.FockStateProjector¶

class FockStateProjector(n, wires)[source]

The number state observable $$\ket{n}\bra{n}$$.

Represents the non-Gaussian number state observable

$\ket{n}\bra{n} = \ket{n_0, n_1, \dots, n_P}\bra{n_0, n_1, \dots, n_P}$

where $$n_i$$ is the occupation number of the $$i$$ th wire.

The expectation of this observable is

$E[\ket{n}\bra{n}] = \text{Tr}(\ket{n}\bra{n}\rho) = \text{Tr}(\braketT{n}{\rho}{n}) = \braketT{n}{\rho}{n}$

corresponding to the probability of measuring the quantum state in the state $$\ket{n}=\ket{n_0, n_1, \dots, n_P}$$.

Note

If expval(FockStateProjector) is applied to a subset of wires, the unaffected wires are traced out prior to the expectation value calculation.

Details:

• Number of wires: Any

• Number of parameters: 1

• Observable order: None (non-Gaussian)

Parameters

n (array) –

Array of non-negative integers representing the number state observable $$\ket{n}\bra{n}=\ket{n_0, n_1, \dots, n_P}\bra{n_0, n_1, \dots, n_P}$$.

For example, to return the observable $$\ket{0,4,2}\bra{0,4,2}$$ acting on wires 0, 1, and 3 of a QNode, you would call FockStateProjector(np.array([0, 4, 2], wires=[0, 1, 3])).

Note that len(n)==len(wires), and that len(n) cannot exceed the total number of wires in the QNode.

 do_check_domain eigvals Eigenvalues of an instantiated observable. ev_order 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 supports_heisenberg wires Wire values.
do_check_domain = True
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

ev_order = None
grad_method = None
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
supports_heisenberg = False
wires

Wire values.

Returns

wire values

Return type

tuple[int]

 check_domain(p[, flattened]) Check the validity of a parameter. Returns the list of operations such that they diagonalize the observable in the computational basis. heisenberg_expand(U, num_wires) Expand the given local Heisenberg-picture array into a full-system one. heisenberg_obs(num_wires) Representation of the observable in the position/momentum operator basis. 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

diagonalizing_gates()

Returns the list of operations such that they diagonalize the observable in the computational basis.

Returns

A list of gates that diagonalize the observable in the computational basis.

Return type

list(qml.Operation)

heisenberg_expand(U, num_wires)

Expand the given local Heisenberg-picture array into a full-system one.

Parameters
• U (array[float]) – array to expand (expected to be of the dimension 1+2*self.num_wires)

• num_wires (int) – total number of wires in the quantum circuit. If zero, return U as is.

Raises

ValueError – if the size of the input matrix is invalid or num_wires is incorrect

Returns

expanded array, dimension 1+2*num_wires

Return type

array[float]

heisenberg_obs(num_wires)

Representation of the observable in the position/momentum operator basis.

Returns the expansion $$q$$ of the observable, $$Q$$, in the basis $$\mathbf{r} = (\I, \x_0, \p_0, \x_1, \p_1, \ldots)$$.

• For first-order observables returns a real vector such that $$Q = \sum_i q_i \mathbf{r}_i$$.

• For second-order observables returns a real symmetric matrix such that $$Q = \sum_{ij} q_{ij} \mathbf{r}_i \mathbf{r}_j$$.

Parameters

num_wires (int) – total number of wires in the quantum circuit

Returns

$$q$$

Return type

array[float]

queue()

Append the operator to the Operator queue.