Skip to content

Commit 081e471

Browse files
authored
Merge branch 'main' into feature/res-analysis-specs
2 parents 28d56a1 + 6198602 commit 081e471

21 files changed

Lines changed: 860 additions & 143 deletions

.git-blame-ignore-revs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,44 @@ c73e73b19c8d38e63b41ca4c8039d9f430c55da1
66

77
# Use `ruff` and `pyupgrade` to support `3.11`+ Python language features (https://github.com/PennyLaneAI/pennylane/pull/7860)
88
a565cd69ad025796923f0354d084f9ca7267ab18
9+
10+
# Migration from qml alias to new qp alias
11+
# https://github.com/PennyLaneAI/pennylane/pull/9310
12+
# https://github.com/PennyLaneAI/pennylane/pull/9317
13+
# https://github.com/PennyLaneAI/pennylane/pull/9320
14+
# https://github.com/PennyLaneAI/pennylane/pull/9315
15+
# https://github.com/PennyLaneAI/pennylane/pull/9312
16+
# https://github.com/PennyLaneAI/pennylane/pull/9314
17+
# https://github.com/PennyLaneAI/pennylane/pull/9319
18+
# https://github.com/PennyLaneAI/pennylane/pull/9313
19+
# https://github.com/PennyLaneAI/pennylane/pull/9326
20+
# https://github.com/PennyLaneAI/pennylane/pull/9331
21+
# https://github.com/PennyLaneAI/pennylane/pull/9329
22+
# https://github.com/PennyLaneAI/pennylane/pull/9280
23+
# https://github.com/PennyLaneAI/pennylane/pull/9327
24+
# https://github.com/PennyLaneAI/pennylane/pull/9330
25+
# https://github.com/PennyLaneAI/pennylane/pull/9325
26+
# https://github.com/PennyLaneAI/pennylane/pull/9358
27+
# https://github.com/PennyLaneAI/pennylane/pull/9281
28+
# https://github.com/PennyLaneAI/pennylane/pull/9360
29+
# https://github.com/PennyLaneAI/pennylane/pull/9376
30+
# https://github.com/PennyLaneAI/pennylane/pull/9375
31+
6a08713922d3aa69c18fd49f92190c4663676543
32+
82b1345f7cb6909b7f8dcdd74a3662697f9c7879
33+
9c7b57f5918d7996b327c37a5b4242057afdff19
34+
54df7dacc50bed50bee94012a9ec8332a944c93d
35+
9c04988b492f96101f948505ad5dcfdf23a28aea
36+
311e8bf4e463ababe49d2bade2aedd4f080eba0a
37+
cd92dea6a332d9e58ebe258e2da468e689fb6755
38+
fe95348de223be724865ec292ed14dd950780167
39+
46e4cdc78387e769b977a8e1f51dfa01ef58501f
40+
ae4295c5ee82790be3d67c471aebe162d571b1d0
41+
a5132e20f658b9bffd64d75499a2ae2e79d0717e
42+
07f3fad6bfa8543d9650c8e1cb2b265de5f8cfdf
43+
d3f4d19a9393537d7a484b22e16155ac19a4dcaf
44+
975767a42ff2f46a3bd36825425e67c3cebd310d
45+
b97b5729a1e36e9d9a1bd6e58cbbb1af9e2a2024
46+
99c8984c697fb112f1c09b0a21d82e7eb0dc6df8
47+
4c57e8c3bd56b381dddd93c6af1e36499b0c98bd
48+
894eabf146b314ea94a92cb7e398b9f23e7e1470
49+
1dc01257f80bb08b9d5f8e3168afc47e6ce66ab1

doc/development/adding_operators.rst

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ serves as the main abstraction of such objects, and all operators (such as gates
2727
inherit 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)
3232
True
3333

3434
The 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

126126
Creating 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'])
219219
Once the class has been created, you can run a suite of validation checks using :func:`.ops.functions.assert_valid`.
220220
This 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

224224
If 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.
267267
If all gates used in the decomposition have gradient recipes defined,
268268
we 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

309309
We 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
312312
True
313313
>>> "Hadamard" in pauli_ops
314314
False

0 commit comments

Comments
 (0)