From 8333fa36c8ee3a853f1aef4398df71b2cc4cd032 Mon Sep 17 00:00:00 2001 From: lillian542 <38584660+lillian542@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:54:56 -0500 Subject: [PATCH] Update Rigetti demos (#1042) 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 --- demonstrations/ensemble_multi_qpu.py | 24 ++++++++++++------------ demonstrations/pytorch_noise.py | 13 ++++++++++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/demonstrations/ensemble_multi_qpu.py b/demonstrations/ensemble_multi_qpu.py index baa67ff58f..d062bb3cc3 100644 --- a/demonstrations/ensemble_multi_qpu.py +++ b/demonstrations/ensemble_multi_qpu.py @@ -46,6 +46,16 @@ # /interfaces.html>`_, which can be installed from `here # `__. # +# .. 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 +# `__ 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 # --------- # @@ -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 # `__). # -# .. 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 -# `__ 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: # @@ -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) diff --git a/demonstrations/pytorch_noise.py b/demonstrations/pytorch_noise.py index 6e03d1c6dd..067c1c8c98 100644 --- a/demonstrations/pytorch_noise.py +++ b/demonstrations/pytorch_noise.py @@ -25,9 +25,16 @@ To follow along with this tutorial on your own computer, you will require the following dependencies: -* The `Rigetti SDK `_, which contains the quantum virtual +* Rigetti's QVM and Quil Compiler services. One option for setting this up is the + `Rigetti SDK `_, 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 `_, in order to access the QVM as a PennyLane device. This can be installed via pip: @@ -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", @@ -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")