Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions demonstrations_v2/adjoint_diff_benchmarking/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import timeit
import matplotlib.pyplot as plt
import pennylane as qml
import pennylane as qp
import pennylane.numpy as pnp

plt.style.use("bmh")
Expand All @@ -27,7 +27,7 @@


def get_time(qnode, params):
globals_dict = {"grad": qml.grad, "circuit": qnode, "params": params}
globals_dict = {"grad": qp.grad, "circuit": qnode, "params": params}
return timeit.timeit("grad(circuit)(params)", globals=globals_dict, number=n_samples)


Expand All @@ -39,19 +39,19 @@ def wires_scaling(n_wires, n_layers):
t_backprop = []

def circuit(params, wires):
qml.StronglyEntanglingLayers(params, wires=range(wires))
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1) @ qml.PauliZ(2))
qp.StronglyEntanglingLayers(params, wires=range(wires))
return qp.expval(qp.PauliZ(0) @ qp.PauliZ(1) @ qp.PauliZ(2))

for i_wires in n_wires:
dev = qml.device("lightning.qubit", wires=i_wires)
dev_python = qml.device("default.qubit", wires=i_wires)
dev = qp.device("lightning.qubit", wires=i_wires)
dev_python = qp.device("default.qubit", wires=i_wires)

circuit_adjoint = qml.QNode(lambda x: circuit(x, wires=i_wires), dev, diff_method="adjoint")
circuit_ps = qml.QNode(lambda x: circuit(x, wires=i_wires), dev, diff_method="parameter-shift")
circuit_backprop = qml.QNode(lambda x: circuit(x, wires=i_wires), dev_python, diff_method="backprop")
circuit_adjoint = qp.QNode(lambda x: circuit(x, wires=i_wires), dev, diff_method="adjoint")
circuit_ps = qp.QNode(lambda x: circuit(x, wires=i_wires), dev, diff_method="parameter-shift")
circuit_backprop = qp.QNode(lambda x: circuit(x, wires=i_wires), dev_python, diff_method="backprop")

# set up the parameters
param_shape = qml.StronglyEntanglingLayers.shape(n_wires=i_wires, n_layers=n_layers)
param_shape = qp.StronglyEntanglingLayers.shape(n_wires=i_wires, n_layers=n_layers)
params = rng.normal(size=pnp.prod(param_shape), requires_grad=True).reshape(param_shape)

t_adjoint.append(get_time(circuit_adjoint, params))
Expand All @@ -64,24 +64,24 @@ def circuit(params, wires):
def layers_scaling(n_wires, n_layers):
rng = pnp.random.default_rng(12345)

dev = qml.device("lightning.qubit", wires=n_wires)
dev_python = qml.device("default.qubit", wires=n_wires)
dev = qp.device("lightning.qubit", wires=n_wires)
dev_python = qp.device("default.qubit", wires=n_wires)

t_adjoint = []
t_ps = []
t_backprop = []

def circuit(params):
qml.StronglyEntanglingLayers(params, wires=range(n_wires))
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1) @ qml.PauliZ(2))
qp.StronglyEntanglingLayers(params, wires=range(n_wires))
return qp.expval(qp.PauliZ(0) @ qp.PauliZ(1) @ qp.PauliZ(2))

circuit_adjoint = qml.QNode(circuit, dev, diff_method="adjoint")
circuit_ps = qml.QNode(circuit, dev, diff_method="parameter-shift")
circuit_backprop = qml.QNode(circuit, dev_python, diff_method="backprop")
circuit_adjoint = qp.QNode(circuit, dev, diff_method="adjoint")
circuit_ps = qp.QNode(circuit, dev, diff_method="parameter-shift")
circuit_backprop = qp.QNode(circuit, dev_python, diff_method="backprop")

for i_layers in n_layers:
# set up the parameters
param_shape = qml.StronglyEntanglingLayers.shape(n_wires=n_wires, n_layers=i_layers)
param_shape = qp.StronglyEntanglingLayers.shape(n_wires=n_wires, n_layers=i_layers)
params = rng.normal(size=pnp.prod(param_shape), requires_grad=True).reshape(param_shape)

t_adjoint.append(get_time(circuit_adjoint, params))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": false,
"executable_latest": false,
"dateOfPublication": "2021-11-23T00:00:00+00:00",
"dateOfLastModification": "2025-09-22T15:48:14+00:00",
"dateOfLastModification": "2026-04-14T15:48:14+00:00",
"categories": [
"Getting Started"
],
Expand Down
44 changes: 22 additions & 22 deletions demonstrations_v2/ahs_aquila/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@

"""

import pennylane as qml
import pennylane as qp

aquila = qml.device(
aquila = qp.device(
"braket.aws.ahs",
device_arn="arn:aws:braket:us-east-1::device/qpu/quera/Aquila",
wires=3,
Expand All @@ -229,7 +229,7 @@
# warnings.warn(
#

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

######################################################################
# Creating a Rydberg Hamiltonian
Expand Down Expand Up @@ -331,7 +331,7 @@
# .. math:: \hat{H} = \sum_{j=1}^{N-1}\sum_{k=j+1}^{N} \frac{C_6}{R^6_{jk}}\hat{n}_j\hat{n}_k
#

H_interaction = qml.pulse.rydberg_interaction(coordinates, **settings)
H_interaction = qp.pulse.rydberg_interaction(coordinates, **settings)

######################################################################
# Driving field
Expand Down Expand Up @@ -478,7 +478,7 @@ def gaussian_fn(p, t):
# We can then define our drive using via :func:`~pennylane.pulse.rydberg_drive`:
#

global_drive = qml.pulse.rydberg_drive(amplitude=gaussian_fn, phase=0, detuning=0, wires=[0, 1, 2])
global_drive = qp.pulse.rydberg_drive(amplitude=gaussian_fn, phase=0, detuning=0, wires=[0, 1, 2])

######################################################################
# With only amplitude as non-zero, the overall driven Hamiltonian in this case simplifies to:
Expand Down Expand Up @@ -520,14 +520,14 @@ def gaussian_fn(p, t):
params = [amplitude_params]
ts = [0.0, 1.75]

default_qubit = qml.device("default.qubit", wires=3)
default_qubit = qp.device("default.qubit", wires=3)


@qml.set_shots(1000)
@qml.qnode(default_qubit, interface="jax")
@qp.set_shots(1000)
@qp.qnode(default_qubit, interface="jax")
def circuit(parameters):
qml.evolve(global_drive)(parameters, ts)
return qml.counts()
qp.evolve(global_drive)(parameters, ts)
return qp.counts()


circuit(params)
Expand All @@ -551,12 +551,12 @@ def circuit(parameters):


def circuit(params):
qml.evolve(H_interaction + global_drive)(params, ts)
return qml.counts()
qp.evolve(H_interaction + global_drive)(params, ts)
return qp.counts()


circuit_qml = qml.set_shots(qml.QNode(circuit, default_qubit, interface="jax"), shots=1000)
circuit_ahs = qml.QNode(circuit, rydberg_simulator)
circuit_qml = qp.set_shots(qp.QNode(circuit, default_qubit, interface="jax"), shots=1000)
circuit_ahs = qp.QNode(circuit, rydberg_simulator)

print(f"PennyLane simulation: {circuit_qml(params)}")
print(f"AWS local simulation: {circuit_ahs(params)}")
Expand Down Expand Up @@ -644,8 +644,8 @@ def circuit(params):
# defining the window; we’ll use ``windows=[0.01, 1.749]``. Our modified global drive is then:
#

amp_fn = qml.pulse.rect(gaussian_fn, windows=[0.01, 1.749])
global_drive = qml.pulse.rydberg_drive(amplitude=amp_fn, phase=0, detuning=0, wires=[0, 1, 2])
amp_fn = qp.pulse.rect(gaussian_fn, windows=[0.01, 1.749])
global_drive = qp.pulse.rydberg_drive(amplitude=amp_fn, phase=0, detuning=0, wires=[0, 1, 2])

######################################################################
# At this point we could skip directly to defining a ``qnode`` using the ``aquila`` device and running our
Expand All @@ -656,7 +656,7 @@ def circuit(params):
# To do this, we create the operator we will be using in our circuit, and pass it to a method on the
# hardware device that creates an AHS program for upload:
#
op = qml.evolve(H_interaction + global_drive)(params, ts)
op = qp.evolve(H_interaction + global_drive)(params, ts)
ahs_program = aquila.create_ahs_program(op)

######################################################################
Expand Down Expand Up @@ -712,7 +712,7 @@ def circuit(params):
# values for plotting the function defined in PennyLane for amplitude
input_times = np.linspace(*ts, 1000)
input_amplitudes = [
qml.pulse.rect(gaussian_fn, windows=[0.01, 1.749])(amplitude_params, _t) for _t in input_times
qp.pulse.rect(gaussian_fn, windows=[0.01, 1.749])(amplitude_params, _t) for _t in input_times
]

# plot PL input and hardware setpoints for comparison
Expand Down Expand Up @@ -754,11 +754,11 @@ def circuit(params):
#


# @qml.qnode(rydberg_simulator)
@qml.qnode(aquila)
# @qp.qnode(rydberg_simulator)
@qp.qnode(aquila)
def circuit(params):
qml.evolve(H_interaction + global_drive)(params, ts)
return qml.counts()
qp.evolve(H_interaction + global_drive)(params, ts)
return qp.counts()


circuit(params)
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/ahs_aquila/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": false,
"executable_latest": false,
"dateOfPublication": "2023-05-16T00:00:00+00:00",
"dateOfLastModification": "2025-11-10T00:00:00+00:00",
"dateOfLastModification": "2026-04-14T00:00:00+00:00",
"categories": [
"Quantum Hardware",
"Devices and Performance",
Expand Down
52 changes: 26 additions & 26 deletions demonstrations_v2/braket-parallel-gradients/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@
##############################################################################
# SV1 can now be loaded with the standard PennyLane :func:`~.pennylane.device`:

import pennylane as qml
import pennylane as qp
from pennylane import numpy as np

n_wires = 25

dev_remote = qml.device(
dev_remote = qp.device(
"braket.aws.qubit",
device_arn=device_arn,
wires=n_wires,
Expand All @@ -115,7 +115,7 @@
# Note the ``parallel=True`` argument. This setting allows us to unlock the power of parallel
# execution on SV1 for gradient calculations. We'll also load ``default.qubit`` for comparison.

dev_local = qml.device("default.qubit", wires=n_wires)
dev_local = qp.device("default.qubit", wires=n_wires)

##############################################################################
# Note that a local Braket device ``braket.local.qubit`` is also available. See the
Expand All @@ -130,13 +130,13 @@

def circuit(params):
for i in range(n_wires):
qml.RX(params[i], wires=i)
qp.RX(params[i], wires=i)
for i in range(n_wires):
qml.CNOT(wires=[i, (i + 1) % n_wires])
qp.CNOT(wires=[i, (i + 1) % n_wires])

# Measure all qubits to make sure all's good with Braket
observables = [qml.PauliZ(n_wires - 1)] + [qml.Identity(i) for i in range(n_wires - 1)]
return qml.expval(qml.prod(*observables))
observables = [qp.PauliZ(n_wires - 1)] + [qp.Identity(i) for i in range(n_wires - 1)]
return qp.expval(qp.prod(*observables))


##############################################################################
Expand All @@ -154,8 +154,8 @@ def circuit(params):
#
# The next step is to convert the above circuit into a PennyLane :func:`~.pennylane.QNode`.

qnode_remote = qml.QNode(circuit, dev_remote)
qnode_local = qml.QNode(circuit, dev_local)
qnode_remote = qp.QNode(circuit, dev_remote)
qnode_local = qp.QNode(circuit, dev_local)

##############################################################################
# .. note::
Expand Down Expand Up @@ -216,7 +216,7 @@ def circuit(params):
#
# First, consider the remote device:

d_qnode_remote = qml.grad(qnode_remote)
d_qnode_remote = qp.grad(qnode_remote)

t_0_remote_grad = time.time()
d_qnode_remote(params)
Expand All @@ -241,7 +241,7 @@ def circuit(params):
# Evaluating the gradient with ``default.qubit`` will take a long time, consider
# commenting-out the following lines unless you are happy to wait.

d_qnode_local = qml.grad(qnode_local)
d_qnode_local = qp.grad(qnode_local)

t_0_local_grad = time.time()
d_qnode_local(params)
Expand Down Expand Up @@ -308,7 +308,7 @@ def circuit(params):
# We will use the remote SV1 device to help us optimize our QAOA circuit as quickly as possible.
# First, the device is loaded again for 20 qubits

dev = qml.device(
dev = qp.device(
"braket.aws.qubit",
device_arn=device_arn,
wires=n_wires,
Expand All @@ -330,25 +330,25 @@ def circuit(params):
# The QAOA problem can then be set up following the standard pattern, as discussed in detail in
# the :doc:`QAOA tutorial<demos/tutorial_qaoa_intro>`.

cost_h, mixer_h = qml.qaoa.maxcut(g)
cost_h, mixer_h = qp.qaoa.maxcut(g)
n_layers = 2


def qaoa_layer(gamma, alpha):
qml.qaoa.cost_layer(gamma, cost_h)
qml.qaoa.mixer_layer(alpha, mixer_h)
qp.qaoa.cost_layer(gamma, cost_h)
qp.qaoa.mixer_layer(alpha, mixer_h)


def circuit(params, **kwargs):
for i in range(n_wires): # Prepare an equal superposition over all qubits
qml.Hadamard(wires=i)
qp.Hadamard(wires=i)

qml.layer(qaoa_layer, n_layers, params[0], params[1])
return qml.expval(cost_h)
qp.layer(qaoa_layer, n_layers, params[0], params[1])
return qp.expval(cost_h)


cost_function = qml.QNode(circuit, dev)
optimizer = qml.AdagradOptimizer(stepsize=0.01)
cost_function = qp.QNode(circuit, dev)
optimizer = qp.AdagradOptimizer(stepsize=0.01)

##############################################################################
# We're now set up to train the circuit! Note, if you are training this circuit yourself, you may
Expand Down Expand Up @@ -481,17 +481,17 @@ def qaoa_training(n_iterations, n_layers=2):
braket_tasks_cost = Tracker().start() # track Braket quantum tasks costs

# declare PennyLane device
dev = qml.device("lightning.qubit", wires=n_wires)
dev = qp.device("lightning.qubit", wires=n_wires)

@qml.qnode(dev)
@qp.qnode(dev)
def cost_function(params, **kwargs):
for i in range(n_wires): # Prepare an equal superposition over all qubits
qml.Hadamard(wires=i)
qml.layer(qaoa_layer, n_layers, params[0], params[1])
return qml.expval(cost_h)
qp.Hadamard(wires=i)
qp.layer(qaoa_layer, n_layers, params[0], params[1])
return qp.expval(cost_h)

params = 0.01 * np.random.uniform(size=[2, n_layers])
optimizer = qml.AdagradOptimizer(stepsize=0.01)
optimizer = qp.AdagradOptimizer(stepsize=0.01)

# run the classical-quantum iterations
for i in range(n_iterations):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"executable_stable": false,
"executable_latest": false,
"dateOfPublication": "2020-12-08T00:00:00+00:00",
"dateOfLastModification": "2025-09-22T15:48:14+00:00",
"dateOfLastModification": "2026-04-14T15:48:14+00:00",
"categories": [
"Devices and Performance"
],
Expand Down
Loading
Loading