diff --git a/demonstrations_v2/adjoint_diff_benchmarking/demo.py b/demonstrations_v2/adjoint_diff_benchmarking/demo.py index 9b0ccff232..99a4be6b78 100644 --- a/demonstrations_v2/adjoint_diff_benchmarking/demo.py +++ b/demonstrations_v2/adjoint_diff_benchmarking/demo.py @@ -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") @@ -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) @@ -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)) @@ -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)) diff --git a/demonstrations_v2/adjoint_diff_benchmarking/metadata.json b/demonstrations_v2/adjoint_diff_benchmarking/metadata.json index 6639c47149..e0a2cb145e 100644 --- a/demonstrations_v2/adjoint_diff_benchmarking/metadata.json +++ b/demonstrations_v2/adjoint_diff_benchmarking/metadata.json @@ -8,9 +8,9 @@ "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" + "Quantum Machine Learning" ], "tags": [], "previewImages": [ @@ -25,4 +25,4 @@ "basedOnPapers": [], "referencedByPapers": [], "relatedContent": [] -} \ No newline at end of file +} diff --git a/demonstrations_v2/ahs_aquila/demo.py b/demonstrations_v2/ahs_aquila/demo.py index 922cf4cb9c..6563c3ca8c 100644 --- a/demonstrations_v2/ahs_aquila/demo.py +++ b/demonstrations_v2/ahs_aquila/demo.py @@ -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, @@ -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 @@ -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 @@ -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: @@ -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) @@ -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)}") @@ -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 @@ -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) ###################################################################### @@ -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 @@ -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) diff --git a/demonstrations_v2/ahs_aquila/metadata.json b/demonstrations_v2/ahs_aquila/metadata.json index 230640dc7b..87af6f361a 100644 --- a/demonstrations_v2/ahs_aquila/metadata.json +++ b/demonstrations_v2/ahs_aquila/metadata.json @@ -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", diff --git a/demonstrations_v2/braket-parallel-gradients/demo.py b/demonstrations_v2/braket-parallel-gradients/demo.py index 8d2f7f9b4d..16c2493f30 100644 --- a/demonstrations_v2/braket-parallel-gradients/demo.py +++ b/demonstrations_v2/braket-parallel-gradients/demo.py @@ -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, @@ -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 @@ -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)) ############################################################################## @@ -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:: @@ -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) @@ -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) @@ -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, @@ -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`. -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 @@ -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): diff --git a/demonstrations_v2/braket-parallel-gradients/metadata.json b/demonstrations_v2/braket-parallel-gradients/metadata.json index cc3960822e..e804996e15 100644 --- a/demonstrations_v2/braket-parallel-gradients/metadata.json +++ b/demonstrations_v2/braket-parallel-gradients/metadata.json @@ -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" ], diff --git a/demonstrations_v2/covalent_cloud_gpu/demo.py b/demonstrations_v2/covalent_cloud_gpu/demo.py index ca709039b2..0b33a02216 100644 --- a/demonstrations_v2/covalent_cloud_gpu/demo.py +++ b/demonstrations_v2/covalent_cloud_gpu/demo.py @@ -32,7 +32,7 @@ import covalent as ct import covalent_cloud as cc import matplotlib.pyplot as plt -import pennylane as qml +import pennylane as qp from matplotlib.colors import ListedColormap from pennylane import numpy as np from sklearn.datasets import make_blobs @@ -124,11 +124,11 @@ def get_kernel_circuit(n_wires): - @qml.qnode(qml.device(QML_DEVICE, wires=n_wires, shots=None)) + @qp.qnode(qp.device(QML_DEVICE, wires=n_wires, shots=None)) def circuit(x1, x2): - qml.IQPEmbedding(x1, wires=range(n_wires), n_repeats=4) - qml.adjoint(qml.IQPEmbedding)(x2, wires=range(n_wires), n_repeats=4) - return qml.probs(wires=range(n_wires)) + qp.IQPEmbedding(x1, wires=range(n_wires), n_repeats=4) + qp.adjoint(qp.IQPEmbedding)(x2, wires=range(n_wires), n_repeats=4) + return qp.probs(wires=range(n_wires)) return lambda x1, x2: circuit(x1, x2)[0] # |0..0> state probability @@ -173,7 +173,7 @@ def get_split_data(n_samples=18, test_size=0.2): def classify_with_qsvm(Xtr, Xte, ytr, yte): kernel = get_kernel_circuit(n_wires=Xtr.shape[1]) - kernel_matrix_fn = lambda X, Z: qml.kernels.kernel_matrix(X, Z, kernel) + kernel_matrix_fn = lambda X, Z: qp.kernels.kernel_matrix(X, Z, kernel) svc = SVC(kernel=kernel_matrix_fn).fit(Xtr, ytr) # train/test accuracy @@ -265,7 +265,7 @@ def run_qsvm(n_samples, test_size): # import covalent as ct # import covalent_cloud as cc # import matplotlib.pyplot as plt -# import pennylane as qml +# import pennylane as qp # from matplotlib.colors import ListedColormap # from pennylane import numpy as np # from sklearn.datasets import make_blobs @@ -308,11 +308,11 @@ def run_qsvm(n_samples, test_size): # # def get_kernel_circuit(n_wires): # -# @qml.qnode(qml.device(QML_DEVICE, wires=n_wires, shots=None)) +# @qp.qnode(qp.device(QML_DEVICE, wires=n_wires, shots=None)) # def circuit(x1, x2): -# qml.IQPEmbedding(x1, wires=range(n_wires), n_repeats=4) -# qml.adjoint(qml.IQPEmbedding)(x2, wires=range(n_wires), n_repeats=4) -# return qml.probs(wires=range(n_wires)) +# qp.IQPEmbedding(x1, wires=range(n_wires), n_repeats=4) +# qp.adjoint(qp.IQPEmbedding)(x2, wires=range(n_wires), n_repeats=4) +# return qp.probs(wires=range(n_wires)) # # return lambda x1, x2: circuit(x1, x2)[0] # |0..0> state probability # @@ -335,7 +335,7 @@ def run_qsvm(n_samples, test_size): # def classify_with_qsvm(Xtr, Xte, ytr, yte): # kernel = get_kernel_circuit(n_wires=Xtr.shape[1]) # -# kernel_matrix_fn = lambda X, Z: qml.kernels.kernel_matrix(X, Z, kernel) +# kernel_matrix_fn = lambda X, Z: qp.kernels.kernel_matrix(X, Z, kernel) # svc = SVC(kernel=kernel_matrix_fn).fit(Xtr, ytr) # # # train/test accuracy diff --git a/demonstrations_v2/covalent_cloud_gpu/metadata.json b/demonstrations_v2/covalent_cloud_gpu/metadata.json index b67c130cef..48e6326e80 100644 --- a/demonstrations_v2/covalent_cloud_gpu/metadata.json +++ b/demonstrations_v2/covalent_cloud_gpu/metadata.json @@ -11,7 +11,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2024-05-24T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning" ], diff --git a/demonstrations_v2/function_fitting_qsp/demo.py b/demonstrations_v2/function_fitting_qsp/demo.py index f9256af8d3..dbd6f9a749 100644 --- a/demonstrations_v2/function_fitting_qsp/demo.py +++ b/demonstrations_v2/function_fitting_qsp/demo.py @@ -182,20 +182,20 @@ def generate_many_sro(a_vals): # -import pennylane as qml +import pennylane as qp def QSP_circ(phi, W): """This circuit applies the SPO. The components in the matrix representation of the final unitary are polynomials! """ - qml.Hadamard(wires=0) # set initial state |+> + qp.Hadamard(wires=0) # set initial state |+> for angle in phi[:-1]: - qml.RZ(angle, wires=0) - qml.QubitUnitary(W, wires=0) + qp.RZ(angle, wires=0) + qp.QubitUnitary(W, wires=0) - qml.RZ(phi[-1], wires=0) # final rotation - qml.Hadamard(wires=0) # change of basis |+> , |-> + qp.RZ(phi[-1], wires=0) # final rotation + qp.Hadamard(wires=0) # change of basis |+> , |-> return @@ -224,7 +224,7 @@ def QSP_circ(phi, W): for i in range(5): phi = torch.rand(d + 1, generator=gen) * 2 * torch.tensor([math.pi], requires_grad=False) - matrix_func = qml.matrix(QSP_circ, wire_order=[0]) + matrix_func = qp.matrix(QSP_circ, wire_order=[0]) y_vals = [matrix_func(phi, w)[0, 0].real for w in w_mats] plt.plot(a_vals, y_vals, label=f"poly #{i}") @@ -274,7 +274,7 @@ def QSP_circ(phi, W): # :math:`\hat{W}(a)` for varying :math:`a,` and produces the # predicted :math:`y` values. # -# Next we leverage the PennyLane function `qml.matrix() +# Next we leverage the PennyLane function `qp.matrix() # `__, # which accepts our quantum function (it can also accept quantum tapes and # QNodes) and returns its unitary matrix representation. We are interested @@ -306,7 +306,7 @@ def __init__(self, degree, num_vals, random_seed=None): def forward(self, omega_mats): """PennyLane forward implementation""" y_pred = [] - generate_qsp_mat = qml.matrix(QSP_circ, wire_order=[0]) + generate_qsp_mat = qp.matrix(QSP_circ, wire_order=[0]) for w in omega_mats: u_qsp = generate_qsp_mat(self.phi, w) diff --git a/demonstrations_v2/function_fitting_qsp/metadata.json b/demonstrations_v2/function_fitting_qsp/metadata.json index 9ae7fc42cb..d52d75ba9c 100644 --- a/demonstrations_v2/function_fitting_qsp/metadata.json +++ b/demonstrations_v2/function_fitting_qsp/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2022-05-24T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning" ], diff --git a/demonstrations_v2/getting_started_with_hybrid_jobs/demo.py b/demonstrations_v2/getting_started_with_hybrid_jobs/demo.py index 6c27e923a6..f3e4b244ac 100644 --- a/demonstrations_v2/getting_started_with_hybrid_jobs/demo.py +++ b/demonstrations_v2/getting_started_with_hybrid_jobs/demo.py @@ -62,10 +62,10 @@ # local simulator before moving onto a QPU. # -import pennylane as qml +import pennylane as qp from pennylane import numpy as np -device = qml.device("braket.local.qubit", wires=1) +device = qp.device("braket.local.qubit", wires=1) ###################################################################### # Now we define a circuit with two rotation gates and measure the expectation value in the @@ -73,11 +73,11 @@ # -@qml.qnode(device) +@qp.qnode(device) def circuit(params): - qml.RX(params[0], wires=0) - qml.RY(params[1], wires=0) - return qml.expval(qml.PauliZ(0)) + qp.RX(params[0], wires=0) + qp.RY(params[1], wires=0) + return qp.expval(qp.PauliZ(0)) ###################################################################### @@ -94,7 +94,7 @@ def circuit(params): def qubit_rotation(num_steps=10, stepsize=0.5): - opt = qml.GradientDescentOptimizer(stepsize=stepsize) + opt = qp.GradientDescentOptimizer(stepsize=stepsize) params = np.array([0.5, 0.75]) for i in range(num_steps): @@ -169,15 +169,15 @@ def qubit_rotation(num_steps=10, stepsize=0.5): @hybrid_job(device="local:pennylane/lightning.qubit") def qubit_rotation_hybrid_job(num_steps=1, stepsize=0.5): - device = qml.device("lightning.qubit", wires=1) + device = qp.device("lightning.qubit", wires=1) - @qml.qnode(device) + @qp.qnode(device) def circuit(params): - qml.RX(params[0], wires=0) - qml.RY(params[1], wires=0) - return qml.expval(qml.PauliZ(0)) + qp.RX(params[0], wires=0) + qp.RY(params[1], wires=0) + return qp.expval(qp.PauliZ(0)) - opt = qml.GradientDescentOptimizer(stepsize=stepsize) + opt = qp.GradientDescentOptimizer(stepsize=stepsize) params = np.array([0.5, 0.75]) for i in range(num_steps): @@ -333,20 +333,20 @@ def circuit(params): @hybrid_job(device=device_arn) # set priority QPU def qpu_qubit_rotation_hybrid_job(num_steps=10, stepsize=0.5): # AWS devices must be declared within the decorated function. - device = qml.device( + device = qp.device( "braket.aws.qubit", device_arn=device_arn.value, # Make sure the device ARN matches the hybrid job device ARN wires=2, ) - @qml.set_shots(1_000) - @qml.qnode(device) + @qp.set_shots(1_000) + @qp.qnode(device) def circuit(params): - qml.RX(params[0], wires=0) - qml.RY(params[1], wires=0) - return qml.expval(qml.PauliZ(0)) + qp.RX(params[0], wires=0) + qp.RY(params[1], wires=0) + return qp.expval(qp.PauliZ(0)) - opt = qml.GradientDescentOptimizer(stepsize=stepsize) + opt = qp.GradientDescentOptimizer(stepsize=stepsize) params = np.array([0.5, 0.75]) for i in range(num_steps): diff --git a/demonstrations_v2/getting_started_with_hybrid_jobs/metadata.json b/demonstrations_v2/getting_started_with_hybrid_jobs/metadata.json index ff533a65fb..69e9930c94 100644 --- a/demonstrations_v2/getting_started_with_hybrid_jobs/metadata.json +++ b/demonstrations_v2/getting_started_with_hybrid_jobs/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2023-10-16T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Devices and Performance" ], diff --git a/demonstrations_v2/gqe_training/demo.py b/demonstrations_v2/gqe_training/demo.py index 05d795a9cc..5b09a4f041 100644 --- a/demonstrations_v2/gqe_training/demo.py +++ b/demonstrations_v2/gqe_training/demo.py @@ -123,10 +123,10 @@ # import numpy as np -import pennylane as qml +import pennylane as qp def generate_molecule_data(molecules="H2"): - datasets = qml.data.load("qchem", molname=molecules) + datasets = qp.data.load("qchem", molname=molecules) # Get the time set T op_times = np.sort(np.array([-2**k for k in range(1, 5)] + [2**k for k in range(1, 5)]) / 160) @@ -136,10 +136,10 @@ def generate_molecule_data(molecules="H2"): for dataset in datasets: molecule = dataset.molecule num_electrons, num_qubits = molecule.n_electrons, 2 * molecule.n_orbitals - singles, doubles = qml.qchem.excitations(num_electrons, num_qubits) - double_excs = [qml.DoubleExcitation(time, wires=double) for double in doubles for time in op_times] - single_excs = [qml.SingleExcitation(time, wires=single) for single in singles for time in op_times] - identity_ops = [qml.exp(qml.I(range(num_qubits)), 1j*time) for time in op_times] # For Identity + singles, doubles = qp.qchem.excitations(num_electrons, num_qubits) + double_excs = [qp.DoubleExcitation(time, wires=double) for double in doubles for time in op_times] + single_excs = [qp.SingleExcitation(time, wires=single) for single in singles for time in op_times] + identity_ops = [qp.exp(qp.I(range(num_qubits)), 1j*time) for time in op_times] # For Identity operator_pool = double_excs + single_excs + identity_ops molecule_data[dataset.molname] = { "op_pool": np.array(operator_pool), @@ -174,18 +174,18 @@ def generate_molecule_data(molecules="H2"): # :class:`~.pennylane.Snapshot` as shown below. # -dev = qml.device("default.qubit", wires=num_qubits) +dev = qp.device("default.qubit", wires=num_qubits) -@qml.qnode(dev) +@qp.qnode(dev) def energy_circuit(gqe_ops): # Computes Eq. 1 from Nakaji et al. based on the selected unitary operators - qml.BasisState(init_state, wires=range(num_qubits)) # Initial state <-- Hartree Fock state + qp.BasisState(init_state, wires=range(num_qubits)) # Initial state <-- Hartree Fock state for op in gqe_ops: - qml.Snapshot(measurement=qml.expval(hamiltonian)) - qml.apply(op) # Applies each of the unitary operators - return qml.expval(hamiltonian) + qp.Snapshot(measurement=qp.expval(hamiltonian)) + qp.apply(op) # Applies each of the unitary operators + return qp.expval(hamiltonian) -energy_circuit = qml.snapshots(energy_circuit) +energy_circuit = qp.snapshots(energy_circuit) def get_subsequence_energies(op_seq): # Collates the energies of each subsequence for a batch of sequences diff --git a/demonstrations_v2/gqe_training/metadata.json b/demonstrations_v2/gqe_training/metadata.json index 87e78f2da5..e8a8918679 100644 --- a/demonstrations_v2/gqe_training/metadata.json +++ b/demonstrations_v2/gqe_training/metadata.json @@ -11,7 +11,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2024-09-20T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning", "Quantum Chemistry", diff --git a/demonstrations_v2/how_to_catalyst_lightning_gpu/demo.py b/demonstrations_v2/how_to_catalyst_lightning_gpu/demo.py index a805edf38d..f7a119740c 100644 --- a/demonstrations_v2/how_to_catalyst_lightning_gpu/demo.py +++ b/demonstrations_v2/how_to_catalyst_lightning_gpu/demo.py @@ -72,7 +72,7 @@ # # .. code-block:: python # -# import pennylane as qml +# import pennylane as qp # import jax.numpy as jnp # # import jax @@ -83,19 +83,19 @@ # # Set a random seed # key = jax.random.PRNGKey(0) # -# dev = qml.device("lightning.gpu", wires=num_wires) +# dev = qp.device("lightning.gpu", wires=num_wires) # -# @qml.qjit(autograph=True) -# @qml.qnode(dev) +# @qp.qjit(autograph=True) +# @qp.qnode(dev) # def circuit(params): # # # Apply layers of RZ and RY rotations # for i in range(num_wires): -# qml.RZ(params[3*i], wires=[i]) -# qml.RY(params[3*i+1], wires=[i]) -# qml.RZ(params[3*i+2], wires=[i]) +# qp.RZ(params[3*i], wires=[i]) +# qp.RY(params[3*i+1], wires=[i]) +# qp.RZ(params[3*i+2], wires=[i]) # -# return qml.expval(qml.PauliZ(0) + qml.PauliZ(num_wires-1)) +# return qp.expval(qp.PauliZ(0) + qp.PauliZ(num_wires-1)) # # # Initialize the weights # weights = jax.random.uniform(key, shape=(3 * num_wires,), dtype=jnp.float32) @@ -129,9 +129,9 @@ # # .. code-block:: python # -# @qml.qjit(autograph=True) +# @qp.qjit(autograph=True) # def workflow(params): -# g = qml.grad(circuit) +# g = qp.grad(circuit) # return g(params) # # >>> workflow(weights) @@ -171,10 +171,10 @@ # catalyst.debug.print("Step = {i}", i=i) # return (params, opt_state) # -# @qml.qjit +# @qp.qjit # def optimization(params): # opt_state = opt.init(params) -# (params, opt_state) = qml.for_loop(0, 10, 1)(update_step)(params, opt_state) +# (params, opt_state) = qp.for_loop(0, 10, 1)(update_step)(params, opt_state) # return params # # >>> optimization(weights) diff --git a/demonstrations_v2/how_to_catalyst_lightning_gpu/metadata.json b/demonstrations_v2/how_to_catalyst_lightning_gpu/metadata.json index bd51790e54..ab41e15ca3 100644 --- a/demonstrations_v2/how_to_catalyst_lightning_gpu/metadata.json +++ b/demonstrations_v2/how_to_catalyst_lightning_gpu/metadata.json @@ -11,7 +11,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2025-02-21T10:00:00+00:00", - "dateOfLastModification": "2025-12-10T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Getting Started", "Quantum Chemistry", diff --git a/demonstrations_v2/how_to_use_qiskit1_with_pennylane/demo.py b/demonstrations_v2/how_to_use_qiskit1_with_pennylane/demo.py index 38d7355ed0..2dc3445e02 100644 --- a/demonstrations_v2/how_to_use_qiskit1_with_pennylane/demo.py +++ b/demonstrations_v2/how_to_use_qiskit1_with_pennylane/demo.py @@ -35,14 +35,14 @@ # # If you want to distill how a PennyLane plugin works down to one thing, it’s all in the provided devices! In # PennyLane, you just :doc:`create your circuit (a quantum function) ` and decorate it with -# the QNode decorator :func:`@qml.qnode(dev) `, where ``dev`` is (one of) the plugin’s device(s). +# the QNode decorator :func:`@qp.qnode(dev) `, where ``dev`` is (one of) the plugin’s device(s). # # In PennyLane and its plugins, # `devices `__ are called upon by their short name, and can be loaded via the :func:`~pennylane.device` function: # # .. code-block:: # -# qml.device("shortname", *device_options) +# qp.device("shortname", *device_options) # # If you’ve # seen PennyLane code before, you’ve probably seen ``"default.qubit"`` or ``"lightning.qubit"`` as @@ -61,7 +61,7 @@ # # # If you want to use any of these devices in PennyLane, simply put those short names into -# ``qml.device`` and any quantum function decorated with ``@qml.qnode(dev)`` will execute on the +# ``qp.device`` and any quantum function decorated with ``@qp.qnode(dev)`` will execute on the # corresponding device. # @@ -96,16 +96,16 @@ # In PennyLane, we can execute the exact same circuit on the exact same device and backend like so: # -import pennylane as qml +import pennylane as qp -dev = qml.device("qiskit.basicsim", wires=2) +dev = qp.device("qiskit.basicsim", wires=2) -@qml.set_shots(1024) -@qml.qnode(dev) +@qp.set_shots(1024) +@qp.qnode(dev) def circuit(): - qml.Hadamard(0) - qml.CNOT([0, 1]) - return qml.counts(wires=1) + qp.Hadamard(0) + qp.CNOT([0, 1]) + return qp.counts(wires=1) print(circuit()) @@ -202,10 +202,10 @@ def qiskit_GHZ_circuit(n): ###################################################################### # To convert this work into PennyLane, let’s start with the Qiskit-side ``SparsePauliOp`` operators -# and converting them to PennyLane objects with ``qml.from_qiskit_op``. +# and converting them to PennyLane objects with ``qp.from_qiskit_op``. # -pl_operators = [qml.from_qiskit_op(qiskit_op) for qiskit_op in operators] +pl_operators = [qp.from_qiskit_op(qiskit_op) for qiskit_op in operators] print(pl_operators) ###################################################################### @@ -227,22 +227,22 @@ def qiskit_GHZ_circuit(n): # ###################################################################### -# Next, we show how to convert the Qiskit ``QuantumCircuit``, ``qc``, to PennyLane with ``qml.from_qiskit``. We +# Next, we show how to convert the Qiskit ``QuantumCircuit``, ``qc``, to PennyLane with ``qp.from_qiskit``. We # can append the measurements — expectation values (:func:`~pennylane.expval`) of ``pl_operators`` — with the # ``measurements`` keyword argument, which accepts a list of PennyLane measurements. # -measurements = [qml.expval(op) for op in pl_operators] # expectation values +measurements = [qp.expval(op) for op in pl_operators] # expectation values qc = qiskit_GHZ_circuit(n) -pl_qfunc = qml.from_qiskit(qc, measurements=measurements) +pl_qfunc = qp.from_qiskit(qc, measurements=measurements) ###################################################################### # The last thing to do is make ``pl_func`` a QNode. We can’t decorate ``pl_qfunc`` with -# ``@qml.qnode``, but we can equivalently wrap it with ``qml.QNode`` and supply the device. +# ``@qp.qnode``, but we can equivalently wrap it with ``qp.QNode`` and supply the device. # -pl_circuit = qml.QNode(pl_qfunc, device=qml.device("lightning.qubit", wires=n)) +pl_circuit = qp.QNode(pl_qfunc, device=qp.device("lightning.qubit", wires=n)) print(pl_circuit()) ###################################################################### @@ -260,11 +260,11 @@ def qiskit_GHZ_circuit(n): # you can measure this with :func:`~pennylane.classical_shadow`. # -measurements = [qml.classical_shadow(wires=range(n))] -pl_qfunc = qml.from_qiskit(qc, measurements=measurements) +measurements = [qp.classical_shadow(wires=range(n))] +pl_qfunc = qp.from_qiskit(qc, measurements=measurements) -pl_circuit = qml.QNode(pl_qfunc, device=qml.device("default.qubit", wires=n)) -print(qml.set_shots(pl_circuit, shots=5)()) +pl_circuit = qp.QNode(pl_qfunc, device=qp.device("default.qubit", wires=n)) +print(qp.set_shots(pl_circuit, shots=5)()) ###################################################################### # .. rst-class:: sphx-glr-script-out @@ -332,27 +332,27 @@ def qiskit_GHZ_circuit(n): # This circuit contains two sets of differentiable parameters: ``phis`` (length 2) and ``theta`` # (scalar). # -# If we give this Qiskit circuit to ``qml.from_qiskit``, we get a quantum function that can +# If we give this Qiskit circuit to ``qp.from_qiskit``, we get a quantum function that can # subsequently be called within a circuit — it’s as if the gates and operations contained within it # get transferred over to our new QNode. # import pennylane.numpy as np -pl_qfunc = qml.from_qiskit(qc) +pl_qfunc = qp.from_qiskit(qc) -dev = qml.device("lightning.qubit", wires=n) +dev = qp.device("lightning.qubit", wires=n) -@qml.qnode(dev) +@qp.qnode(dev) def differentiable_circuit(phis, theta): pl_qfunc(phis, theta) - return [qml.expval(qml.Z(i)) for i in range(n)] + return [qp.expval(qp.Z(i)) for i in range(n)] phis = np.array([0.6, 0.7]) theta = np.array([0.19]) print(differentiable_circuit(phis, theta)) -qml.draw_mpl(differentiable_circuit, style="pennylane")(phis, theta) +qp.draw_mpl(differentiable_circuit, style="pennylane")(phis, theta) plt.show() ###################################################################### @@ -388,7 +388,7 @@ def cost(phis, theta): # function value after each optimization step. # -opt = qml.AdamOptimizer(0.1) +opt = qp.AdamOptimizer(0.1) for i in range(100): (phis, theta), new_loss = opt.step_and_cost(cost, phis, theta) diff --git a/demonstrations_v2/how_to_use_qiskit1_with_pennylane/metadata.json b/demonstrations_v2/how_to_use_qiskit1_with_pennylane/metadata.json index e322437390..028021841f 100644 --- a/demonstrations_v2/how_to_use_qiskit1_with_pennylane/metadata.json +++ b/demonstrations_v2/how_to_use_qiskit1_with_pennylane/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2024-07-02T00:00:00+00:00", - "dateOfLastModification": "2025-11-11T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Computing", "How-to" diff --git a/demonstrations_v2/ibm_pennylane/demo.py b/demonstrations_v2/ibm_pennylane/demo.py index 1452518ecb..cb3727ed7f 100644 --- a/demonstrations_v2/ibm_pennylane/demo.py +++ b/demonstrations_v2/ibm_pennylane/demo.py @@ -41,14 +41,14 @@ # they can be used just like any other device offered in PennyLane! # Currently, there are three devices available — ``Aer``, ``BasicSim`` and ``Remote`` — that can be initialized # as follows: -import pennylane as qml +import pennylane as qp from qiskit_aer import AerSimulator qubits = 4 -dev_aer = qml.device("qiskit.aer", wires=qubits) -dev_basicsim = qml.device("qiskit.basicsim", wires=qubits) +dev_aer = qp.device("qiskit.aer", wires=qubits) +dev_basicsim = qp.device("qiskit.basicsim", wires=qubits) try: - dev_remote = qml.device("qiskit.remote", wires=qubits, backend=AerSimulator()) + dev_remote = qp.device("qiskit.remote", wires=qubits, backend=AerSimulator()) except Exception as e: print(e) @@ -62,7 +62,7 @@ # To specify which machine or computational framework these devices actually connect to, we can # use the ``backend`` argument. -dev_aer = qml.device("qiskit.aer", wires=qubits) +dev_aer = qp.device("qiskit.aer", wires=qubits) ############################################################################## # For the Aer device, different quantum computers can be used by changing the backend to the name @@ -137,10 +137,10 @@ from pennylane import numpy as pnp from qiskit_ibm_runtime import QiskitRuntimeService -import pennylane as qml +import pennylane as qp # Obtaining the Hamiltonian for H2 from PennyLane QChem dataset -[dataset] = qml.data.load("qchem", molname="H2", bondlength=0.742, basis="STO-3G") +[dataset] = qp.data.load("qchem", molname="H2", bondlength=0.742, basis="STO-3G") H = dataset.hamiltonian qubits = 4 @@ -153,7 +153,7 @@ try: # Our device supports a maximum of 31 qubits NUM_QUBITS_SUPPORTED = 31 - dev = qml.device("qiskit.remote", wires=NUM_QUBITS_SUPPORTED, backend=backend) + dev = qp.device("qiskit.remote", wires=NUM_QUBITS_SUPPORTED, backend=backend) except Exception as e: print(e) @@ -171,30 +171,30 @@ def four_qubit_ansatz(theta): # initial state 1100: - qml.PauliX(wires=0) - qml.PauliX(wires=1) + qp.PauliX(wires=0) + qp.PauliX(wires=1) # change of basis - qml.RX(pnp.pi / 2, wires=0) - qml.Hadamard(wires=1) - qml.Hadamard(wires=2) - qml.Hadamard(wires=3) + qp.RX(pnp.pi / 2, wires=0) + qp.Hadamard(wires=1) + qp.Hadamard(wires=2) + qp.Hadamard(wires=3) - qml.CNOT(wires=[3, 2]) - qml.CNOT(wires=[2, 1]) - qml.CNOT(wires=[1, 0]) + qp.CNOT(wires=[3, 2]) + qp.CNOT(wires=[2, 1]) + qp.CNOT(wires=[1, 0]) - qml.RZ(theta, wires=0) + qp.RZ(theta, wires=0) - qml.CNOT(wires=[1, 0]) - qml.CNOT(wires=[2, 1]) - qml.CNOT(wires=[3, 2]) + qp.CNOT(wires=[1, 0]) + qp.CNOT(wires=[2, 1]) + qp.CNOT(wires=[3, 2]) # invert change of basis - qml.RX(-pnp.pi / 2, wires=0) - qml.Hadamard(wires=1) - qml.Hadamard(wires=2) - qml.Hadamard(wires=3) + qp.RX(-pnp.pi / 2, wires=0) + qp.Hadamard(wires=1) + qp.Hadamard(wires=2) + qp.Hadamard(wires=3) ############################################################################## @@ -206,15 +206,15 @@ def four_qubit_ansatz(theta): from pennylane_qiskit import qiskit_session -@qml.qnode(dev) +@qp.qnode(dev) def cost_fn(theta): four_qubit_ansatz(theta) - return qml.expval(H) + return qp.expval(H) max_iterations = 40 theta = pnp.array(0.0, requires_grad=True) -opt = qml.GradientDescentOptimizer(stepsize=0.4) +opt = qp.GradientDescentOptimizer(stepsize=0.4) energies = [] with qiskit_session(dev) as session: @@ -244,28 +244,28 @@ def cost_fn(theta): # finite number of shots to estimate the energy in each iteration, rather than performing an exact # calculation using the information hidden in the vector representation of the quantum state. -dev1 = qml.device("default.qubit", wires=4) +dev1 = qp.device("default.qubit", wires=4) shots = 8000 -dev2 = qml.device("qiskit.aer", wires=4) +dev2 = qp.device("qiskit.aer", wires=4) -@qml.qnode(dev1) +@qp.qnode(dev1) def cost_fn_1(theta): four_qubit_ansatz(theta) - return qml.expval(H) + return qp.expval(H) -@qml.set_shots(shots) -@qml.qnode(dev2) +@qp.set_shots(shots) +@qp.qnode(dev2) def cost_fn_2(theta): four_qubit_ansatz(theta) - return qml.expval(H) + return qp.expval(H) # we can also use the qnode to draw the circuit import matplotlib.pyplot as plt -qml.draw_mpl(cost_fn_1, decimals=2)(theta=1.0) +qp.draw_mpl(cost_fn_1, decimals=2)(theta=1.0) plt.show() ############################################################################## @@ -278,7 +278,7 @@ def cost_fn_2(theta): stepsize = 0.4 max_iterations = 40 -opt = qml.GradientDescentOptimizer(stepsize=stepsize) +opt = qp.GradientDescentOptimizer(stepsize=stepsize) theta_1 = pnp.array(0.0, requires_grad=True) theta_2 = pnp.array(0.0, requires_grad=True) energies_1 = [] @@ -346,7 +346,7 @@ def cost_fn_2(theta): plt.plot(energies_2, color="b", label="qiskit.aer") # min energy = min eigenvalue -min_energy = min(qml.eigvals(H)) +min_energy = min(qp.eigvals(H)) z = [min_energy] * max_iterations plt.plot(z, "--", color="k", label="Exact answer") diff --git a/demonstrations_v2/ibm_pennylane/metadata.json b/demonstrations_v2/ibm_pennylane/metadata.json index cedbf05b73..299478ccea 100644 --- a/demonstrations_v2/ibm_pennylane/metadata.json +++ b/demonstrations_v2/ibm_pennylane/metadata.json @@ -14,7 +14,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2023-06-20T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Devices and Performance" ], diff --git a/demonstrations_v2/learning2learn/demo.py b/demonstrations_v2/learning2learn/demo.py index 5c14d5ad68..e44d650763 100644 --- a/demonstrations_v2/learning2learn/demo.py +++ b/demonstrations_v2/learning2learn/demo.py @@ -139,7 +139,7 @@ # # Quantum Machine Learning -import pennylane as qml +import pennylane as qp from pennylane import qaoa # Classical Machine Learning @@ -236,18 +236,18 @@ def qaoa_layer(gamma, alpha): # Creates the actual quantum circuit for the QAOA algorithm def circuit(params, **kwargs): for w in wires: - qml.Hadamard(wires=w) - qml.layer(qaoa_layer, n_layers, params[0], params[1]) - return qml.expval(cost_h) + qp.Hadamard(wires=w) + qp.layer(qaoa_layer, n_layers, params[0], params[1]) + return qp.expval(cost_h) # Evaluates the cost Hamiltonian def hamiltonian(params, **kwargs): """Evaluate the cost Hamiltonian, given the angles and the graph.""" - dev = qml.device("default.qubit", wires=len(graph.nodes)) + dev = qp.device("default.qubit", wires=len(graph.nodes)) # This qnode evaluates the expectation value of the cost hamiltonian operator - cost = qml.QNode(circuit, dev, diff_method="backprop", interface="tf") + cost = qp.QNode(circuit, dev, diff_method="backprop", interface="tf") return cost(params) diff --git a/demonstrations_v2/learning2learn/metadata.json b/demonstrations_v2/learning2learn/metadata.json index fc267bd39d..9f31c5f741 100644 --- a/demonstrations_v2/learning2learn/metadata.json +++ b/demonstrations_v2/learning2learn/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2021-03-02T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Machine Learning" ], diff --git a/demonstrations_v2/low_depth_circuits_mnist/demo.py b/demonstrations_v2/low_depth_circuits_mnist/demo.py index d9f6656a9a..511cbf3550 100644 --- a/demonstrations_v2/low_depth_circuits_mnist/demo.py +++ b/demonstrations_v2/low_depth_circuits_mnist/demo.py @@ -121,13 +121,13 @@ def FRQI_decoding(states): # # The dataset configuration sets the name as ``'low-depth-mnist'`` and constructs the dataset path as # ``datasets/low-depth-mnist/low-depth-mnist.h5``. For dataset loading, if the file exists locally, it -# is loaded using ``qml.data.Dataset.open``. Otherwise, the dataset is downloaded from the PennyLane -# data repository via ``qml.data.load``, note that the dataset size is approximately 1 GB. +# is loaded using ``qp.data.Dataset.open``. Otherwise, the dataset is downloaded from the PennyLane +# data repository via ``qp.data.load``, note that the dataset size is approximately 1 GB. # import os import jax -import pennylane as qml +import pennylane as qp # JAX supports the single-precision numbers by default. # The following line enables double-precision. @@ -142,10 +142,10 @@ def FRQI_decoding(states): # Load the dataset if already downloaded if os.path.exists(dataset_path): - dataset_params = qml.data.Dataset.open(dataset_path) + dataset_params = qp.data.Dataset.open(dataset_path) else: # Download the dataset (~ 1 GB) - [dataset_params] = qml.data.load(DATASET_NAME) + [dataset_params] = qp.data.load(DATASET_NAME) ###################################################################### # In the following cell, we define the ``get_circuit`` function that creates a quantum circuit based @@ -172,22 +172,22 @@ def get_circuit(circuit_layout): :return circuit: A JAX-compiled quantum circuit function that takes parameters and returns the quantum state. """ - dev = qml.device("default.qubit", wires=11) + dev = qp.device("default.qubit", wires=11) @jax.jit - @qml.qnode(dev) + @qp.qnode(dev) def circuit(params): counter = 0 for gate, wire in circuit_layout: if gate == "RY": - qml.RY(params[counter], wire) + qp.RY(params[counter], wire) counter += 1 elif gate == "CNOT": - qml.CNOT(wire) + qp.CNOT(wire) - return qml.state() + return qp.state() return circuit @@ -327,32 +327,32 @@ def circuit(params): key = jax.random.PRNGKey(SEED) # Define the model and training functions -dev = qml.device("default.qubit", wires=N_QUBITS) +dev = qp.device("default.qubit", wires=N_QUBITS) @jax.jit -@qml.qnode(dev, interface="jax") +@qp.qnode(dev, interface="jax") def circuit(network_params, state): p = iter(network_params) - qml.StatePrep(state, wires=range(N_QUBITS)) + qp.StatePrep(state, wires=range(N_QUBITS)) # First two layers of local RY rotations for w in range(N_QUBITS): - qml.RY(next(p), wires=w) + qp.RY(next(p), wires=w) # SO(4) building blocks for _ in range(DEPTH): for j in range(N_QUBITS - 1): - qml.CNOT(wires=[j, j + 1]) - qml.RY(next(p), wires=j) - qml.RY(next(p), wires=j + 1) - qml.CNOT(wires=[j, j + 1]) - qml.RY(next(p), wires=j) - qml.RY(next(p), wires=j + 1) + qp.CNOT(wires=[j, j + 1]) + qp.RY(next(p), wires=j) + qp.RY(next(p), wires=j + 1) + qp.CNOT(wires=[j, j + 1]) + qp.RY(next(p), wires=j) + qp.RY(next(p), wires=j + 1) # Probability of computational basis states of the last qubit # Can be extended to more qubits for multiclass case - return qml.probs(N_QUBITS - 1) + return qp.probs(N_QUBITS - 1) model = jax.vmap(circuit, in_axes=(None, 0)) diff --git a/demonstrations_v2/low_depth_circuits_mnist/metadata.json b/demonstrations_v2/low_depth_circuits_mnist/metadata.json index 259a920be2..2308658d93 100644 --- a/demonstrations_v2/low_depth_circuits_mnist/metadata.json +++ b/demonstrations_v2/low_depth_circuits_mnist/metadata.json @@ -14,7 +14,7 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2025-12-04T00:00:00+00:00", - "dateOfLastModification": "2026-01-14T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Machine Learning" ], diff --git a/demonstrations_v2/ml_classical_shadows/demo.py b/demonstrations_v2/ml_classical_shadows/demo.py index bbff01acec..813153b849 100644 --- a/demonstrations_v2/ml_classical_shadows/demo.py +++ b/demonstrations_v2/ml_classical_shadows/demo.py @@ -116,7 +116,7 @@ def build_coupling_mats(num_mats, num_rows, num_cols): # :math:`H` for the model we have instantiated above. # -import pennylane as qml +import pennylane as qp def Hamiltonian(J_mat): coeffs, ops = [], [] @@ -124,10 +124,10 @@ def Hamiltonian(J_mat): for i, j in it.combinations(range(ns), r=2): coeff = J_mat[i, j] if coeff: - for op in [qml.PauliX, qml.PauliY, qml.PauliZ]: + for op in [qp.PauliX, qp.PauliY, qp.PauliZ]: coeffs.append(coeff) ops.append(op(i) @ op(j)) - H = qml.Hamiltonian(coeffs, ops) + H = qp.Hamiltonian(coeffs, ops) return H print(f"Hamiltonian =\n{Hamiltonian(J_mat)}") @@ -151,11 +151,11 @@ def Hamiltonian(J_mat): def corr_function(i, j): ops = [] - for op in [qml.PauliX, qml.PauliY, qml.PauliZ]: + for op in [qp.PauliX, qp.PauliY, qp.PauliZ]: if i != j: ops.append(op(i) @ op(j)) else: - ops.append(qml.Identity(i)) + ops.append(qp.Identity(i)) return ops ###################################################################### @@ -186,14 +186,14 @@ def corr_function(i, j): # state and measures the expectation value of the provided set of observables. # -dev_exact = qml.device("default.qubit", wires=num_qubits) # for exact simulation +dev_exact = qp.device("default.qubit", wires=num_qubits) # for exact simulation def circuit(psi, observables): psi = psi / np.linalg.norm(psi) # normalize the state - qml.StatePrep(psi, wires=range(num_qubits)) - return [qml.expval(o) for o in observables] + qp.StatePrep(psi, wires=range(num_qubits)) + return [qp.expval(o) for o in observables] -circuit_exact = qml.QNode(circuit, dev_exact) +circuit_exact = qp.QNode(circuit, dev_exact) ###################################################################### @@ -284,8 +284,8 @@ def build_exact_corrmat(coups, corrs, circuit, psi): # a ``QNode`` utilizing a device that performs single-shot measurements. # -dev_oshot = qml.device("default.qubit", wires=num_qubits) -circuit_oshot = qml.set_shots(qml.QNode(circuit, dev_oshot), shots = 1) +dev_oshot = qp.device("default.qubit", wires=num_qubits) +circuit_oshot = qp.set_shots(qp.QNode(circuit, dev_oshot), shots = 1) ###################################################################### @@ -297,7 +297,7 @@ def build_exact_corrmat(coups, corrs, circuit, psi): def gen_class_shadow(circ_template, circuit_params, num_shadows, num_qubits): # prepare the complete set of available Pauli operators - unitary_ops = [qml.PauliX, qml.PauliY, qml.PauliZ] + unitary_ops = [qp.PauliX, qp.PauliY, qp.PauliZ] # sample random Pauli measurements uniformly unitary_ensmb = np.random.randint(0, 3, size=(num_shadows, num_qubits), dtype=int) @@ -345,9 +345,9 @@ def gen_class_shadow(circ_template, circuit_params, num_shadows, num_qubits): def snapshot_state(meas_list, obs_list): # undo the rotations done for performing Pauli measurements in the specific basis rotations = [ - qml.matrix(qml.Hadamard(wires=0)), # X-basis - qml.matrix(qml.Hadamard(wires=0)) @ qml.matrix(qml.adjoint(qml.S(wires=0))), # Y-basis - qml.matrix(qml.Identity(wires=0)), # Z-basis + qp.matrix(qp.Hadamard(wires=0)), # X-basis + qp.matrix(qp.Hadamard(wires=0)) @ qp.matrix(qp.adjoint(qp.S(wires=0))), # Y-basis + qp.matrix(qp.Identity(wires=0)), # Z-basis ] # reconstruct snapshot from local Pauli measurements @@ -409,7 +409,7 @@ def estimate_shadow_obs(shadow, observable, k=10): # convert Pennylane observables to indices map_name_to_int = {"PauliX": 0, "PauliY": 1, "PauliZ": 2} - if isinstance(observable, (qml.PauliX, qml.PauliY, qml.PauliZ)): + if isinstance(observable, (qp.PauliX, qp.PauliY, qp.PauliZ)): target_obs = np.array([map_name_to_int[observable.name]]) target_locs = np.array([observable.wires[0]]) else: diff --git a/demonstrations_v2/ml_classical_shadows/metadata.json b/demonstrations_v2/ml_classical_shadows/metadata.json index d9a05c75ae..9c5ad43fc8 100644 --- a/demonstrations_v2/ml_classical_shadows/metadata.json +++ b/demonstrations_v2/ml_classical_shadows/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2022-05-02T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Machine Learning" ], diff --git a/demonstrations_v2/oqc_pulse/demo.py b/demonstrations_v2/oqc_pulse/demo.py index e2289bd640..d7ff03559a 100644 --- a/demonstrations_v2/oqc_pulse/demo.py +++ b/demonstrations_v2/oqc_pulse/demo.py @@ -79,7 +79,7 @@ for :math:`1 \text{ ns}.` We choose :math:`\omega = 5 \times 2\pi \text{ GHz}` as the drive and qubit frequency (i.e. we are at resonance :math:`\omega - \nu = 0`). """ -import pennylane as qml +import pennylane as qp import numpy as np import jax.numpy as jnp import jax @@ -87,7 +87,7 @@ jax.config.update("jax_enable_x64", True) import matplotlib.pyplot as plt -X, Y, Z = qml.PauliX(0), qml.PauliY(0), qml.PauliZ(0) +X, Y, Z = qp.PauliX(0), qp.PauliY(0), qp.PauliZ(0) omega = 2 * jnp.pi * 5.0 @@ -103,17 +103,17 @@ def wrapped(p, t): return wrapped -H = -omega / 2 * qml.PauliZ(0) -H += amp(omega) * qml.PauliY(0) +H = -omega / 2 * qp.PauliZ(0) +H += amp(omega) * qp.PauliY(0) # We generate a qnode that evolves the qubit state according to the time-dependent # Hamiltonian H. @jax.jit -@qml.qnode(qml.device("default.qubit", wires=1), interface="jax") +@qp.qnode(qp.device("default.qubit", wires=1), interface="jax") def trajectory(params, t): - qml.evolve(H)((params,), t, return_intermediate=True) - return [qml.expval(op) for op in [X, Y, Z]] + qp.evolve(H)((params,), t, return_intermediate=True) + return [qp.expval(op) for op in [X, Y, Z]] # By setting ``return_intermediate=True``, we can output all intermediate time steps. @@ -155,17 +155,17 @@ def wrapped(p, t): return wrapped -H1 = -omega / 2 * qml.PauliZ(0) +H1 = -omega / 2 * qp.PauliZ(0) H1 += amp(omega) * Y # This time we compute the full evolution until the final time after 20ns # return_intermediate=False is the default, so we dont have to set it explicitly. @jax.jit -@qml.qnode(qml.device("default.qubit", wires=1), interface="jax") +@qp.qnode(qp.device("default.qubit", wires=1), interface="jax") def trajectory(Omega0, phi): - qml.evolve(H1)([[Omega0, phi]], 20.0) - return [qml.expval(op) for op in [X, Y, Z]] + qp.evolve(H1)([[Omega0, phi]], 20.0) + return [qp.expval(op) for op in [X, Y, Z]] # We use ``jax.vmap`` to efficiently evaluate the ``trajectory`` function for all amplitudes @@ -217,8 +217,8 @@ def trajectory(Omega0, phi): # We start by setting up the real device and a simulation device and perform all measurements on qubit 5. wire = 5 -dev_sim = qml.device("default.qubit", wires=[wire]) -dev_lucy = qml.device( +dev_sim = qp.device("default.qubit", wires=[wire]) +dev_lucy = qp.device( "braket.aws.qubit", device_arn="arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy", wires=range(8)) @@ -232,30 +232,30 @@ def trajectory(Omega0, phi): # :func:`~.pennylane.pulse.transmon_interaction` and :func:`~.pennylane.pulse.transmon_drive`. # This corresponds to the Z term for a single qubit with no interactions. -H0 = qml.pulse.transmon_interaction( +H0 = qp.pulse.transmon_interaction( qubit_freq=[qubit_freq], connections=[], coupling=[], wires=[wire] ) # This corresponds to the drive term proportional to Y. # We can control the amplitude and phase via a callable parameter. # The drive frequency is set equal to the qubit's resonance frequency. -Hd0 = qml.pulse.transmon_drive( - amplitude=qml.pulse.constant, - phase=qml.pulse.constant, +Hd0 = qp.pulse.transmon_drive( + amplitude=qp.pulse.constant, + phase=qp.pulse.constant, freq=qubit_freq, wires=[wire], ) def circuit(params, duration): - qml.evolve(H0 + Hd0)(params, t=duration) - return qml.expval(qml.PauliZ(wire)) + qp.evolve(H0 + Hd0)(params, t=duration) + return qp.expval(qp.PauliZ(wire)) # We create two qunodes, one that executes on the remote device # and one in simulation for comparison. -qnode_sim = jax.jit(qml.QNode(circuit, dev_sim, interface="jax")) -qnode_lucy = qml.set_shots(qml.QNode(circuit, dev_lucy, interface="jax"), shots = 1000) +qnode_sim = jax.jit(qp.QNode(circuit, dev_sim, interface="jax")) +qnode_lucy = qp.set_shots(qp.QNode(circuit, dev_lucy, interface="jax"), shots = 1000) ############################################################################## # We are going to fit the resulting Rabi oscillations to a sinusoid. For this we use @@ -425,30 +425,30 @@ def amplitude(p, t): return attenuation * p -Hd_attenuated = qml.pulse.transmon_drive( - amplitude, qml.pulse.constant, qubit_freq, wires=[wire] +Hd_attenuated = qp.pulse.transmon_drive( + amplitude, qp.pulse.constant, qubit_freq, wires=[wire] ) @jax.jit -@qml.qnode(dev_sim, interface="jax") +@qp.qnode(dev_sim, interface="jax") def qnode_sim(params, duration=15.0): - qml.evolve(H0 + Hd_attenuated)(params, t=duration, atol=1e-12) + qp.evolve(H0 + Hd_attenuated)(params, t=duration, atol=1e-12) return [ - qml.expval(qml.PauliX(wire)), - qml.expval(qml.PauliY(wire)), - qml.expval(qml.PauliZ(wire)), + qp.expval(qp.PauliX(wire)), + qp.expval(qp.PauliY(wire)), + qp.expval(qp.PauliZ(wire)), ] -@qml.set_shots(1000) -@qml.qnode(dev_lucy, interface="jax") +@qp.set_shots(1000) +@qp.qnode(dev_lucy, interface="jax") def qnode_lucy(params, duration=15.0): - qml.evolve(H0 + Hd0)(params, t=duration) + qp.evolve(H0 + Hd0)(params, t=duration) return [ - qml.expval(qml.PauliX(wire)), - qml.expval(qml.PauliY(wire)), - qml.expval(qml.PauliZ(wire)), + qp.expval(qp.PauliX(wire)), + qp.expval(qp.PauliY(wire)), + qp.expval(qp.PauliZ(wire)), ] diff --git a/demonstrations_v2/oqc_pulse/metadata.json b/demonstrations_v2/oqc_pulse/metadata.json index 9416960812..1df044733a 100644 --- a/demonstrations_v2/oqc_pulse/metadata.json +++ b/demonstrations_v2/oqc_pulse/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2023-10-30T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Computing" ], diff --git a/demonstrations_v2/plugins_hybrid/demo.py b/demonstrations_v2/plugins_hybrid/demo.py index 600fbca71a..cd4173a584 100644 --- a/demonstrations_v2/plugins_hybrid/demo.py +++ b/demonstrations_v2/plugins_hybrid/demo.py @@ -132,7 +132,7 @@ As usual, we begin by importing PennyLane and the wrapped version of NumPy provided by PennyLane: """ -import pennylane as qml +import pennylane as qp from pennylane import numpy as np ############################################################################## @@ -140,7 +140,7 @@ # the PennyLane-SF plugin is installed, the ``'strawberryfields.fock'`` device can be loaded # — no additional commands or library imports required. -dev_fock = qml.device("strawberryfields.fock", wires=2, cutoff_dim=2) +dev_fock = qp.device("strawberryfields.fock", wires=2, cutoff_dim=2) ############################################################################## # Compared to the default devices provided with PennyLane, the ``'strawberryfields.fock'`` @@ -164,11 +164,11 @@ # running on Strawberry Fields. -@qml.qnode(dev_fock, diff_method="parameter-shift") +@qp.qnode(dev_fock, diff_method="parameter-shift") def photon_redirection(params): - qml.FockState(1, wires=0) - qml.Beamsplitter(params[0], params[1], wires=[0, 1]) - return qml.expval(qml.NumberOperator(1)) + qp.FockState(1, wires=0) + qp.Beamsplitter(params[0], params[1], wires=[0, 1]) + return qp.expval(qp.NumberOperator(1)) ############################################################################## @@ -219,7 +219,7 @@ def cost(params): # # This can also be verified directly using PennyLane: -dphoton_redirection = qml.grad(photon_redirection, argnums=0) +dphoton_redirection = qp.grad(photon_redirection, argnums=0) print(dphoton_redirection([0.0, 0.0])) ############################################################################## @@ -236,7 +236,7 @@ def cost(params): # parameters over 100 optimization steps. # initialise the optimizer -opt = qml.GradientDescentOptimizer(stepsize=0.4) +opt = qp.GradientDescentOptimizer(stepsize=0.4) # set the number of steps steps = 100 @@ -304,24 +304,24 @@ def cost(params): # returns the squared difference of its two inputs using NumPy: # create the devices -dev_qubit = qml.device("default.qubit", wires=1) -dev_fock = qml.device("strawberryfields.fock", wires=2, cutoff_dim=10) +dev_qubit = qp.device("default.qubit", wires=1) +dev_fock = qp.device("strawberryfields.fock", wires=2, cutoff_dim=10) -@qml.qnode(dev_qubit, interface="autograd") +@qp.qnode(dev_qubit, interface="autograd") def qubit_rotation(phi1, phi2): """Qubit rotation QNode""" - qml.RX(phi1, wires=0) - qml.RY(phi2, wires=0) - return qml.expval(qml.PauliZ(0)) + qp.RX(phi1, wires=0) + qp.RY(phi2, wires=0) + return qp.expval(qp.PauliZ(0)) -@qml.qnode(dev_fock, diff_method="parameter-shift") +@qp.qnode(dev_fock, diff_method="parameter-shift") def photon_redirection(params): """The photon redirection QNode""" - qml.FockState(1, wires=0) - qml.Beamsplitter(params[0], params[1], wires=[0, 1]) - return qml.expval(qml.NumberOperator(1)) + qp.FockState(1, wires=0) + qp.Beamsplitter(params[0], params[1], wires=[0, 1]) + return qp.expval(qp.NumberOperator(1)) def squared_difference(x, y): @@ -374,7 +374,7 @@ def cost(params, phi1=0.5, phi2=0.1): # :math:`\theta=0.01,` :math:`\phi=0.01.` # initialise the optimizer -opt = qml.GradientDescentOptimizer(stepsize=0.4) +opt = qp.GradientDescentOptimizer(stepsize=0.4) # set the number of steps steps = 100 diff --git a/demonstrations_v2/plugins_hybrid/metadata.json b/demonstrations_v2/plugins_hybrid/metadata.json index e8c09421a6..33e215634a 100644 --- a/demonstrations_v2/plugins_hybrid/metadata.json +++ b/demonstrations_v2/plugins_hybrid/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2019-10-11T00:00:00+00:00", - "dateOfLastModification": "2026-01-14T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Devices and Performance" ], diff --git a/demonstrations_v2/pytorch_noise/demo.py b/demonstrations_v2/pytorch_noise/demo.py index 4250ea9dfa..8e0c26a414 100644 --- a/demonstrations_v2/pytorch_noise/demo.py +++ b/demonstrations_v2/pytorch_noise/demo.py @@ -67,7 +67,7 @@ PyTorch as well: """ -import pennylane as qml +import pennylane as qp import torch from torch.autograd import Variable @@ -78,7 +78,7 @@ # # Next, we will create our device: -dev = qml.device("rigetti.qvm", device="2q", noisy=True) +dev = qp.device("rigetti.qvm", device="2q", noisy=True) ############################################################################## # Here, we create a noisy two-qubit system, simulated via the QVM. If we wish, we could @@ -96,11 +96,11 @@ # running on the QVM. -@qml.qnode(dev, interface="torch") +@qp.qnode(dev, interface="torch") def circuit(phi, theta): - qml.RX(theta, wires=0) - qml.RZ(phi, wires=0) - return qml.expval(qml.PauliZ(0)) + qp.RX(theta, wires=0) + qp.RZ(phi, wires=0) + return qp.expval(qp.PauliZ(0)) ############################################################################## @@ -199,7 +199,7 @@ def cost(phi, theta, step): # on using Amazon Braket, see our tutorial on # :doc:`Computing gradients in parallel with Amazon Braket `. -import pennylane as qml +import pennylane as qp import torch from torch.autograd import Variable @@ -209,7 +209,7 @@ def cost(phi, theta, step): device_arn = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3" -qpu = qml.device( +qpu = qp.device( "braket.aws.qubit", device_arn=device_arn, wires=32, @@ -220,11 +220,11 @@ def cost(phi, theta, step): # Warning: check the pricing of Aspen-M-3 on Braket to make # sure you are aware of the costs associated with running the # optimization below. -@qml.qnode(dev, interface="torch") +@qp.qnode(dev, interface="torch") def circuit(phi, theta): - qml.RX(theta, wires=0) - qml.RZ(phi, wires=0) - return qml.expval(qml.PauliZ(0)) + qp.RX(theta, wires=0) + qp.RZ(phi, wires=0) + return qp.expval(qp.PauliZ(0)) def cost(phi, theta, step): diff --git a/demonstrations_v2/pytorch_noise/metadata.json b/demonstrations_v2/pytorch_noise/metadata.json index f183f8b47a..e975c57941 100644 --- a/demonstrations_v2/pytorch_noise/metadata.json +++ b/demonstrations_v2/pytorch_noise/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2019-10-11T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Devices and Performance" ], diff --git a/demonstrations_v2/qnn_module_tf/demo.py b/demonstrations_v2/qnn_module_tf/demo.py index e04993f90e..255731a197 100644 --- a/demonstrations_v2/qnn_module_tf/demo.py +++ b/demonstrations_v2/qnn_module_tf/demo.py @@ -94,16 +94,16 @@ # :doc:`default.qubit ` simulator and # operations from the :doc:`templates ` module. -import pennylane as qml +import pennylane as qp n_qubits = 2 -dev = qml.device("default.qubit", wires=n_qubits) +dev = qp.device("default.qubit", wires=n_qubits) -@qml.qnode(dev) +@qp.qnode(dev) def qnode(inputs, weights): - qml.AngleEmbedding(inputs, wires=range(n_qubits)) - qml.BasicEntanglerLayers(weights, wires=range(n_qubits)) - return [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)] + qp.AngleEmbedding(inputs, wires=range(n_qubits)) + qp.BasicEntanglerLayers(weights, wires=range(n_qubits)) + return [qp.expval(qp.PauliZ(wires=i)) for i in range(n_qubits)] ############################################################################### # Interfacing with Keras @@ -131,7 +131,7 @@ def qnode(inputs, weights): # # Now that ``weight_shapes`` is defined, it is easy to then convert the QNode: -qlayer = qml.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits) +qlayer = qp.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits) ############################################################################### # With this done, the QNode can now be treated just like any other Keras layer and we can proceed @@ -233,8 +233,8 @@ def qnode(inputs, weights): # re-define the layers clayer_1 = tf.keras.layers.Dense(4) -qlayer_1 = qml.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits) -qlayer_2 = qml.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits) +qlayer_1 = qp.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits) +qlayer_2 = qp.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits) clayer_2 = tf.keras.layers.Dense(2, activation="softmax") # construct the model diff --git a/demonstrations_v2/qnn_module_tf/metadata.json b/demonstrations_v2/qnn_module_tf/metadata.json index bc01bf098e..22aa94648c 100644 --- a/demonstrations_v2/qnn_module_tf/metadata.json +++ b/demonstrations_v2/qnn_module_tf/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2020-11-02T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Devices and Performance", "Quantum Machine Learning" diff --git a/demonstrations_v2/qnspsa/demo.py b/demonstrations_v2/qnspsa/demo.py index 87b42dd07e..fbec39013a 100644 --- a/demonstrations_v2/qnspsa/demo.py +++ b/demonstrations_v2/qnspsa/demo.py @@ -186,7 +186,7 @@ # initialize a graph for the max cut problem import networkx as nx -import pennylane as qml +import pennylane as qp from pennylane import qaoa nodes = n_qubits = 4 @@ -197,7 +197,7 @@ cost_h, mixer_h = qaoa.maxcut(g) depth = 2 # define device to be the PennyLane lightning local simulator -dev = qml.device("lightning.qubit", wires=n_qubits) +dev = qp.device("lightning.qubit", wires=n_qubits) def qaoa_layer(gamma, alpha): @@ -208,19 +208,19 @@ def qaoa_layer(gamma, alpha): def qaoa_circuit(params, n_qubits, depth): # initialize all qubits into +X eigenstate. for w in range(n_qubits): - qml.Hadamard(wires=w) + qp.Hadamard(wires=w) gammas = params[0] alphas = params[1] # stack building blocks for depth times. - qml.layer(qaoa_layer, depth, gammas, alphas) + qp.layer(qaoa_layer, depth, gammas, alphas) # define ansatz and loss function -@qml.set_shots(1000) -@qml.qnode(dev) +@qp.set_shots(1000) +@qp.qnode(dev) def cost_function(params): qaoa_circuit(params, n_qubits, depth) - return qml.expval(cost_h) + return qp.expval(cost_h) ###################################################################### @@ -356,14 +356,14 @@ def get_grad(params_curr): # def get_overlap_tape(qnode, params1, params2): - tape_forward = qml.workflow.construct_tape(qnode)(params1) - tape_inv = qml.workflow.construct_tape(qnode)(params2) + tape_forward = qp.workflow.construct_tape(qnode)(params1) + tape_inv = qp.workflow.construct_tape(qnode)(params2) - ops = tape_forward.operations + list(qml.adjoint(op) for op in reversed(tape_inv.operations)) - return qml.tape.QuantumTape(ops, [qml.probs(wires=tape_forward.wires)]) + ops = tape_forward.operations + list(qp.adjoint(op) for op in reversed(tape_inv.operations)) + return qp.tape.QuantumTape(ops, [qp.probs(wires=tape_forward.wires)]) def get_state_overlap(tape): - return qml.execute([tape], dev, None)[0][0] + return qp.execute([tape], dev, None)[0][0] ###################################################################### @@ -616,10 +616,10 @@ def get_next_params(params, gradient): # ``QNode.__call__()`` function (in this example, ``cost_function()``). In # a handwavy argument, each ``QNode.__call__()`` does the following two # things: (1) it constructs a tape with the given parameters, and (2) -# calls ``qml.execute()`` to execute the single tape. +# calls ``qp.execute()`` to execute the single tape. # # However, in this use case, the better practice is to group the tapes and -# call one ``qml.execute()`` on all the tapes. This practice utilizes the +# call one ``qp.execute()`` on all the tapes. This practice utilizes the # batch execution feature from PennyLane, and has a few potential # advantages. Some simulators provide parallelization support, so that the # grouped tapes can be executed simutaneously. As an example, utilizing @@ -635,7 +635,7 @@ def get_next_params(params, gradient): # import random -import pennylane as qml +import pennylane as qp from pennylane import numpy as np from scipy.linalg import sqrtm import warnings @@ -698,7 +698,7 @@ def step(self, cost, params): measurements are required for the updates for the case. Args: - cost (qml.QNode): the QNode wrapper for the objective function for + cost (qp.QNode): the QNode wrapper for the objective function for optimization params (np.array): Parameter before update. @@ -723,7 +723,7 @@ def step_and_cost(self, cost, params): the corresponding objective function value after the step. Args: - cost (qml.QNode): the QNode wrapper for the objective function for + cost (qp.QNode): the QNode wrapper for the objective function for optimization params (np.array): Parameter before update. @@ -750,7 +750,7 @@ def __step_core(self, cost, params): for i in range(self.resamplings): grad_tapes, grad_dir = self.__get_spsa_grad_tapes(cost, params) metric_tapes, tensor_dirs = self.__get_tensor_tapes(cost, params) - raw_results = qml.execute(grad_tapes + metric_tapes, cost.device, None) + raw_results = qp.execute(grad_tapes + metric_tapes, cost.device, None) grad = self.__post_process_grad(raw_results[:2], grad_dir) metric_tensor = self.__post_process_tensor(raw_results[2:], tensor_dirs) grad_avg = grad_avg * i / (i + 1) + grad / (i + 1) @@ -765,7 +765,7 @@ def __step_core_first_order(self, cost, params): grad_avg = np.zeros(params.shape) for i in range(self.resamplings): grad_tapes, grad_dir = self.__get_spsa_grad_tapes(cost, params) - raw_results = qml.execute(grad_tapes, cost.device, None) + raw_results = qp.execute(grad_tapes, cost.device, None) grad = self.__post_process_grad(raw_results, grad_dir) grad_avg = grad_avg * i / (i + 1) + grad / (i + 1) return params - self.stepsize * grad_avg @@ -818,8 +818,8 @@ def __get_spsa_grad_tapes(self, cost, params): # used to estimate the gradient per optimization step. The sampled # direction is of the shape of the input parameter. direction = self.__get_perturbation_direction(params) - tape_forward = qml.workflow.construct_tape(cost)(params + self.finite_diff_step * direction) - tape_backward = qml.workflow.construct_tape(cost)(params - self.finite_diff_step * direction) + tape_forward = qp.workflow.construct_tape(cost)(params + self.finite_diff_step * direction) + tape_backward = qp.workflow.construct_tape(cost)(params - self.finite_diff_step * direction) return [tape_forward, tape_backward], direction def __update_tensor(self, tensor_raw): @@ -862,10 +862,10 @@ def __regularize_tensor(self, metric_tensor): def __apply_blocking(self, cost, params_curr, params_next): # For numerical stability: apply the blocking condition on the parameter update. - tape_loss_curr = qml.workflow.construct_tape(cost)(params_curr) - tape_loss_next = qml.workflow.construct_tape(cost)(params_next) + tape_loss_curr = qp.workflow.construct_tape(cost)(params_curr) + tape_loss_next = qp.workflow.construct_tape(cost)(params_next) - loss_curr, loss_next = qml.execute([tape_loss_curr, tape_loss_next], cost.device, None) + loss_curr, loss_next = qp.execute([tape_loss_curr, tape_loss_next], cost.device, None) # self.k has been updated earlier. ind = (self.k - 2) % self.history_length self.last_n_steps[ind] = loss_curr diff --git a/demonstrations_v2/qnspsa/metadata.json b/demonstrations_v2/qnspsa/metadata.json index 63fb4a2256..3482191a3e 100644 --- a/demonstrations_v2/qnspsa/metadata.json +++ b/demonstrations_v2/qnspsa/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2022-07-18T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Optimization" ], diff --git a/demonstrations_v2/qonn/demo.py b/demonstrations_v2/qonn/demo.py index e3fc5fb572..355a3ec2ee 100644 --- a/demonstrations_v2/qonn/demo.py +++ b/demonstrations_v2/qonn/demo.py @@ -76,7 +76,7 @@ # gradient-based optimizers. # -import pennylane as qml +import pennylane as qp from pennylane import numpy as np import nlopt @@ -90,7 +90,7 @@ # lower cutoff value will cause loss of information, while a higher value # might use unnecessary resources without any improvement). -dev = qml.device("strawberryfields.fock", wires=4, cutoff_dim=4) +dev = qp.device("strawberryfields.fock", wires=4, cutoff_dim=4) ###################################################################### # @@ -119,12 +119,12 @@ def layer(theta, phi, wires): M = len(wires) phi_nonlinear = np.pi / 2 - qml.Interferometer( + qp.Interferometer( theta, phi, np.zeros(M), wires=wires, mesh="triangular", ) for i in wires: - qml.Kerr(phi_nonlinear, wires=i) + qp.Kerr(phi_nonlinear, wires=i) ###################################################################### @@ -134,19 +134,19 @@ def layer(theta, phi, wires): # a list of parameters ``theta`` and ``phi`` for a specific layer. # -@qml.qnode(dev) +@qp.qnode(dev) def quantum_neural_net(var, x): wires = list(range(len(x))) # Encode input x into a sequence of quantum fock states for i in wires: - qml.FockState(x[i], wires=i) + qp.FockState(x[i], wires=i) # "layer" subcircuits for i, v in enumerate(var): layer(v[: len(v) // 2], v[len(v) // 2 :], wires) - return [qml.expval(qml.NumberOperator(w)) for w in wires] + return [qp.expval(qp.NumberOperator(w)) for w in wires] ###################################################################### @@ -309,7 +309,7 @@ def cost(var, data_input, labels): # requirements of both NLopt and the above-defined cost function. # -cost_grad = qml.grad(cost) +cost_grad = qp.grad(cost) print_every = 1 @@ -446,7 +446,7 @@ def cost_wrapper(var, grad=[]): ############################################################################## # We can also print the circuit to see how the final network looks. -print(qml.draw(quantum_neural_net)(var_init, X[0])) +print(qp.draw(quantum_neural_net)(var_init, X[0])) ############################################################################## # .. rst-class:: sphx-glr-script-out diff --git a/demonstrations_v2/qonn/metadata.json b/demonstrations_v2/qonn/metadata.json index f536c7b945..5ba2fd4305 100644 --- a/demonstrations_v2/qonn/metadata.json +++ b/demonstrations_v2/qonn/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2020-08-05T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Optimization" ], diff --git a/demonstrations_v2/qrack/demo.py b/demonstrations_v2/qrack/demo.py index ec6588347f..ae0251aa38 100644 --- a/demonstrations_v2/qrack/demo.py +++ b/demonstrations_v2/qrack/demo.py @@ -94,7 +94,7 @@ initialization and perform the QFT across a width of 60 qubits, with Catalyst's `qjit `__. """ -import pennylane as qml +import pennylane as qp from pennylane import numpy as np from catalyst import qjit @@ -103,17 +103,17 @@ import random qubits = 60 -dev = qml.device("qrack.simulator", qubits) +dev = qp.device("qrack.simulator", qubits) @qjit -@qml.set_shots(8) -@qml.qnode(dev) +@qp.set_shots(8) +@qp.qnode(dev) def circuit(): for i in range(qubits): if random.uniform(0, 1) < 0.5: - qml.X(wires=[i]) - qml.QFT(wires=range(qubits)) - return qml.sample(wires=range(qubits)) + qp.X(wires=[i]) + qp.QFT(wires=range(qubits)) + return qp.sample(wires=range(qubits)) def counts_from_samples(samples): counts = {} @@ -160,19 +160,19 @@ def counts_from_samples(samples): # `GHZ state `__ initialization). qubits = 12 -dev = qml.device("qrack.simulator", qubits) +dev = qp.device("qrack.simulator", qubits) @qjit -@qml.set_shots(8) -@qml.qnode(dev) +@qp.set_shots(8) +@qp.qnode(dev) def circuit(): for i in range(qubits): th = random.uniform(0, np.pi) ph = random.uniform(0, np.pi) dl = random.uniform(0, np.pi) - qml.U3(th, ph, dl, wires=[i]) - qml.QFT(wires=range(qubits)) - return qml.sample(wires=range(qubits)) + qp.U3(th, ph, dl, wires=[i]) + qp.QFT(wires=range(qubits)) + return qp.sample(wires=range(qubits)) counts = counts_from_samples(circuit()) @@ -198,7 +198,7 @@ def circuit(): # To demonstrate this, we prepare a 60-qubit GHZ state, which would commonly be intractable in the case of state vector simulation. qubits = 60 -dev = qml.device( +dev = qp.device( "qrack.simulator", qubits, isBinaryDecisionTree=False, @@ -207,13 +207,13 @@ def circuit(): ) @qjit -@qml.set_shots(8) -@qml.qnode(dev) +@qp.set_shots(8) +@qp.qnode(dev) def circuit(): - qml.Hadamard(0) + qp.Hadamard(0) for i in range(1, qubits): - qml.CNOT(wires=[i - 1, i]) - return qml.sample(wires=range(qubits)) + qp.CNOT(wires=[i - 1, i]) + return qp.sample(wires=range(qubits)) counts = counts_from_samples(circuit()) @@ -242,18 +242,18 @@ def circuit(): # qubits = 24 -dev = qml.device( +dev = qp.device( "qrack.simulator", qubits, isBinaryDecisionTree=True, isStabilizerHybrid=False ) @qjit -@qml.set_shots(8) -@qml.qnode(dev) +@qp.set_shots(8) +@qp.qnode(dev) def circuit(): - qml.Hadamard(0) + qp.Hadamard(0) for i in range(1, qubits): - qml.CNOT(wires=[i - 1, i]) - return qml.sample(wires=range(qubits)) + qp.CNOT(wires=[i - 1, i]) + return qp.sample(wires=range(qubits)) counts = counts_from_samples(circuit()) @@ -296,19 +296,19 @@ def circuit(): def bench(n, results): for device in ["qrack.simulator", "lightning.qubit"]: - dev = qml.device(device, n) + dev = qp.device(device, n) @qjit - @qml.set_shots(1) - @qml.qnode(dev) + @qp.set_shots(1) + @qp.qnode(dev) def circuit(): for i in range(n): th = random.uniform(0, np.pi) ph = random.uniform(0, np.pi) dl = random.uniform(0, np.pi) - qml.U3(th, ph, dl, wires=[i]) - qml.QFT(wires=range(n)) - return qml.sample(wires=range(n)) + qp.U3(th, ph, dl, wires=[i]) + qp.QFT(wires=range(n)) + return qp.sample(wires=range(n)) start_ns = time.perf_counter_ns() circuit() @@ -348,34 +348,34 @@ def circuit(): # `Lightning `__. How does Qrack with QJIT compare to Qrack without it? def bench(n, results): - dev = qml.device("qrack.simulator", n) + dev = qp.device("qrack.simulator", n) @qjit - @qml.set_shots(1) - @qml.qnode(dev) + @qp.set_shots(1) + @qp.qnode(dev) def circuit(): for i in range(n): th = random.uniform(0, np.pi) ph = random.uniform(0, np.pi) dl = random.uniform(0, np.pi) - qml.U3(th, ph, dl, wires=[i]) - qml.QFT(wires=range(n)) - return qml.sample(wires=range(n)) + qp.U3(th, ph, dl, wires=[i]) + qp.QFT(wires=range(n)) + return qp.sample(wires=range(n)) start_ns = time.perf_counter_ns() circuit() results[f"QJIT Qrack ({n} qb)"] = time.perf_counter_ns() - start_ns - @qml.set_shots(1) - @qml.qnode(dev) + @qp.set_shots(1) + @qp.qnode(dev) def circuit(): for i in range(n): th = random.uniform(0, np.pi) ph = random.uniform(0, np.pi) dl = random.uniform(0, np.pi) - qml.U3(th, ph, dl, wires=[i]) - qml.QFT(wires=range(n)) - return qml.sample(wires=range(n)) + qp.U3(th, ph, dl, wires=[i]) + qp.QFT(wires=range(n)) + return qp.sample(wires=range(n)) start_ns = time.perf_counter_ns() circuit() @@ -414,16 +414,16 @@ def circuit(): def validate(n): results = [] for device in ["qrack.simulator", "lightning.qubit"]: - dev = qml.device(device, n) + dev = qp.device(device, n) @qjit - @qml.qnode(dev) + @qp.qnode(dev) def circuit(): - qml.Hadamard(0) + qp.Hadamard(0) for i in range(1, n): - qml.CNOT(wires=[i - 1, i]) - qml.QFT(wires=range(n)) - return qml.state() + qp.CNOT(wires=[i - 1, i]) + qp.QFT(wires=range(n)) + return qp.state() start_ns = time.perf_counter_ns() results.append(circuit()) diff --git a/demonstrations_v2/qrack/metadata.json b/demonstrations_v2/qrack/metadata.json index edb2f0114f..f772c0d4d7 100644 --- a/demonstrations_v2/qrack/metadata.json +++ b/demonstrations_v2/qrack/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2024-07-10T00:00:00+00:00", - "dateOfLastModification": "2025-12-10T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Compilation", "Devices and Performance" diff --git a/demonstrations_v2/qsim_beyond_classical/demo.py b/demonstrations_v2/qsim_beyond_classical/demo.py index 64dc876b5d..5abd466a1c 100644 --- a/demonstrations_v2/qsim_beyond_classical/demo.py +++ b/demonstrations_v2/qsim_beyond_classical/demo.py @@ -68,7 +68,7 @@ # Cirq. # -import pennylane as qml +import pennylane as qp from pennylane_cirq import ops import cirq @@ -124,7 +124,7 @@ # shots = 500000 -dev = qml.device('cirq.qsim', wires=wires, qubits=qubits) +dev = qp.device('cirq.qsim', wires=wires, qubits=qubits) ###################################################################### @@ -149,14 +149,14 @@ # The :math:`\sqrt{X}` gate is already implemented in PennyLane, while the # two other gates can be implemented as follows: -sqrtYgate = lambda wires: qml.RY(np.pi / 2, wires=wires) +sqrtYgate = lambda wires: qp.RY(np.pi / 2, wires=wires) -sqrtWgate = lambda wires: qml.QubitUnitary( +sqrtWgate = lambda wires: qp.QubitUnitary( np.array([[1, -np.sqrt(1j)], [np.sqrt(-1j), 1]]) / np.sqrt(2), wires=wires ) -single_qubit_gates = [qml.SX, sqrtYgate, sqrtWgate] +single_qubit_gates = [qp.SX, sqrtYgate, sqrtWgate] ###################################################################### @@ -301,8 +301,8 @@ def generate_single_qubit_gate_list(): # :math:`\left|0\right>` and :math:`\left|1\right>.` # -@qml.set_shots(shots) -@qml.qnode(dev) +@qp.set_shots(shots) +@qp.qnode(dev) def circuit(seed=42, return_probs=False): np.random.seed(seed) gate_idx = generate_single_qubit_gate_list() @@ -313,17 +313,17 @@ def circuit(seed=42, return_probs=False): single_qubit_gates[gate_idx[i][w]](wires=w) for qb_1, qb_2 in gate_order[gs]: - qml.ISWAP(wires=(qb_1, qb_2)) - qml.CPhase(-np.pi/6, wires=(qb_1, qb_2)) + qp.ISWAP(wires=(qb_1, qb_2)) + qp.CPhase(-np.pi/6, wires=(qb_1, qb_2)) # one half-cycle - single-qubit gates only for w in range(wires): single_qubit_gates[gate_idx[-1][w]](wires=w) if return_probs: - return qml.probs(wires=range(wires)) + return qp.probs(wires=range(wires)) else: - return qml.sample() + return qp.sample() ###################################################################### # The cross-entropy benchmarking fidelity diff --git a/demonstrations_v2/qsim_beyond_classical/metadata.json b/demonstrations_v2/qsim_beyond_classical/metadata.json index 2e0158ef35..692e8c85d0 100644 --- a/demonstrations_v2/qsim_beyond_classical/metadata.json +++ b/demonstrations_v2/qsim_beyond_classical/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2020-11-30T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Hardware", "Quantum Computing" diff --git a/demonstrations_v2/quantum_neural_net/demo.py b/demonstrations_v2/quantum_neural_net/demo.py index b90f66d2b6..b81dbba94c 100644 --- a/demonstrations_v2/quantum_neural_net/demo.py +++ b/demonstrations_v2/quantum_neural_net/demo.py @@ -35,7 +35,7 @@ and an optimizer. """ -import pennylane as qml +import pennylane as qp from pennylane import numpy as np from pennylane.optimize import AdamOptimizer @@ -44,7 +44,7 @@ # only one quantum mode (or ``wire``). You will need to have the # Strawberry Fields plugin for PennyLane installed. -dev = qml.device("strawberryfields.fock", wires=1, cutoff_dim=10) +dev = qp.device("strawberryfields.fock", wires=1, cutoff_dim=10) ############################################################################## # Quantum node @@ -56,15 +56,15 @@ def layer(v): # Matrix multiplication of input layer - qml.Rotation(v[0], wires=0) - qml.Squeezing(v[1], 0.0, wires=0) - qml.Rotation(v[2], wires=0) + qp.Rotation(v[0], wires=0) + qp.Squeezing(v[1], 0.0, wires=0) + qp.Rotation(v[2], wires=0) # Bias - qml.Displacement(v[3], 0.0, wires=0) + qp.Displacement(v[3], 0.0, wires=0) # Element-wise nonlinear transformation - qml.Kerr(v[4], wires=0) + qp.Kerr(v[4], wires=0) ############################################################################## @@ -73,16 +73,16 @@ def layer(v): # is the expectation of the x-quadrature. -@qml.qnode(dev) +@qp.qnode(dev) def quantum_neural_net(var, x): # Encode input x into quantum state - qml.Displacement(x, 0.0, wires=0) + qp.Displacement(x, 0.0, wires=0) # "layer" subcircuits for v in var: layer(v) - return qml.expval(qml.X(0)) + return qp.expval(qp.X(0)) ############################################################################## diff --git a/demonstrations_v2/quantum_neural_net/metadata.json b/demonstrations_v2/quantum_neural_net/metadata.json index 4c0f7d04bd..e4039d4c9f 100644 --- a/demonstrations_v2/quantum_neural_net/metadata.json +++ b/demonstrations_v2/quantum_neural_net/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2019-10-11T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning" ], diff --git a/demonstrations_v2/quantum_volume/demo.py b/demonstrations_v2/quantum_volume/demo.py index ac3d72f9aa..d25b607a57 100644 --- a/demonstrations_v2/quantum_volume/demo.py +++ b/demonstrations_v2/quantum_volume/demo.py @@ -329,7 +329,7 @@ # using numpy to generate a permutation, and then apply it with the built-in # :func:`~.pennylane.Permute` subroutine. -import pennylane as qml +import pennylane as qp # Object for random number generation from numpy rng = np.random.default_rng() @@ -337,7 +337,7 @@ def permute_qubits(num_qubits): # A random permutation perm_order = list(rng.permutation(num_qubits)) - qml.Permute(perm_order, wires=list(range(num_qubits))) + qp.Permute(perm_order, wires=list(range(num_qubits))) ############################################################################## @@ -353,7 +353,7 @@ def apply_random_su4_layer(num_qubits): for qubit_idx in range(0, num_qubits, 2): if qubit_idx < num_qubits - 1: rand_haar_su4 = unitary_group.rvs(4) - qml.QubitUnitary(rand_haar_su4, wires=[qubit_idx, qubit_idx + 1]) + qp.QubitUnitary(rand_haar_su4, wires=[qubit_idx, qubit_idx + 1]) ############################################################################## @@ -378,16 +378,16 @@ def qv_circuit_layer(num_qubits): # need to run the same random circuit on two devices independently. num_qubits = 5 -dev_ideal = qml.device("lightning.qubit", shots=None, wires=num_qubits) +dev_ideal = qp.device("lightning.qubit", shots=None, wires=num_qubits) m = 3 # number of qubits -with qml.tape.QuantumTape() as tape: +with qp.tape.QuantumTape() as tape: for _ in range(m): qv_circuit_layer(m) -(expanded_tape,), _ = qml.transforms.decompose(tape, gate_set={qml.QubitUnitary, qml.SWAP}) -print(qml.drawer.tape_text(expanded_tape, wire_order=dev_ideal.wires, show_all_wires=True, show_matrices=True)) +(expanded_tape,), _ = qp.transforms.decompose(tape, gate_set={qp.QubitUnitary, qp.SWAP}) +print(qp.drawer.tape_text(expanded_tape, wire_order=dev_ideal.wires, show_all_wires=True, show_matrices=True)) ############################################################################## @@ -485,10 +485,10 @@ def heavy_output_set(m, probs): # # Adds a measurement of the first m qubits to the previous circuit -tape = tape.copy(measurements=[qml.probs(wires=range(m))]) +tape = tape.copy(measurements=[qp.probs(wires=range(m))]) # Run the circuit, compute heavy outputs, and print results -[output_probs] = qml.execute([tape], dev_ideal) # returns a list of result ! +[output_probs] = qp.execute([tape], dev_ideal) # returns a list of result ! output_probs = output_probs.reshape(2**m) heavy_outputs, prob_heavy_output = heavy_output_set(m, output_probs) @@ -597,7 +597,7 @@ def heavy_output_set(m, probs): "routing_method": "sabre", } -dev_noisy = qml.device("qiskit.remote", wires=5, backend=FakeLimaV2(), **transpile_args) +dev_noisy = qp.device("qiskit.remote", wires=5, backend=FakeLimaV2(), **transpile_args) ############################################################################## @@ -621,20 +621,20 @@ def heavy_output_set(m, probs): for trial in range(num_trials): # Simulate the circuit analytically - with qml.tape.QuantumTape() as tape_probs: + with qp.tape.QuantumTape() as tape_probs: for _ in range(m): qv_circuit_layer(m) - qml.probs(wires=range(m)) + qp.probs(wires=range(m)) - # when using qml.execute, shots must be on the tape - tape_counts = tape_probs.copy(measurements=[qml.counts()], shots=1000) + # when using qp.execute, shots must be on the tape + tape_counts = tape_probs.copy(measurements=[qp.counts()], shots=1000) - output_probs = qml.execute([tape_probs], dev_ideal) + output_probs = qp.execute([tape_probs], dev_ideal) output_probs = output_probs[0].reshape(2**m) heavy_outputs, prob_heavy_output = heavy_output_set(m, output_probs) # Execute circuit on the noisy device - [counts] = qml.execute([tape_counts], dev_noisy) + [counts] = qp.execute([tape_counts], dev_noisy) device_heavy_outputs = np.sum( [counts[x] if x[:m] in heavy_outputs else 0 for x in counts.keys()] diff --git a/demonstrations_v2/quantum_volume/metadata.json b/demonstrations_v2/quantum_volume/metadata.json index d9d6ec377a..e15d0f552a 100644 --- a/demonstrations_v2/quantum_volume/metadata.json +++ b/demonstrations_v2/quantum_volume/metadata.json @@ -8,7 +8,7 @@ "executable_stable": false, "executable_latest": false, "dateOfPublication": "2020-12-15T00:00:00+00:00", - "dateOfLastModification": "2025-10-15T00:00:00+00:00", + "dateOfLastModification": "2026-04-14T00:00:00+00:00", "categories": [ "Quantum Hardware", "Quantum Computing" diff --git a/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py b/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py index 281173c352..3224ab4b4d 100644 --- a/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py +++ b/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py @@ -36,12 +36,12 @@ # # We demonstrate this with a :math:`25 \times 25` honeycomb lattice of spins. # Here, we generate the Hamiltonian ourselves, using the -# :func:`qml.spin.kitaev ` function, +# :func:`qp.spin.kitaev ` function, # and group the Hamiltonian terms into qubit-wise # commuting groups: # -import pennylane as qml +import pennylane as qp import numpy as np import time @@ -49,15 +49,15 @@ kx, ky, kz = (0.5, 0.6, 0.7) t1 = time.time() -flat_hamiltonian = qml.spin.kitaev(n_cells, coupling=np.array([kx, ky, kz])) +flat_hamiltonian = qp.spin.kitaev(n_cells, coupling=np.array([kx, ky, kz])) flat_hamiltonian.compute_grouping() # compute the qubit-wise commuting groups! groups = [] for group_indices in flat_hamiltonian.grouping_indices: - grouped_term = qml.sum(*(flat_hamiltonian.operands[index] for index in group_indices)) + grouped_term = qp.sum(*(flat_hamiltonian.operands[index] for index in group_indices)) groups.append(grouped_term) -grouped_hamiltonian = qml.sum(*groups) +grouped_hamiltonian = qp.sum(*groups) t2 = time.time() t_generation = t2 - t1 @@ -68,12 +68,12 @@ num_steps = 10 order = 6 -@qml.qnode(qml.device("default.qubit")) +@qp.qnode(qp.device("default.qubit")) def executable_circuit(hamiltonian, num_steps, order): for wire in hamiltonian.wires: # uniform superposition over all basis states - qml.Hadamard(wire) - qml.TrotterProduct(hamiltonian, time=1.0, n=num_steps, order=order) - return qml.state() + qp.Hadamard(wire) + qp.TrotterProduct(hamiltonian, time=1.0, n=num_steps, order=order) + return qp.state() ###################################################################### # Now, let’s import our quantum resource :mod:`estimator `. diff --git a/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/metadata.json b/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/metadata.json index bd80f53787..2476e6e234 100644 --- a/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/metadata.json +++ b/demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/metadata.json @@ -11,7 +11,7 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2026-01-13T10:00:00+00:00", - "dateOfLastModification": "2026-02-24T10:00:00+00:01", + "dateOfLastModification": "2026-04-14T10:00:00+00:01", "categories": [ "Algorithms", "How-to", diff --git a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/demo.py b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/demo.py index 975e5dd03a..608ac0fba4 100644 --- a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/demo.py +++ b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/demo.py @@ -30,7 +30,7 @@ # target predictions given by ``target``. # -import pennylane as qml +import pennylane as qp import jax from jax import numpy as jnp import jaxopt @@ -41,9 +41,9 @@ data = jnp.sin(jnp.mgrid[-2:2:0.2].reshape(n_wires, -1)) ** 3 targets = jnp.array([-0.2, 0.4, 0.35, 0.2]) -dev = qml.device("default.qubit", wires=n_wires) +dev = qp.device("default.qubit", wires=n_wires) -@qml.qnode(dev) +@qp.qnode(dev) def circuit(data, weights): """Quantum circuit ansatz""" @@ -51,18 +51,18 @@ def circuit(data, weights): for i in range(n_wires): # data[i] will be of shape (4,); we are # taking advantage of operation vectorization here - qml.RY(data[i], wires=i) + qp.RY(data[i], wires=i) # trainable ansatz for i in range(n_wires): - qml.RX(weights[i, 0], wires=i) - qml.RY(weights[i, 1], wires=i) - qml.RX(weights[i, 2], wires=i) - qml.CNOT(wires=[i, (i + 1) % n_wires]) + qp.RX(weights[i, 0], wires=i) + qp.RY(weights[i, 1], wires=i) + qp.RX(weights[i, 2], wires=i) + qp.CNOT(wires=[i, (i + 1) % n_wires]) # we use a sum of local Z's as an observable since a # local Z would only be affected by params on that qubit. - return qml.expval(qml.sum(*[qml.PauliZ(i) for i in range(n_wires)])) + return qp.expval(qp.sum(*[qp.PauliZ(i) for i in range(n_wires)])) def my_model(data, weights, bias): return circuit(data, weights) + bias diff --git a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/metadata.json b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/metadata.json index 4fef5d309d..cc61f72d6b 100644 --- a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/metadata.json +++ b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_JAXopt/metadata.json @@ -11,7 +11,7 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2024-01-18T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning", "Optimization", diff --git a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/demo.py b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/demo.py index 19c1b684cd..d15b8d4974 100644 --- a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/demo.py +++ b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/demo.py @@ -31,7 +31,7 @@ # target predictions given by ``target``. # -import pennylane as qml +import pennylane as qp import jax from jax import numpy as jnp import optax @@ -40,9 +40,9 @@ data = jnp.sin(jnp.mgrid[-2:2:0.2].reshape(n_wires, -1)) ** 3 targets = jnp.array([-0.2, 0.4, 0.35, 0.2]) -dev = qml.device("default.qubit", wires=n_wires) +dev = qp.device("default.qubit", wires=n_wires) -@qml.qnode(dev) +@qp.qnode(dev) def circuit(data, weights): """Quantum circuit ansatz""" @@ -50,18 +50,18 @@ def circuit(data, weights): for i in range(n_wires): # data[i] will be of shape (4,); we are # taking advantage of operation vectorization here - qml.RY(data[i], wires=i) + qp.RY(data[i], wires=i) # trainable ansatz for i in range(n_wires): - qml.RX(weights[i, 0], wires=i) - qml.RY(weights[i, 1], wires=i) - qml.RX(weights[i, 2], wires=i) - qml.CNOT(wires=[i, (i + 1) % n_wires]) + qp.RX(weights[i, 0], wires=i) + qp.RY(weights[i, 1], wires=i) + qp.RX(weights[i, 2], wires=i) + qp.CNOT(wires=[i, (i + 1) % n_wires]) # we use a sum of local Z's as an observable since a # local Z would only be affected by params on that qubit. - return qml.expval(qml.sum(*[qml.PauliZ(i) for i in range(n_wires)])) + return qp.expval(qp.sum(*[qp.PauliZ(i) for i in range(n_wires)])) def my_model(data, weights, bias): return circuit(data, weights) + bias diff --git a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/metadata.json b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/metadata.json index 9d83d33705..0c361693ab 100644 --- a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/metadata.json +++ b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_and_Optax/metadata.json @@ -11,7 +11,7 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2024-01-18T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning", "Optimization", diff --git a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/demo.py b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/demo.py index e5e984cdb4..7ac0d50f08 100644 --- a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/demo.py +++ b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/demo.py @@ -30,7 +30,7 @@ target predictions given by ``target``. """ -import pennylane as qml +import pennylane as qp from jax import numpy as jnp import optax import catalyst @@ -39,37 +39,37 @@ data = jnp.sin(jnp.mgrid[-2:2:0.2].reshape(n_wires, -1)) ** 3 targets = jnp.array([-0.2, 0.4, 0.35, 0.2]) -dev = qml.device("lightning.qubit", wires=n_wires) +dev = qp.device("lightning.qubit", wires=n_wires) -@qml.qnode(dev) +@qp.qnode(dev) def circuit(data, weights): """Quantum circuit ansatz""" - @qml.for_loop(0, n_wires, 1) + @qp.for_loop(0, n_wires, 1) def data_embedding(i): - qml.RY(data[i], wires=i) + qp.RY(data[i], wires=i) data_embedding() - @qml.for_loop(0, n_wires, 1) + @qp.for_loop(0, n_wires, 1) def ansatz(i): - qml.RX(weights[i, 0], wires=i) - qml.RY(weights[i, 1], wires=i) - qml.RX(weights[i, 2], wires=i) - qml.CNOT(wires=[i, (i + 1) % n_wires]) + qp.RX(weights[i, 0], wires=i) + qp.RY(weights[i, 1], wires=i) + qp.RX(weights[i, 2], wires=i) + qp.CNOT(wires=[i, (i + 1) % n_wires]) ansatz() # we use a sum of local Z's as an observable since a # local Z would only be affected by params on that qubit. - return qml.expval(qml.sum(*[qml.PauliZ(i) for i in range(n_wires)])) + return qp.expval(qp.sum(*[qp.PauliZ(i) for i in range(n_wires)])) ###################################################################### # The :func:`catalyst.vmap` function allows us to specify that the first argument to circuit (``data``) # contains a batch dimension. In this example, the batch dimension is the second axis (axis 1). # -circuit = qml.qjit(catalyst.vmap(circuit, in_axes=(1, None))) +circuit = qp.qjit(catalyst.vmap(circuit, in_axes=(1, None))) ###################################################################### # We will define a simple cost function that computes the overlap between model output and target @@ -79,7 +79,7 @@ def ansatz(i): def my_model(data, weights, bias): return circuit(data, weights) + bias -@qml.qjit +@qp.qjit def loss_fn(params, data, targets): predictions = my_model(data, params["weights"], params["bias"]) loss = jnp.sum((targets - predictions) ** 2 / len(data)) @@ -110,7 +110,7 @@ def loss_fn(params, data, targets): loss_fn(params, data, targets) -print(qml.qjit(catalyst.grad(loss_fn, method="fd"))(params, data, targets)) +print(qp.qjit(catalyst.grad(loss_fn, method="fd"))(params, data, targets)) ###################################################################### # Create the optimizer @@ -130,7 +130,7 @@ def loss_fn(params, data, targets): opt = optax.adam(learning_rate=0.3) -@qml.qjit +@qp.qjit def update_step(i, args): params, opt_state, data, targets = args @@ -165,11 +165,11 @@ def update_step(i, args): params = {"weights": weights, "bias": bias} -@qml.qjit +@qp.qjit def optimization(params, data, targets): opt_state = opt.init(params) args = (params, opt_state, data, targets) - (params, opt_state, _, _) = qml.for_loop(0, 100, 1)(update_step)(args) + (params, opt_state, _, _) = qp.for_loop(0, 100, 1)(update_step)(args) return params ###################################################################### diff --git a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/metadata.json b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/metadata.json index 496e9e53df..ac41e8da56 100644 --- a/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/metadata.json +++ b/demonstrations_v2/tutorial_How_to_optimize_QML_model_using_JAX_catalyst_and_Optax/metadata.json @@ -8,7 +8,7 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2024-04-26T00:00:00+00:00", - "dateOfLastModification": "2025-12-10T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ "Quantum Machine Learning", "Optimization", diff --git a/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/demo.py b/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/demo.py index 9d485e3b4e..7c17f241e3 100644 --- a/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/demo.py +++ b/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/demo.py @@ -51,7 +51,7 @@ # The number of gates increases with the number of qubits. # -import pennylane as qml +import pennylane as qp import numpy as np # Define the keyword arguments for the MPS method @@ -69,20 +69,20 @@ phi = 0.1 # Instantiate the device with the MPS method and the specified kwargs -dev = qml.device("default.tensor", method="mps", **kwargs_mps) +dev = qp.device("default.tensor", method="mps", **kwargs_mps) # Define the quantum circuit -@qml.qnode(dev) +@qp.qnode(dev) def circuit(theta, phi, num_qubits): for qubit in range(num_qubits - 4): - qml.RX(theta, wires=qubit + 1) - qml.CNOT(wires=[qubit, qubit + 1]) - qml.RY(phi, wires=qubit + 1) - qml.DoubleExcitation(theta, wires=[qubit, qubit + 1, qubit + 3, qubit + 4]) - qml.Toffoli(wires=[qubit + 1, qubit + 3, qubit + 4]) - return qml.expval( - qml.X(num_qubits - 1) @ qml.Y(num_qubits - 2) @ qml.Z(num_qubits - 3) + qp.RX(theta, wires=qubit + 1) + qp.CNOT(wires=[qubit, qubit + 1]) + qp.RY(phi, wires=qubit + 1) + qp.DoubleExcitation(theta, wires=[qubit, qubit + 1, qubit + 3, qubit + 4]) + qp.Toffoli(wires=[qubit + 1, qubit + 3, qubit + 4]) + return qp.expval( + qp.X(num_qubits - 1) @ qp.Y(num_qubits - 2) @ qp.Z(num_qubits - 3) ) @@ -136,7 +136,7 @@ def circuit(theta, phi, num_qubits): # As in the previous circuit, the number of gates increases with the number of qubits. # -import pennylane as qml +import pennylane as qp import numpy as np # Define the keyword arguments for the TN method @@ -155,23 +155,23 @@ def circuit(theta, phi, num_qubits): depth = 10 # Instantiate the device with the TN method and the specified kwargs -dev = qml.device("default.tensor", method="tn", **kwargs_tn) +dev = qp.device("default.tensor", method="tn", **kwargs_tn) -@qml.qnode(dev) +@qp.qnode(dev) def circuit(theta, depth, num_qubits): for i in range(num_qubits): - qml.X(wires=i) + qp.X(wires=i) for _ in range(1, depth - 1): for i in range(0, num_qubits, 2): - qml.CNOT(wires=[i, i + 1]) + qp.CNOT(wires=[i, i + 1]) for i in range(num_qubits % 5): - qml.RZ(theta, wires=i) + qp.RZ(theta, wires=i) for i in range(1, num_qubits - 1, 2): - qml.CZ(wires=[i, i + 1]) + qp.CZ(wires=[i, i + 1]) for i in range(num_qubits): - qml.CNOT(wires=[i, (i + 1)]) - return qml.var(qml.X(num_qubits - 1)) + qp.CNOT(wires=[i, (i + 1)]) + return qp.var(qp.X(num_qubits - 1)) # Simulate the circuit for different numbers of qubits diff --git a/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/metadata.json b/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/metadata.json index 5578581f7a..1a774ecd6f 100644 --- a/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/metadata.json +++ b/demonstrations_v2/tutorial_How_to_simulate_quantum_circuits_with_tensor_networks/metadata.json @@ -8,9 +8,8 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2024-07-09T00:00:00+00:00", - "dateOfLastModification": "2026-01-14T15:48:14+00:00", + "dateOfLastModification": "2026-04-14T15:48:14+00:00", "categories": [ - "Getting Started", "Quantum Computing", "Devices and Performance", "How-to" @@ -50,4 +49,4 @@ "weight": 1.0 } ] -} \ No newline at end of file +} diff --git a/demonstrations_v2/tutorial_adjoint_diff/demo.py b/demonstrations_v2/tutorial_adjoint_diff/demo.py index a95a269490..e1296dd5a2 100644 --- a/demonstrations_v2/tutorial_adjoint_diff/demo.py +++ b/demonstrations_v2/tutorial_adjoint_diff/demo.py @@ -69,7 +69,7 @@ # # To start, we import PennyLane and Jax's numpy: -import pennylane as qml +import pennylane as qp import pennylane.numpy as pnp @@ -77,17 +77,17 @@ # We also need a circuit to simulate: # -dev = qml.device("default.qubit", wires=2) +dev = qp.device("default.qubit", wires=2) x = pnp.array([0.1, 0.2, 0.3], requires_grad=True) -@qml.qnode(dev, diff_method="adjoint") +@qp.qnode(dev, diff_method="adjoint") def circuit(a): - qml.RX(a[0], wires=0) - qml.CNOT(wires=(0, 1)) - qml.RY(a[1], wires=1) - qml.RZ(a[2], wires=1) - return qml.expval(qml.PauliX(wires=1)) + qp.RX(a[0], wires=0) + qp.CNOT(wires=(0, 1)) + qp.RY(a[1], wires=1) + qp.RZ(a[2], wires=1) + return qp.expval(qp.PauliX(wires=1)) ############################################################################## # The fast c++ simulator device ``"lightning.qubit"`` also supports adjoint differentiation, @@ -102,19 +102,19 @@ def circuit(a): n_params = 3 ops = [ - qml.RX(x[0], wires=0), - qml.CNOT(wires=(0, 1)), - qml.RY(x[1], wires=1), - qml.RZ(x[2], wires=1), + qp.RX(x[0], wires=0), + qp.CNOT(wires=(0, 1)), + qp.RY(x[1], wires=1), + qp.RZ(x[2], wires=1), ] -M = qml.PauliX(wires=1) +M = qp.PauliX(wires=1) ############################################################################## # We will be using internal functions to manipulate the nuts and bolts of a statevector # simulation. # # Internally, the statevector simulation uses a 2x2x2x... array to represent the state, whereas -# the result of a measurement ``qml.state()`` flattens this internal representation. Each dimension +# the result of a measurement ``qp.state()`` flattens this internal representation. Each dimension # in the statevector corresponds to a different qubit. # # The internal functions ``create_initial_state`` and ``apply_operation`` @@ -181,7 +181,7 @@ def circuit(a): for op in ops: bra_n = apply_operation(op, bra_n) bra_n = apply_operation(M, bra_n) -bra_n = apply_operation(qml.adjoint(ops[-1]), bra_n) +bra_n = apply_operation(qp.adjoint(ops[-1]), bra_n) ket_n = create_initial_state((0, 1)) @@ -218,7 +218,7 @@ def circuit(a): bra_n_v2 = apply_operation(M, state) ket_n_v2 = state -adj_op = qml.adjoint(ops[-1]) +adj_op = qp.adjoint(ops[-1]) bra_n_v2 = apply_operation(adj_op, bra_n_v2) ket_n_v2 = apply_operation(adj_op, ket_n_v2) @@ -249,7 +249,7 @@ def circuit(a): ket_loop = state for op in reversed(ops): - adj_op = qml.adjoint(op) + adj_op = qp.adjoint(op) bra_loop = apply_operation(adj_op, bra_loop) ket_loop = apply_operation(adj_op, ket_loop) print(pnp.vdot(bra_loop, ket_loop)) @@ -341,7 +341,7 @@ def circuit(a): # # Luckily, PennyLane already has a built-in function for calculating this. -grad_op0 = qml.operation.operation_derivative(ops[0]) +grad_op0 = qp.operation.operation_derivative(ops[0]) print(grad_op0) ############################################################################## @@ -358,13 +358,13 @@ def circuit(a): grads = [] for op in reversed(ops): - adj_op = qml.adjoint(op) + adj_op = qp.adjoint(op) ket = apply_operation(adj_op, ket) # Calculating the derivative if op.num_params != 0: - dU = qml.operation.operation_derivative(op) - ket_temp = apply_operation(qml.QubitUnitary(dU, op.wires), ket) + dU = qp.operation.operation_derivative(op) + ket_temp = apply_operation(qp.QubitUnitary(dU, op.wires), ket) dM = 2 * pnp.real(pnp.vdot(bra, ket_temp)) grads.append(dM) @@ -378,7 +378,7 @@ def circuit(a): print("our calculation: ", [float(grad) for grad in grads]) -grad_compare = qml.grad(circuit)(x) +grad_compare = qp.grad(circuit)(x) print("comparison: ", grad_compare) ############################################################################## @@ -389,17 +389,17 @@ def circuit(a): # ``"default.qubit"`` or PennyLane's fast C++ simulator ``"lightning.qubit"``. -dev_lightning = qml.device("lightning.qubit", wires=2) +dev_lightning = qp.device("lightning.qubit", wires=2) -@qml.qnode(dev_lightning, diff_method="adjoint") +@qp.qnode(dev_lightning, diff_method="adjoint") def circuit_adjoint(a): - qml.RX(a[0], wires=0) - qml.CNOT(wires=(0, 1)) - qml.RY(a[1], wires=1) - qml.RZ(a[2], wires=1) - return qml.expval(M) + qp.RX(a[0], wires=0) + qp.CNOT(wires=(0, 1)) + qp.RY(a[1], wires=1) + qp.RZ(a[2], wires=1) + return qp.expval(M) -print(qml.grad(circuit_adjoint)(x)) +print(qp.grad(circuit_adjoint)(x)) ############################################################################## # Performance diff --git a/demonstrations_v2/tutorial_adjoint_diff/metadata.json b/demonstrations_v2/tutorial_adjoint_diff/metadata.json index 93c4194c2e..d362e2a578 100644 --- a/demonstrations_v2/tutorial_adjoint_diff/metadata.json +++ b/demonstrations_v2/tutorial_adjoint_diff/metadata.json @@ -8,9 +8,9 @@ "executable_stable": true, "executable_latest": true, "dateOfPublication": "2021-11-23T00:00:00+00:00", - "dateOfLastModification": "2025-09-22T15:48:14+00:00", + "dateOfLastModification": "2026-04-10T15:48:14+00:00", "categories": [ - "Getting Started" + "Quantum Machine Learning" ], "tags": [], "previewImages": [ @@ -67,4 +67,4 @@ "weight": 1.0 } ] -} \ No newline at end of file +}