Skip to content

Commit a395d67

Browse files
authored
Manual demo fixes for 0.42 QA (#1436)
* Update `ahs_aquila` demo to render `qml.QuantumFunctionError` deprecation warning * Update `qnspsa` demo to stop unravelling parameters to cost function * Update adjoint differentiation demos (`adjoint_diff_benchmarking` and `tutorial_adjoint_diff`) to use autograd instead of JAX * Use log scaling for y-axis of second plot * Update `getting_started_with_hybrid_jobs` demo to render deprecation warning, and use a while loop to block until job metrics are available * Update `quantum_volume` demo with new coupling map and instructions for setting up API key
1 parent bade853 commit a395d67

15 files changed

+107
-311
lines changed
Loading
Loading

_static/demonstration_assets/quantum_volume/lima.svg

Lines changed: 0 additions & 233 deletions
This file was deleted.

demonstrations/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/adjoint_diff_benchmarking.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/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/ahs_aquila.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/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
],

0 commit comments

Comments
 (0)