Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 14 additions & 14 deletions demonstrations_v2/tutorial_optimal_control/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ def smooth_rectangles(params, t, k=2.0, max_amp=1.0, eps=0.0, T=1.0):
# up the subsequent executions a lot. For optimization workflows of small-scale
# functions, this almost always pays off.

import pennylane as qml
import pennylane as qp

X, Y, Z = qml.PauliX, qml.PauliY, qml.PauliZ
X, Y, Z = qp.PauliX, qp.PauliY, qp.PauliZ

num_wires = 2
# Hamiltonian terms of the drift and parametrized parts of H
Expand All @@ -455,20 +455,20 @@ def smooth_rectangles(params, t, k=2.0, max_amp=1.0, eps=0.0, T=1.0):
# Coefficients: 1 for drift Hamiltonian and smooth rectangles for parametrized part
coeffs = [1.0, 1.0] + [S_k for op in ops_param]
# Build H
H = qml.dot(coeffs, ops_H_d + ops_param)
H = qp.dot(coeffs, ops_H_d + ops_param)
# Set tolerances for the ODE solver
atol = rtol = 1e-10

# Target unitary is CNOT. We get its matrix and note that we do not need the dagger
# because CNOT is Hermitian.
target = qml.CNOT([0, 1]).matrix()
target = qp.CNOT([0, 1]).matrix()
target_name = "CNOT"
print(f"Our target unitary is a {target_name} gate, with matrix\n{target.astype('int')}")


def pulse_matrix(params):
"""Compute the unitary time evolution matrix of the pulse for given parameters."""
return qml.evolve(H, atol=atol, rtol=rtol)(params, T).matrix()
return qp.evolve(H, atol=atol, rtol=rtol)(params, T).matrix()


@jax.jit
Expand Down Expand Up @@ -644,20 +644,20 @@ def plot_optimal_pulses(hist, pulse_fn, ops, T, target_name):
# Coefficients: 1. for drift Hamiltonian and smooth rectangles for parametrized part
coeffs = [1.0, 1.0, 1.0] + [S_k for op in ops_param]
# Build H
H = qml.dot(coeffs, ops_H_d + ops_param)
H = qp.dot(coeffs, ops_H_d + ops_param)
# Set tolerances for the ODE solver
atol = rtol = 1e-10

# Target unitary is Toffoli. We get its matrix and note that we do not need the dagger
# because Toffoli is Hermitian and unitary.
target = qml.Toffoli([0, 1, 2]).matrix()
target = qp.Toffoli([0, 1, 2]).matrix()
target_name = "Toffoli"
print(f"Our target unitary is a {target_name} gate, with matrix\n{target.astype('int')}")


def pulse_matrix(params):
"""Compute the unitary time evolution matrix of the pulse for given parameters."""
return qml.evolve(H, atol=atol, rtol=rtol)(params, T).matrix()
return qp.evolve(H, atol=atol, rtol=rtol)(params, T).matrix()


@jax.jit
Expand Down Expand Up @@ -697,18 +697,18 @@ def profit(params):
# flip the third qubit, returning a probability of one in the last entry
# and zeros elsewhere.

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


@qml.qnode(dev, interface="jax")
@qp.qnode(dev, interface="jax")
def node(params):
# Prepare |110>
qml.PauliX(0)
qml.PauliX(1)
qp.PauliX(0)
qp.PauliX(1)
# Apply pulse sequence
qml.evolve(H, atol=atol, rtol=rtol)(params, T)
qp.evolve(H, atol=atol, rtol=rtol)(params, T)
# Return quantum state
return qml.probs()
return qp.probs()


probs = node(max_params)
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_optimal_control/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2023-08-08T00:00:00+00:00",
"dateOfLastModification": "2025-12-10T15:48:14+00:00",
"dateOfLastModification": "2026-04-17T15:48:14+00:00",
"categories": [
"Optimization",
"Quantum Computing",
Expand Down
20 changes: 10 additions & 10 deletions demonstrations_v2/tutorial_pasqal/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@
# We will need to provide this device with the ``ThreeDQubit`` object that we created
# above. We also need to instantiate the device with a fixed control radius.

import pennylane as qml
import pennylane as qp

num_wires = len(qubits)
control_radius = 32.4
dev = qml.device("cirq.pasqal", control_radius=control_radius,
dev = qp.device("cirq.pasqal", control_radius=control_radius,
qubits=qubits, wires=num_wires)

##############################################################################
Expand Down Expand Up @@ -263,28 +263,28 @@
peak_qubit = 8

def controlled_rotation(phi, wires):
qml.RY(phi, wires=wires[1])
qml.CNOT(wires=wires)
qml.RY(-phi, wires=wires[1])
qml.CNOT(wires=wires)
qp.RY(phi, wires=wires[1])
qp.CNOT(wires=wires)
qp.RY(-phi, wires=wires[1])
qp.CNOT(wires=wires)

@qml.qnode(dev, interface="tf")
@qp.qnode(dev, interface="tf")
def circuit(weights, data):

# Input classical data loaded into qubits at second level
for idx in range(4):
if data[idx]:
qml.PauliX(wires=idx)
qp.PauliX(wires=idx)

# Interact qubits from second and third levels
for idx in range(4):
qml.CNOT(wires=[idx, idx + 4])
qp.CNOT(wires=[idx, idx + 4])

# Interact qubits from third level with peak using parameterized gates
for idx, wire in enumerate(range(4, 8)):
controlled_rotation(weights[idx], wires=[wire, peak_qubit])

return qml.expval(qml.PauliZ(wires=peak_qubit))
return qp.expval(qp.PauliZ(wires=peak_qubit))


##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_pasqal/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": "2020-10-13T00:00:00+00:00",
"dateOfLastModification": "2026-02-19T00:00:00+00:00",
"dateOfLastModification": "2026-04-17T00:00:00+00:00",
"categories": [
"Quantum Hardware",
"Quantum Computing"
Expand Down
28 changes: 14 additions & 14 deletions demonstrations_v2/tutorial_period_finding/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# Implementation of period finding in PennyLane
# ----------------

import pennylane as qml
import pennylane as qp
import numpy as np
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -194,7 +194,7 @@ def Oracle(f):
# check that this is a unitary
assert np.allclose(U @ np.linalg.inv(U), np.eye(2**7))

return qml.QubitUnitary(U, wires=range(7))
return qp.QubitUnitary(U, wires=range(7))


#####################################################################
Expand All @@ -208,28 +208,28 @@ def Oracle(f):
# reason we define a device with 2 shots. We also add some snapshots to the circuit that we will look at later.


dev = qml.device("default.qubit", wires=7)
dev = qp.device("default.qubit", wires=7)


@qml.set_shots(2)
@qml.qnode(dev)
@qp.set_shots(2)
@qp.qnode(dev)
def circuit():
"""Circuit to implement the period finding algorithm."""

for i in range(4):
qml.Hadamard(wires=i)
qp.Hadamard(wires=i)

qml.Snapshot("initial_state")
qp.Snapshot("initial_state")

Oracle(f)

qml.Snapshot("loaded_function")
qp.Snapshot("loaded_function")

qml.QFT(wires=range(4))
qp.QFT(wires=range(4))

qml.Snapshot("fourier_spectrum")
qp.Snapshot("fourier_spectrum")

return qml.sample(wires=range(4))
return qp.sample(wires=range(4))


# take two samples from the circuit
Expand Down Expand Up @@ -271,9 +271,9 @@ def circuit():
# look at the states that were prepared by making use of the snapshots we recorded during the
# circuit simulation.

dev = qml.device("default.qubit", wires=7)
qnode = qml.set_shots(qml.QNode(circuit, dev), shots = 1)
intermediate_states = qml.snapshots(circuit)()
dev = qp.device("default.qubit", wires=7)
qnode = qp.set_shots(qp.QNode(circuit, dev), shots = 1)
intermediate_states = qp.snapshots(circuit)()

#####################################################################
# We can plot them as discrete functions, where the size of a point indicates the absolute value
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_period_finding/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2025-04-16T10:00:00+00:00",
"dateOfLastModification": "2025-10-15T00:00:00+00:00",
"dateOfLastModification": "2026-04-17T00:00:00+00:00",
"categories": [
"Algorithms"
],
Expand Down
20 changes: 10 additions & 10 deletions demonstrations_v2/tutorial_phase_kickback/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
# circuits. Here we will work with 5 qubits, we will use qubit [0] as the control ancilla qubit, and qubits [1,2,3,4] will be our target qubits where we will encode :math:`|\psi\rangle.`
#

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

num_wires = 5
dev = qml.device("default.qubit", wires=num_wires)
dev = qp.device("default.qubit", wires=num_wires)

######################################################################
# Building the quantum lock
Expand Down Expand Up @@ -83,7 +83,7 @@


def quantum_lock(secret_key):
return qml.FlipSign(secret_key, wires=list(range(1, num_wires)))
return qp.FlipSign(secret_key, wires=list(range(1, num_wires)))


######################################################################
Expand All @@ -93,22 +93,22 @@ def quantum_lock(secret_key):


def build_key(key):
return qml.BasisState(key, wires=list(range(1, num_wires)))
return qp.BasisState(key, wires=list(range(1, num_wires)))


######################################################################
# Now we’ll put it all together to build our quantum locking mechanism:
#


@qml.set_shots(1)
@qml.qnode(dev)
@qp.set_shots(1)
@qp.qnode(dev)
def quantum_locking_mechanism(lock, key):
build_key(key)
qml.Hadamard(wires=0) # Hadamard on ancilla qubit
qml.ctrl(lock, control=0) # Controlled unitary operation
qml.Hadamard(wires=0) # Hadamard again on ancilla qubit
return qml.sample(wires=0)
qp.Hadamard(wires=0) # Hadamard on ancilla qubit
qp.ctrl(lock, control=0) # Controlled unitary operation
qp.Hadamard(wires=0) # Hadamard again on ancilla qubit
return qp.sample(wires=0)


def check_key(lock, key):
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_phase_kickback/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2023-08-01T00:00:00+00:00",
"dateOfLastModification": "2025-12-19T00:00:00+00:00",
"dateOfLastModification": "2026-04-17T00:00:00+00:00",
"categories": [
"Getting Started",
"Algorithms",
Expand Down
Loading
Loading