Skip to content

Commit

Permalink
Merge dev into master (#1302)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Nightly Merge Action <[email protected]>
Co-authored-by: Andrija Paurevic <[email protected]>
Co-authored-by: Yushao Chen (Jerry) <[email protected]>
Co-authored-by: Soran Jahangiri <[email protected]>
Co-authored-by: Guillermo Alonso-Linaje <[email protected]>
Co-authored-by: Austin Huang <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Mikhail Andrenkov <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: Korbinian Kottmann <[email protected]>
Co-authored-by: Ivana Kurečić <[email protected]>
Co-authored-by: Paul Finlay <[email protected]>
Co-authored-by: Jack Brown <[email protected]>
Co-authored-by: bellekaplan <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: obliviateandsurrender <[email protected]>
Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Alex Preciado <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Astral Cai <[email protected]>
  • Loading branch information
1 parent d135e0c commit 5f3c0ef
Show file tree
Hide file tree
Showing 89 changed files with 917 additions and 762 deletions.
3 changes: 0 additions & 3 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@

# Raise PennyLane deprecation warnings as errors
warnings.filterwarnings("error", category=PennyLaneDeprecationWarning)
warnings.filterwarnings(
"ignore", message="Device will no longer be accessible", category=PennyLaneDeprecationWarning
)

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/ensemble_multi_qpu.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2020-02-14T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"dateOfLastModification": "2025-01-14T00:00:00+00:00",
"categories": [
"Quantum Machine Learning"
],
Expand Down
16 changes: 8 additions & 8 deletions demonstrations/ensemble_multi_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
classification problem.
.. warning::
This demo does not work with the latest version of Qiskit or the Pennylane-Qiskit plugin.
It is compatible with ``qiskit==0.46`` and ``pennylane-qiskit==0.35.1``. Older versions of
Qiskit and the Pennylane-Qiskit plugin should not be installed in environments with an
existing installation of Qiskit 1.0 or above.
This demo does not work with the latest version of Qiskit or the Pennylane-Qiskit plugin and
is compatible with Python versions 3.10 and lower. It is compatible with ``qiskit==0.46`` and
``pennylane-qiskit==0.35.1``. Older versions of Qiskit and the Pennylane-Qiskit plugin should
not be installed in environments with an existing installation of Qiskit 1.0 or above.
We use the ``rigetti.qvm`` device to simulate one QPU and the ``qiskit.aer`` device to
simulate another. Each QPU makes an independent prediction, and an ensemble model is
Expand Down Expand Up @@ -198,9 +198,9 @@ def plot_points(x_train, y_train, x_test, y_test):
##############################################################################
# .. note::
# If you have access to Rigetti hardware, you can swap out ``rigetti.qvm`` for ``rigetti.qpu``
# and specify the hardware device to run on. Users with access to the IBM Q Experience can
# swap ``qiskit.aer`` for ``qiskit.ibmq`` and specify their chosen backend (see `here
# <https://docs.pennylane.ai/projects/qiskit/en/latest/devices/ibmq.html>`__).
# and specify the hardware device to run on. Users with access to the IBM hardware can
# swap ``qiskit.aer`` for ``qiskit.remote`` and specify their chosen backend (see `here
# <https://docs.pennylane.ai/projects/qiskit/en/latest/devices/remote.html>`__).
#
#
# The circuits for both QPUs are shown in the figure below:
Expand Down Expand Up @@ -578,4 +578,4 @@ def plot_points_prediction(x, y, p, title):
##############################################################################
# About the author
# ----------------
# .. include:: ../_static/authors/thomas_bromley.txt
# .. include:: ../_static/authors/thomas_bromley.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2023-10-16T00:00:00+00:00",
"dateOfLastModification": "2024-11-06T00:00:00+00:00",
"dateOfLastModification": "2025-01-14T00:00:00+00:00",
"categories": [
"Devices and Performance"
],
Expand Down
4 changes: 4 additions & 0 deletions demonstrations/getting_started_with_hybrid_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ def circuit(params):
# .. note::
# AWS devices must be declared within the body of the decorated function.
#
# .. warning::
# The Rigetti device used in this demo, AspenM3, has been retired. For an updated list of available hardware through
# Amazon Braket, please consult the `supported regions and devices documentation <https://docs.aws.amazon.com/braket/latest/developerguide/braket-devices.html>`__. The general steps outlined below still hold regardless of the choice of device, though.
#

from braket.devices import Devices

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2024-07-02T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"dateOfLastModification": "2025-01-08T00:00:00+00:00",
"categories": [
"Quantum Computing",
"How-to"
Expand Down
10 changes: 7 additions & 3 deletions demonstrations/how_to_use_qiskit1_with_pennylane.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def qiskit_GHZ_circuit(n):
#

pl_circuit = qml.QNode(pl_qfunc, device=qml.device("lightning.qubit", wires=n))
pl_circuit()
print(pl_circuit())

######################################################################
# .. rst-class:: sphx-glr-script-out
Expand All @@ -263,7 +263,7 @@ def qiskit_GHZ_circuit(n):
pl_qfunc = qml.from_qiskit(qc, measurements=measurements)

pl_circuit = qml.QNode(pl_qfunc, device=qml.device("default.qubit", wires=n))
pl_circuit(shots=5)
print(pl_circuit(shots=5))

######################################################################
# .. rst-class:: sphx-glr-script-out
Expand Down Expand Up @@ -304,6 +304,7 @@ def qiskit_GHZ_circuit(n):
#

from qiskit.circuit import ParameterVector, Parameter
from matplotlib import pyplot as plt

n = 3

Expand All @@ -316,6 +317,8 @@ def qiskit_GHZ_circuit(n):
qc.ry(angle2, [2])

qc.draw("mpl")
plt.show()


######################################################################
# .. rst-class:: image-no-text-wrap
Expand Down Expand Up @@ -349,7 +352,8 @@ def differentiable_circuit(phis, theta):
theta = np.array([0.19])

print(differentiable_circuit(phis, theta))
print(qml.draw_mpl(differentiable_circuit)(phis, theta))
qml.draw_mpl(differentiable_circuit, style="pennylane")(phis, theta)
plt.show()

######################################################################
# .. rst-class:: sphx-glr-script-out
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/ibm_pennylane.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"dateOfPublication": "2023-06-20T00:00:00+00:00",
"dateOfLastModification": "2024-11-06T00:00:00+00:00",
"dateOfLastModification": "2025-01-10T00:00:00+00:00",
"categories": [
"Devices and Performance"
],
Expand Down
21 changes: 17 additions & 4 deletions demonstrations/ibm_pennylane.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@
#
# First, we set up our problem as usual, and then retrieve a program ID from IBM, which gives us a
# place to upload our job:
#
# .. warning::
#
# By default, this demo uses the online simulator (`ibmq_qasm_simulator`), which is free at the
# time of writing. Please note that IBM Quantum's policies may change, and simulators could become paid services.
# Always verify current pricing and access policies on the IBM Quantum platform.
#
# This demo can also run on quantum hardware by updating the backend variable accordingly. Be aware, that access
# to IBM Quantum hardware is not free and may result in substantial costs. Ensure you are aware of these costs
# and comfortable with them before proceeding.

from pennylane import numpy as pnp
from qiskit_ibm_runtime import QiskitRuntimeService
Expand All @@ -135,13 +145,16 @@
H = dataset.hamiltonian
qubits = 4

# Initialize QiskitRuntimeService
service = QiskitRuntimeService()
# Gets a 127 qubit device from IBM
backend = service.least_busy(n_qubits=127, simulator=False, operational=True)

# Use the `ibmq_qasm_simulator` available on IBM Cloud
backend = service.backend("ibmq_qasm_simulator")

try:
# Although we only need 4 qubits, our device has 127 qubits, therefore we initialize with wires=127
dev = qml.device("qiskit.remote", wires=127, backend=backend)
# Our device supports a maximum of 31 qubits
NUM_QUBITS_SUPPORTED = 31
dev = qml.device("qiskit.remote", wires=NUM_QUBITS_SUPPORTED, backend=backend)
except Exception as e:
print(e)

Expand Down
2 changes: 1 addition & 1 deletion demonstrations/learning2learn.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2021-03-02T00:00:00+00:00",
"dateOfLastModification": "2024-11-06T00:00:00+00:00",
"dateOfLastModification": "2025-01-07T00:00:00+00:00",
"categories": [
"Quantum Machine Learning"
],
Expand Down
3 changes: 3 additions & 0 deletions demonstrations/learning2learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*Author: Stefano Mangini — Posted: 02 March 2021. Last updated: 15 September 2021.*
.. warning::
This demo is only compatible with TensorFlow version ``2.9`` or below.
Otherwise, the output of some cells and plots may differ.
In this demo we recreate the architecture proposed
in *Learning to learn with quantum neural networks via
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/ml_classical_shadows.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2022-05-02T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"dateOfLastModification": "2025-01-10T00:00:00+00:00",
"categories": [
"Quantum Machine Learning"
],
Expand Down
5 changes: 2 additions & 3 deletions demonstrations/ml_classical_shadows.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ def estimate_shadow_obs(shadow, observable, k=10):
target_obs = np.array([map_name_to_int[observable.name]])
target_locs = np.array([observable.wires[0]])
else:
target_obs = np.array([map_name_to_int[o.name] for o in observable.obs])
target_locs = np.array([o.wires[0] for o in observable.obs])
target_obs = np.array([map_name_to_int[o.name] for o in observable.operands])
target_locs = np.array([o.wires[0] for o in observable.operands])

# perform median of means to return the result
means = []
Expand Down Expand Up @@ -859,4 +859,3 @@ def fit_predict_data(cij, kernel, opt="linear"):
#
# About the author
# ----------------

2 changes: 1 addition & 1 deletion demonstrations/oqc_pulse.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2023-10-30T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"dateOfLastModification": "2025-01-14T00:00:00+00:00",
"categories": [
"Quantum Computing"
],
Expand Down
4 changes: 4 additions & 0 deletions demonstrations/oqc_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*Author: Korbinian Kottmann — Posted: 30 October 2023.*
.. warning::
The OQC Lucy device is no longer available on Amazon Braket. As there is no alternative at this time, this
demo is now intended for educational purposes only.
Pulse-level access to quantum computers offers many interesting new avenues in
quantum optimal control, variational quantum algorithms and device-aware algorithm design.
We now have the possibility to run hardware-level circuits combined with standard gates on a
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/pytorch_noise.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2019-10-11T00:00:00+00:00",
"dateOfLastModification": "2024-10-07T00:00:00+00:00",
"dateOfLastModification": "2025-01-14T00:00:00+00:00",
"categories": [
"Devices and Performance"
],
Expand Down
6 changes: 5 additions & 1 deletion demonstrations/pytorch_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*Author: Josh Izaac — Posted: 11 October 2019. Last updated: 9 November 2022.*
.. warning::
This demo is only compatible with PennyLane v0.40 or below and Braket v1.31.0. To use Rigetti hardware with newer versions of PennyLane please use the `PennyLane-Braket plugin <https://amazon-braket-pennylane-plugin-python.readthedocs.io/en/stable/index.html>`__ instead.
Let's revisit the original :ref:`qubit rotation <qubit_rotation>` tutorial, but instead of
using the default NumPy/autograd QNode interface, we'll use the :doc:`introduction/interfaces/torch`.
We'll also replace the ``default.qubit`` device with a noisy ``rigetti.qvm``
Expand Down Expand Up @@ -251,4 +255,4 @@ def cost(phi, theta, step):
#
# About the author
# ----------------
# .. include:: ../_static/authors/josh_izaac.txt
# .. include:: ../_static/authors/josh_izaac.txt
2 changes: 1 addition & 1 deletion demonstrations/qnspsa.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2022-07-18T00:00:00+00:00",
"dateOfLastModification": "2024-11-06T00:00:00+00:00",
"dateOfLastModification": "2025-01-09T00:00:00+00:00",
"categories": [
"Optimization"
],
Expand Down
63 changes: 17 additions & 46 deletions demonstrations/qnspsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,12 @@ def get_grad(params_curr):
# 0 (minimum overlap) and 1 (perfect overlap).
#

from copy import copy


def get_operations(qnode, params):
qnode.construct([params], {})
return qnode.tape.operations


def get_overlap_tape(qnode, params1, params2):
op_forward = get_operations(qnode, params1)
op_inv = get_operations(qnode, params2)

with qml.tape.QuantumTape() as tape:
for op in op_forward:
qml.apply(op)
for op in reversed(op_inv):
qml.adjoint(copy(op))
qml.probs(wires=qnode.tape.wires.labels)
return tape
tape_forward = qml.workflow.construct_tape(qnode)(*params1)
tape_inv = qml.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)])

def get_state_overlap(tape):
return qml.execute([tape], dev, None)[0][0]
Expand Down Expand Up @@ -833,10 +819,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)
cost.construct([params + self.finite_diff_step * direction], {})
tape_forward = cost.tape.copy(copy_operations=True)
cost.construct([params - self.finite_diff_step * direction], {})
tape_backward = cost.tape.copy(copy_operations=True)
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])
return [tape_forward, tape_backward], direction

def __update_tensor(self, tensor_raw):
Expand Down Expand Up @@ -864,21 +848,7 @@ def __get_tensor_tapes(self, cost, params):
return tapes, dir_vecs

def __get_overlap_tape(self, cost, params1, params2):
op_forward = self.__get_operations(cost, params1)
op_inv = self.__get_operations(cost, params2)

with qml.tape.QuantumTape() as tape:
for op in op_forward:
qml.apply(op)
for op in reversed(op_inv):
qml.adjoint(copy(op))
qml.probs(wires=cost.tape.wires.labels)
return tape

def __get_operations(self, cost, params):
# Given a QNode, returns the list of operations before the measurement.
cost.construct([params], {})
return cost.tape.operations
return get_overlap_tape(cost, params1, params2)

def __get_tensor_moving_avg(self, metric_tensor):
# For numerical stability: averaging on the Fubini-Study metric tensor.
Expand All @@ -893,10 +863,8 @@ 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.
cost.construct([params_curr], {})
tape_loss_curr = cost.tape.copy(copy_operations=True)
cost.construct([params_next], {})
tape_loss_next = cost.tape.copy(copy_operations=True)
tape_loss_curr = qml.workflow.construct_tape(cost)(*[params_curr])
tape_loss_next = qml.workflow.construct_tape(cost)(*[params_next])

loss_curr, loss_next = qml.execute([tape_loss_curr, tape_loss_next], cost.device, None)
# self.k has been updated earlier.
Expand Down Expand Up @@ -945,11 +913,14 @@ def __apply_blocking(self, cost, params_curr, params_next):
# The optimizer performs reasonably well: the loss drops over optimization
# steps and converges finally. We then reproduce the benchmarking test
# between the gradient descent, quantum natural gradient descent, SPSA and
# QN-SPSA in Fig. 1(b) of reference [#Gacon2021]_ with the following job. You
# can find a more detailed version of the example in this
# `notebook <https://github.com/aws/amazon-braket-examples/blob/main/examples/hybrid_jobs/6_QNSPSA_optimizer_with_embedded_simulator/qnspsa_with_embedded_simulator.ipynb>`__,
# with its dependencies in the `source_scripts`
# `folder <https://github.com/aws/amazon-braket-examples/blob/main/examples/hybrid_jobs/6_QNSPSA_optimizer_with_embedded_simulator/source_scripts/>`__.
# QN-SPSA in Fig. 1(b) of reference [#Gacon2021]_ with the following job.
#
# .. warning::
# The code required to plot the results of the example below is not provided, but a similar
# example can be found in this
# `notebook <https://github.com/aws/amazon-braket-examples/blob/main/examples/hybrid_jobs/6_QNSPSA_optimizer_with_embedded_simulator/qnspsa_with_embedded_simulator.ipynb>`__,
# with all its dependencies included in the `source_scripts`
# `folder <https://github.com/aws/amazon-braket-examples/blob/main/examples/hybrid_jobs/6_QNSPSA_optimizer_with_embedded_simulator/source_scripts/>`__.
#
# .. note::
# In order for the remainder of this demo to work, you will need to have done 3 things:
Expand Down
2 changes: 1 addition & 1 deletion demonstrations/qrack.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2024-07-10T00:00:00+00:00",
"dateOfLastModification": "2024-11-06T00:00:00+00:00",
"dateOfLastModification": "2025-01-10T00:00:00+00:00",
"categories": [
"Devices and Performance"
],
Expand Down
Loading

0 comments on commit 5f3c0ef

Please sign in to comment.