qml.PolyXP¶
-
class
PolyXP
(q, wires)[source]¶ Bases:
pennylane.operation.CVObservable
An arbitrary second-order polynomial observable.
Represents an arbitrary observable \(P(\x,\p)\) that is a second order polynomial in the basis \(\mathbf{r} = (\I, \x_0, \p_0, \x_1, \p_1, \ldots)\).
For first-order observables the representation is a real vector \(\mathbf{d}\) such that \(P(\x,\p) = \mathbf{d}^T \mathbf{r}\).
For second-order observables the representation is a real symmetric matrix \(A\) such that \(P(\x,\p) = \mathbf{r}^T A \mathbf{r}\).
Used by
QNode._pd_analytic()
for evaluating arbitrary order-2 CV expectation values.Details:
Number of wires: Any
Number of parameters: 1
Observable order: 2nd order in the quadrature operators
Heisenberg representation: \(A\)
- Parameters
q (array[float]) – expansion coefficients
Attributes
Eigenvalues of an instantiated observable.
Matrix representation of an instantiated operator in the computational basis.
String for the name of the operator.
Current parameter values.
Wires of this operator.
-
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
= 2¶
-
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¶
-
supports_heisenberg
= True¶
Methods
check_domain
(p[, flattened])Check the validity of a parameter.
compare
(other)Compares with another
Hamiltonian
,Tensor
, orObservable
, to determine if they are equivalent.Returns the list of operations such that they diagonalize the observable in the computational basis.
heisenberg_expand
(U, wires)Expand the given local Heisenberg-picture array into a full-system one.
heisenberg_obs
(wires)Representation of the observable in the position/momentum operator basis.
queue
()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
, orObservable
, 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
()¶ 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, 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
)wires (Wires) – wires on the device the array
U
should be expanded to apply to
- 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
(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
wires (Wires) – wires on the device that the observable gets applied to
- Returns
\(q\)
- Return type
array[float]
-
queue
()¶ Append the operator to the Operator queue.
Contents
Using PennyLane
Development
API
Downloads