@@ -27,8 +27,8 @@ serves as the main abstraction of such objects, and all operators (such as gates
2727inherit from it.
2828
2929>>> from jax import numpy as jnp
30- >>> op = qml .Rot(jnp.array(0.1 ), jnp.array(0.2 ), jnp.array(0.3 ), wires = [" a" ])
31- >>> isinstance (op, qml .operation.Operator)
30+ >>> op = qp .Rot(jnp.array(0.1 ), jnp.array(0.2 ), jnp.array(0.3 ), wires = [" a" ])
31+ >>> isinstance (op, qp .operation.Operator)
3232True
3333
3434The basic components of operators are the following:
@@ -64,20 +64,20 @@ The basic components of operators are the following:
6464
6565 * Representation as a **product of operators ** (:meth: `.Operator.decomposition `):
6666
67- >>> op = qml .Rot(0.1 , 0.2 , 0.3 , wires = [" a" ])
67+ >>> op = qp .Rot(0.1 , 0.2 , 0.3 , wires = [" a" ])
6868 >>> op.decomposition()
6969 [RZ(0.1, wires=['a']), RY(0.2, wires=['a']), RZ(0.3, wires=['a'])]
7070
7171 * Representation as a **linear combination of operators ** (:meth: `.Operator.terms `):
7272
73- >>> op = qml .Hamiltonian([1 ., 2 .], [qml .PauliX(0 ), qml .PauliZ(0 )])
73+ >>> op = qp .Hamiltonian([1 ., 2 .], [qp .PauliX(0 ), qp .PauliZ(0 )])
7474 >>> op.terms()
7575 ((1.0, 2.0), [PauliX(wires=[0]), PauliZ(wires=[0])])
7676
7777 * Representation via the **eigenvalue decomposition ** specified by eigenvalues (for the diagonal matrix, :meth: `.Operator.eigvals `)
7878 and diagonalizing gates (for the unitaries :meth: `.Operator.diagonalizing_gates `):
7979
80- >>> op = qml .PauliX(0 )
80+ >>> op = qp .PauliX(0 )
8181 >>> op.diagonalizing_gates()
8282 [H(0)]
8383 >>> op.eigvals()
@@ -86,7 +86,7 @@ The basic components of operators are the following:
8686 * Representation as a **matrix ** (:meth: `.Operator.matrix `), as specified by a global wire order that tells us where the
8787 wires are found on a register:
8888
89- >>> op = qml .PauliRot(0.2 , " X" , wires = [" b" ])
89+ >>> op = qp .PauliRot(0.2 , " X" , wires = [" b" ])
9090 >>> op.matrix(wire_order = [" a" , " b" ])
9191 [[9.95e-01-2.26e-18j 2.72e-17-9.98e-02j, 0+0j, 0+0j]
9292 [2.72e-17-9.98e-02j 9.95e-01-2.26e-18j, 0+0j, 0+0j]
@@ -100,7 +100,7 @@ The basic components of operators are the following:
100100 >>> col = np.array([1 , 0 ])
101101 >>> data = np.array([1 , - 1 ])
102102 >>> mat = coo_matrix((data, (row, col)), shape = (4 , 4 ))
103- >>> op = qml .SparseHamiltonian(mat, wires = [" a" ])
103+ >>> op = qp .SparseHamiltonian(mat, wires = [" a" ])
104104 >>> op.sparse_matrix(wire_order = [" a" ])
105105 (0, 1) 1
106106 (1, 0) - 1
@@ -111,7 +111,7 @@ specific subclasses.
111111
112112* Operators inheriting from :class: `~.Operator ` support addition and scalar multiplication:
113113
114- >>> op = qml .PauliX(0 ) + 0.1 * qml .PauliZ(0 )
114+ >>> op = qp .PauliX(0 ) + 0.1 * qp .PauliZ(0 )
115115 >>> op.name
116116 Hamiltonian
117117 >>> op
@@ -120,7 +120,7 @@ specific subclasses.
120120
121121* Operators may define a hermitian conjugate:
122122
123- >>> qml .RX(1 ., wires = 0 ).adjoint()
123+ >>> qp .RX(1 ., wires = 0 ).adjoint()
124124 RX(-1.0, wires=[0])
125125
126126Creating custom operators
@@ -137,7 +137,7 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint
137137 import pennylane as qp
138138
139139
140- class FlipAndRotate (qml .operation .Operation ):
140+ class FlipAndRotate (qp .operation .Operation ):
141141
142142 # This attribute tells PennyLane what differentiation method to use. Here
143143 # we request parameter-shift (or "analytic") differentiation.
@@ -152,7 +152,7 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint
152152
153153 # note: we use the framework-agnostic math library since
154154 # trainable inputs could be tensors of different types
155- shape = qml .math.shape(angle)
155+ shape = qp .math.shape(angle)
156156 if len (shape) > 1 :
157157 raise ValueError (f " Expected a scalar angle; got angle of shape { shape} . " )
158158
@@ -166,7 +166,7 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint
166166
167167 # we extract all wires that the operator acts on,
168168 # relying on the Wire class arithmetic
169- all_wires = qml .wires.Wires(wire_rot) + qml .wires.Wires(wire_flip)
169+ all_wires = qp .wires.Wires(wire_rot) + qp .wires.Wires(wire_flip)
170170
171171 # The parent class expects all trainable parameters to be fed as positional
172172 # arguments, and all wires acted on fed as a keyword argument.
@@ -186,8 +186,8 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint
186186 # The general signature of this function is (*parameters, wires, **hyperparameters).
187187 op_list = []
188188 if do_flip:
189- op_list.append(qml .PauliX(wires = wires[1 ]))
190- op_list.append(qml .RX(angle, wires = wires[0 ]))
189+ op_list.append(qp .PauliX(wires = wires[1 ]))
190+ op_list.append(qp .RX(angle, wires = wires[0 ]))
191191 return op_list
192192
193193 def adjoint (self ):
@@ -219,7 +219,7 @@ FlipAndRotate(-0.1, wires=['q3', 'q1'])
219219Once the class has been created, you can run a suite of validation checks using :func: `.ops.functions.assert_valid `.
220220This function will warn you of some common errors in custom operators.
221221
222- >>> qml .ops.functions.assert_valid(op)
222+ >>> qp .ops.functions.assert_valid(op)
223223
224224If the above operator omitted the ``_unflatten `` custom definition, it would raise:
225225
@@ -253,12 +253,12 @@ The new gate can be used with PennyLane devices.
253253
254254 from pennylane import numpy as np
255255
256- dev = qml .device(" default.qubit" , wires = [" q1" , " q2" , " q3" ])
256+ dev = qp .device(" default.qubit" , wires = [" q1" , " q2" , " q3" ])
257257
258- @qml .qnode (dev)
258+ @qp .qnode (dev)
259259 def circuit (angle ):
260260 FlipAndRotate(angle, wire_rot = " q1" , wire_flip = " q1" )
261- return qml .expval(qml .PauliZ(" q1" ))
261+ return qp .expval(qp .PauliZ(" q1" ))
262262
263263 >>> a = np.array(3.14 )
264264>>> circuit(a)
@@ -267,7 +267,7 @@ The new gate can be used with PennyLane devices.
267267If all gates used in the decomposition have gradient recipes defined,
268268we can even compute gradients of circuits that use the new gate without any extra effort.
269269
270- >>> qml .grad(circuit)(a)
270+ >>> qp .grad(circuit)(a)
271271-0.0015926529164868282
272272
273273.. note ::
@@ -278,8 +278,8 @@ we can even compute gradients of circuits that use the new gate without any extr
278278
279279 def FlipAndRotate (angle , wire_rot , wire_flip = None , do_flip = False ):
280280 if do_flip:
281- qml .PauliX(wires = wire_flip)
282- qml .RX(angle, wires = wire_rot)
281+ qp .PauliX(wires = wire_flip)
282+ qp .RX(angle, wires = wire_rot)
283283
284284 and call it in the quantum function *as if it was a gate *.
285285 However, classes allow much more functionality, such as defining the adjoint gate above,
@@ -308,7 +308,7 @@ For example, we can create a new attribute, ``pauli_ops``, like so:
308308
309309We can check either a string or an Operation for inclusion in this set:
310310
311- >>> qml .PauliX(0 ) in pauli_ops
311+ >>> qp .PauliX(0 ) in pauli_ops
312312True
313313>>> " Hadamard" in pauli_ops
314314False
0 commit comments