Skip to content

Commit f02f55d

Browse files
authored
Sync v2 from dev (#1443)
**Title:** Fix v2 builds **Summary:** This PR syncs changes from `demonstrations` with `demonstrations_v2` and adds `pennylane_qisket` as a individual dependency in `tutorial_error_mitigation`
1 parent 0e1f6db commit f02f55d

File tree

26 files changed

+135
-98
lines changed

26 files changed

+135
-98
lines changed

demonstrations_v2/adjoint_diff_benchmarking/demo.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@
2222
import timeit
2323
import matplotlib.pyplot as plt
2424
import pennylane as qml
25-
import jax
26-
27-
jax.config.update("jax_platform_name", "cpu")
28-
jax.config.update('jax_enable_x64', True)
25+
import pennylane.numpy as pnp
2926

3027
plt.style.use("bmh")
3128

3229
n_samples = 5
3330

3431

3532
def get_time(qnode, params):
36-
globals_dict = {'grad': jax.grad, 'circuit': qnode, 'params': params}
33+
globals_dict = {"grad": qml.grad, "circuit": qnode, "params": params}
3734
return timeit.timeit("grad(circuit)(params)", globals=globals_dict, number=n_samples)
3835

3936

4037
def wires_scaling(n_wires, n_layers):
41-
key = jax.random.PRNGKey(42)
38+
rng = pnp.random.default_rng(12345)
4239

4340
t_adjoint = []
4441
t_ps = []
@@ -58,7 +55,7 @@ def circuit(params, wires):
5855

5956
# set up the parameters
6057
param_shape = qml.StronglyEntanglingLayers.shape(n_wires=i_wires, n_layers=n_layers)
61-
params = jax.random.normal(key, param_shape)
58+
params = rng.normal(size=pnp.prod(param_shape), requires_grad=True).reshape(param_shape)
6259

6360
t_adjoint.append(get_time(circuit_adjoint, params))
6461
t_backprop.append(get_time(circuit_backprop, params))
@@ -68,10 +65,10 @@ def circuit(params, wires):
6865

6966

7067
def layers_scaling(n_wires, n_layers):
71-
key = jax.random.PRNGKey(42)
68+
rng = pnp.random.default_rng(12345)
7269

7370
dev = qml.device("lightning.qubit", wires=n_wires)
74-
dev_python = qml.device('default.qubit', wires=n_wires)
71+
dev_python = qml.device("default.qubit", wires=n_wires)
7572

7673
t_adjoint = []
7774
t_ps = []
@@ -88,7 +85,7 @@ def circuit(params):
8885
for i_layers in n_layers:
8986
# set up the parameters
9087
param_shape = qml.StronglyEntanglingLayers.shape(n_wires=n_wires, n_layers=i_layers)
91-
params = jax.random.normal(key, param_shape)
88+
params = rng.normal(size=pnp.prod(param_shape), requires_grad=True).reshape(param_shape)
9289

9390
t_adjoint.append(get_time(circuit_adjoint, params))
9491
t_backprop.append(get_time(circuit_backprop, params))
@@ -110,9 +107,9 @@ def circuit(params):
110107
# Generating the graphic
111108
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
112109

113-
ax1.plot(wires_list, adjoint_wires, '.-', label="adjoint")
114-
ax1.plot(wires_list, ps_wires, '.-', label="parameter-shift")
115-
ax1.plot(wires_list, backprop_wires, '.-', label="backprop")
110+
ax1.plot(wires_list, adjoint_wires, ".-", label="adjoint")
111+
ax1.plot(wires_list, ps_wires, ".-", label="parameter-shift")
112+
ax1.plot(wires_list, backprop_wires, ".-", label="backprop")
116113

117114
ax1.legend()
118115

@@ -122,16 +119,17 @@ def circuit(params):
122119
ax1.set_yscale("log")
123120
ax1.set_title("Scaling with wires")
124121

125-
ax2.plot(layers_list, adjoint_layers, '.-', label="adjoint")
126-
ax2.plot(layers_list, ps_layers, '.-', label="parameter-shift")
127-
ax2.plot(layers_list, backprop_layers, '.-', label="backprop")
122+
ax2.plot(layers_list, adjoint_layers, ".-", label="adjoint")
123+
ax2.plot(layers_list, ps_layers, ".-", label="parameter-shift")
124+
ax2.plot(layers_list, backprop_layers, ".-", label="backprop")
128125

129126
ax2.legend()
130127

131128
ax2.set_xlabel("Number of layers")
132129
ax2.set_xticks(layers_list)
133-
ax2.set_ylabel("Time")
134-
ax2.set_title("Scaling with Layers")
130+
ax2.set_ylabel("Log Time")
131+
ax2.set_yscale("log")
132+
ax2.set_title("Scaling with layers")
135133

136134
plt.savefig("scaling.png")
137135

demonstrations_v2/adjoint_diff_benchmarking/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77
],
88
"dateOfPublication": "2021-11-23T00:00:00+00:00",
9-
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
9+
"dateOfLastModification": "2025-07-11T00:00:00+00:00",
1010
"categories": [
1111
"Getting Started"
1212
],

demonstrations_v2/ahs_aquila/demo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
133133
The modification of the energy levels when atoms are in proximity gives rise to Rydberg blockade,
134134
where atoms that have been driven by a pulse that would, in isolation, leave them in the excited state
135-
instead remain in the ground state due to neighboring atoms being excited. The distance within which two
135+
instead remain in the ground state due to neighboring atoms being excited. The distance within which two
136136
neighboring atoms are effectively prevented from both being excited is referred to as the *blockade radius* :math:`R_b.`
137137
138138
This brings us to our discussion of the second part of the Hamiltonian: the drive term.
@@ -220,6 +220,16 @@
220220
device_arn="arn:aws:braket:us-east-1::device/qpu/quera/Aquila",
221221
wires=3,
222222
)
223+
##############################################################################
224+
# .. rst-class:: sphx-glr-script-out
225+
#
226+
#
227+
# .. code-block:: none
228+
#
229+
# pennylane/pennylane/__init__.py:201: PennyLaneDeprecationWarning: pennylane.QuantumFunctionError is no longer accessible at top-level
230+
# and must be imported as pennylane.exceptions.QuantumFunctionError. Support for top-level access will be removed in v0.43.
231+
# warnings.warn(
232+
#
223233

224234
rydberg_simulator = qml.device("braket.local.ahs", wires=3)
225235

demonstrations_v2/ahs_aquila/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77
],
88
"dateOfPublication": "2023-05-16T00:00:00+00:00",
9-
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
9+
"dateOfLastModification": "2025-07-11T00:00:00+00:00",
1010
"categories": ["Quantum Hardware", "Devices and Performance", "Quantum Computing"],
1111
"tags": [],
1212
"previewImages": [

demonstrations_v2/getting_started_with_hybrid_jobs/demo.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
In this tutorial, we'll walk through how to create your first hybrid quantum-classical algorithms on AWS.
1212
With a single-line-of-code, we'll see how to scale from PennyLane simulators on your laptop to running full-scale experiments on AWS that leverage both powerful classical compute and quantum devices.
13-
You'll gain understanding of the hybrid jobs queue, including QPU priority queuing, and learn how to scale classical resources for resource-intensive tasks.
13+
You'll gain understanding of the hybrid jobs queue, including QPU priority queuing, and learn how to scale classical resources for resource-intensive tasks.
1414
We hope these tools will empower you to start experimenting today with hybrid quantum algorithms!
1515
1616
.. figure:: /_static/demonstration_assets/getting_started_with_hybrid_jobs/socialthumbnail_large_getting_started_with_hybrid_jobs.png
@@ -40,8 +40,8 @@
4040
time, enabling you to keep track of costs, budget, or custom metrics such as training loss or
4141
expectation values.
4242
43-
Importantly, on specific QPUs, running your algorithm in Hybrid Jobs benefits from `parametric compilation <https://docs.aws.amazon.com/braket/latest/developerguide/braket-jobs-parametric-compilation.html>`__.
44-
This reduces the overhead associated with the computationally expensive compilation step by compiling a circuit only once and not for every iteration in your hybrid algorithm.
43+
Importantly, on specific QPUs, running your algorithm in Hybrid Jobs benefits from `parametric compilation <https://docs.aws.amazon.com/braket/latest/developerguide/braket-jobs-parametric-compilation.html>`__.
44+
This reduces the overhead associated with the computationally expensive compilation step by compiling a circuit only once and not for every iteration in your hybrid algorithm.
4545
This dramatically reduces the total runtime for many variational algorithms.
4646
For long-running hybrid jobs, Braket automatically uses the updated calibration data from the hardware provider when compiling your circuit to ensure the highest quality results.
4747
@@ -67,6 +67,15 @@
6767

6868
device = qml.device("braket.local.qubit", wires=1)
6969

70+
##############################################################################
71+
# .. rst-class:: sphx-glr-script-out
72+
#
73+
# .. code-block:: none
74+
#
75+
# pennylane/__init__.py:200: PennyLaneDeprecationWarning: pennylane.QuantumFunctionError is no longer accessible at top-level
76+
# and must be imported as pennylane.exceptions.QuantumFunctionError. Support for top-level access will be removed in v0.43.
77+
# warnings.warn(
78+
7079
######################################################################
7180
# Now we define a circuit with two rotation gates and measure the expectation value in the
7281
# :math:`Z`-basis.
@@ -246,6 +255,22 @@ def circuit(params):
246255
# Additionally, we can plot the metrics recorded during the algorithm. Below we show the expectation
247256
# value decreases with each iteration as expected.
248257
#
258+
# .. note::
259+
#
260+
# ``job.metrics()`` will be an empty dictionary while the job is running, and likely also for
261+
# a few minutes afterwards. To make sure that the below plot generates correctly, it is recommended
262+
# to block execution until the metrics are correctly reported. This can be done by:
263+
#
264+
# * using a ``while`` loop to manually block execution until the metrics are available.
265+
# * using a Python debugger and setting a breakpoint before the line that uses ``job.metrics()``
266+
# and blocking as needed.
267+
#
268+
# We will use a ``while`` loop as shown below.
269+
#
270+
271+
while len(job.metrics()) == 0:
272+
pass
273+
249274

250275
import pandas as pd
251276
import matplotlib.pyplot as plt
@@ -304,8 +329,8 @@ def circuit(params):
304329
# .. note::
305330
# AWS devices must be declared within the body of the decorated function.
306331
#
307-
# .. warning::
308-
# The Rigetti device used in this demo, AspenM3, has been retired. For an updated list of available hardware through
332+
# .. warning::
333+
# The Rigetti device used in this demo, AspenM3, has been retired. For an updated list of available hardware through
309334
# Amazon Braket, please consult the `supported regions and devices documentation <https://docs.aws.amazon.com/braket/latest/developerguide/braket-devices.html>`__. The general steps outlined below still hold regardless of the choice of device, though.
310335
#
311336

demonstrations_v2/getting_started_with_hybrid_jobs/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77
],
88
"dateOfPublication": "2023-10-16T00:00:00+00:00",
9-
"dateOfLastModification": "2025-01-14T00:00:00+00:00",
9+
"dateOfLastModification": "2025-07-11T00:00:00+00:00",
1010
"categories": [
1111
"Devices and Performance"
1212
],

demonstrations_v2/how_to_catalyst_lightning_gpu/demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
#
108108
# .. code-block:: none
109109
#
110-
# 1.7712995142661776
110+
# 1.2454125296886156
111111
#
112112
# Lightning-GPU has feature parity with `the rest of Lightning state-vector simulators <https://docs.pennylane.ai/projects/lightning/en/stable>`__,
113113
# providing native support for many PennyLane's operations and measurement processes with
@@ -141,7 +141,7 @@
141141
#
142142
# .. code-block:: none
143143
#
144-
# [ 8.8817842e-16 ... -6.2915415e-01 0.0000000e+00]
144+
# [ -1.1102230e-16 ... -7.2645772e-01 0.0000000e+00]
145145
#
146146
#
147147
# Note that in the above example, we didn't use ``method="adjoint"``.
@@ -194,7 +194,7 @@
194194
# Step = 7
195195
# Step = 8
196196
# Step = 9
197-
# [1.24479175e-01 ... 9.45755959e-01 4.64060426e-01]
197+
# [0.947667 ... 3.093198 0.8401809 ]
198198
#
199199
#
200200
# We used `Optax <https://github.com/google-deepmind/optax>`__,

demonstrations_v2/how_to_catalyst_lightning_gpu/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
],
1111
"dateOfPublication": "2025-02-21T10:00:00+00:00",
12-
"dateOfLastModification": "2025-02-21T10:00:00+00:00",
12+
"dateOfLastModification": "2025-07-11T10:00:00+00:00",
1313
"categories": [
1414
"Getting Started",
1515
"Quantum Chemistry",

demonstrations_v2/how_to_use_qiskit1_with_pennylane/demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def circuit():
113113
#
114114
# .. code-block:: none
115115
#
116-
# {'0': tensor(474, requires_grad=True), '1': tensor(550, requires_grad=True)}
116+
# {'0': 474, '1': 550}
117117
#
118118

119119
######################################################################
@@ -403,7 +403,7 @@ def cost(phis, theta):
403403
# .. code-block:: none
404404
#
405405
# Optimized parameters: phis = [3.12829384 3.12823583], theta = [3.1310224]
406-
# Optimized cost function val: -2.999796472821245
406+
# Optimized cost function value: -2.999796472821245
407407
#
408408

409409
######################################################################

demonstrations_v2/how_to_use_qiskit1_with_pennylane/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77
],
88
"dateOfPublication": "2024-07-02T00:00:00+00:00",
9-
"dateOfLastModification": "2025-01-08T00:00:00+00:00",
9+
"dateOfLastModification": "2025-07-10T00:00:00+00:00",
1010
"categories": [
1111
"Quantum Computing",
1212
"How-to"

0 commit comments

Comments
 (0)