Skip to content

Commit

Permalink
Update Rigetti demos (#1042)
Browse files Browse the repository at this point in the history
A few updates to the Rigetti demos:

- Pytorch Noise
- Update Aspen-M-2 to Aspen-M-3 for the hardware version (M-2 is
decommissioned)
- Add the info about connecting to Rigetti with Docker (included in the
other Rigetti demos)
- Ensemble Multi QPU
- Move the information about connecting to the Rigetti device to
_before_ the section where we try to connect to the Rigetti device
   - Change how we cast to torch during prediction phase

---------

Co-authored-by: Mudit Pandey <[email protected]>
  • Loading branch information
lillian542 and mudit2812 authored Mar 1, 2024
1 parent 931390c commit 8333fa3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
24 changes: 12 additions & 12 deletions demonstrations/ensemble_multi_qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
# /interfaces.html>`_, which can be installed from `here
# <https://pytorch.org/get-started/locally/>`__.
#
# .. warning::
# Rigetti's QVM and Quil Compiler services must be running for this tutorial to execute. They
# can be installed by consulting the `Rigetti documentation
# <http://docs.rigetti.com/qcs/>`__ or, for users with Docker, by running:
#
# .. code-block:: bash
#
# docker run -d -p 5555:5555 rigetti/quilc -R -p 5555
# docker run -d -p 5000:5000 rigetti/qvm -S -p 5000
#
# Load data
# ---------
#
Expand Down Expand Up @@ -186,15 +196,6 @@ def plot_points(x_train, y_train, x_test, y_test):
# swap ``qiskit.aer`` for ``qiskit.ibmq`` and specify their chosen backend (see `here
# <https://docs.pennylane.ai/projects/qiskit/en/latest/devices/ibmq.html>`__).
#
# .. warning::
# Rigetti's QVM and Quil Compiler services must be running for this tutorial to execute. They
# can be installed by consulting the `Rigetti documentation
# <http://docs.rigetti.com/qcs/>`__ or, for users with Docker, by running:
#
# .. code-block:: bash
#
# docker run -d -p 5555:5555 rigetti/quilc -R -p 5555
# docker run -d -p 5000:5000 rigetti/qvm -S -p 5000
#
# The circuits for both QPUs are shown in the figure below:
#
Expand Down Expand Up @@ -259,9 +260,8 @@ def decision(softmax):

def predict_point(params, x_point=None, parallel=True):
if parallel:
results = tuple(dask.delayed(q)(params, x=x_point) for q in qnodes)
results = dask.compute(*results, scheduler="threads")
results = torch.tensor(torch.vstack(results))
results = tuple(dask.delayed(q)(params, x=torch.from_numpy(x_point)) for q in qnodes)
results = torch.tensor(dask.compute(*results, scheduler="threads"))
else:
results = tuple(q(params, x=x_point) for q in qnodes)
results = torch.tensor(results)
Expand Down
13 changes: 10 additions & 3 deletions demonstrations/pytorch_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
To follow along with this tutorial on your own computer, you will require the
following dependencies:
* The `Rigetti SDK <https://qcs.rigetti.com/sdk-downloads>`_, which contains the quantum virtual
* Rigetti's QVM and Quil Compiler services. One option for setting this up is the
`Rigetti SDK <https://qcs.rigetti.com/sdk-downloads>`_, which contains the quantum virtual
machine (QVM) and quilc quantum compiler. Once installed, the QVM and quilc can be
started by running the commands ``quilc -S`` and ``qvm -S`` in separate terminal windows.
Alternatively, for users with Docker, the QVM and Quil Compiler services can be run with commands:
.. code-block:: bash
docker run -d -p 5555:5555 rigetti/quilc -R -p 5555
docker run -d -p 5000:5000 rigetti/qvm -S -p 5000
* `PennyLane-Rigetti plugin <https://docs.pennylane.ai/projects/rigetti/en/latest/>`_, in order
to access the QVM as a PennyLane device. This can be installed via pip:
Expand Down Expand Up @@ -198,7 +205,7 @@ def cost(phi, theta, step):
my_prefix = "Your-Folder-Name" # the name of the folder in the bucket
s3_folder = (my_bucket, my_prefix)

device_arn = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2"
device_arn = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3"

qpu = qml.device(
"braket.aws.qubit",
Expand All @@ -208,7 +215,7 @@ def cost(phi, theta, step):
)

# Note: swap dev to qpu here to use the QPU
# Warning: check the pricing of Aspen-M-2 on Braket to make
# 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")
Expand Down

0 comments on commit 8333fa3

Please sign in to comment.