Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pyQuil v3 #107

Merged
merged 62 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e0d9fb5
update pyquil to v3, add qcs-api-client
MarquessV Sep 29, 2022
7028eea
replace ForestConnection with QCSClientConfiguration
MarquessV Sep 29, 2022
06bde97
migrate qvm to pyquil v3
MarquessV Sep 29, 2022
ffc9507
reenable forest.qpu and migrate to pyquilv3
MarquessV Sep 29, 2022
b87450f
migrate forest.(numpy_)wavefunction to pyquil v3
MarquessV Sep 29, 2022
d353074
fix how timeouts are handled in qvm
MarquessV Oct 3, 2022
f3bae8b
first pass at documentation updates
MarquessV Oct 4, 2022
7d15428
forest -> QCS
MarquessV Oct 4, 2022
da1ae9d
get qvm tests passing
MarquessV Oct 6, 2022
0d9e0d2
get QPU tests passing
MarquessV Oct 7, 2022
522ab14
relax pyquil requirement, doc suggestions
MarquessV Oct 10, 2022
46c2ac8
make shot_range, bin_size optional to match QubitDevice, cleanup RESET
MarquessV Oct 12, 2022
70390e9
let pyQuil set its own defaults add missing asserts to tests
MarquessV Oct 12, 2022
08c66bf
create separate doc for server config and include it where needed
MarquessV Oct 12, 2022
bb4edd4
reformat with black
MarquessV Oct 12, 2022
788b3cc
remove RequestException as it is no longer used in pyQuil
MarquessV Oct 12, 2022
67e65fc
Update README.rst
MarquessV Oct 13, 2022
22ea520
Update README.rst
MarquessV Oct 13, 2022
7c4a100
Update README.rst
MarquessV Oct 13, 2022
7fb83a2
fix typo in qpu docs and correct notes on server configuration
MarquessV Oct 13, 2022
2dea717
remove special mention of operations that are now available in pennylane
MarquessV Oct 13, 2022
c5c71f2
remove reference to special operations, add lower bound for PennyLane
MarquessV Oct 13, 2022
2141065
add compiler and execution timeout to docstrings
MarquessV Oct 13, 2022
844b59c
add docstring to extract_samples
MarquessV Oct 13, 2022
4a7bb45
remove unused kwargs on ForestDevice and its children
MarquessV Oct 13, 2022
72f3a1c
reformat with black
MarquessV Oct 13, 2022
ef3c6a2
remove comment on wrap_in_numshots_loop
MarquessV Oct 13, 2022
d83f5a7
consolidate gate import, remove comment about unsupported gates
MarquessV Oct 13, 2022
9e9579b
use dict literal instead of dict()
MarquessV Oct 13, 2022
d328da4
remove mention of special support for gates
MarquessV Oct 14, 2022
c4337ab
remove figure, add description to title-card directives
MarquessV Oct 14, 2022
7a6c8cf
import CPHASE
MarquessV Oct 14, 2022
a2080b7
remove extra params from super call
MarquessV Oct 14, 2022
28a10a7
increase shots on tests without parametric_compilation
MarquessV Oct 14, 2022
5aafa7f
remove pytest.mark.xfail from converter tests
MarquessV Oct 14, 2022
f5f6758
fix jacobian call in differntiation test
MarquessV Oct 17, 2022
e44423e
device refactor: move shared init logic into ForestDevice
MarquessV Oct 17, 2022
2a4b703
device refactor: move execute and apply into ForestDevice
MarquessV Oct 17, 2022
250ec90
device refactor: move circuit_hash, compiled_program properties into
MarquessV Oct 17, 2022
06a0341
device refactor: consolidate reset method logic into ForestDevice
MarquessV Oct 17, 2022
9595f34
device refactor: move generate and extract_samples into ForestDevice
MarquessV Oct 17, 2022
d75b48e
device refactor: QPUDevice inherits from ForestDevice
MarquessV Oct 17, 2022
e3be565
device refactor: formatting and cleanup
MarquessV Oct 17, 2022
0ab8488
device refactor: lift shared logic for qvm qpu out of ForestDevice into
MarquessV Oct 18, 2022
2210148
device refactor: make noisy a qvm only param, cleanup docstrings
MarquessV Oct 18, 2022
36987d8
device refactor: cleanup and reformat with black
MarquessV Oct 18, 2022
f8c9e68
device refactor: cleanup a few pylint nits
MarquessV Oct 18, 2022
59fd5a3
Fix tests
AlbertMitjans Oct 19, 2022
3b89a18
Merge remote-tracking branch 'upstream/fix-pyqvm-tests' into migrate-…
MarquessV Oct 19, 2022
bae8350
set min pennylane version to 0.18
MarquessV Oct 19, 2022
b16f93d
replace plugin operations with pennylane gates
MarquessV Oct 19, 2022
0d6b4a4
fix pyquil.simulation import
MarquessV Oct 19, 2022
61dd4a6
remove extra reset in QCDevice, add requested docstrings
MarquessV Oct 19, 2022
ac0863a
remove trailing newline, simplify simulation import
MarquessV Oct 19, 2022
1ee610b
simplify generate_samples and move `pyqvm` specific logic to QVMDevice
MarquessV Oct 19, 2022
ae036e9
update docs requirements
MarquessV Oct 19, 2022
e78e874
bump quilc version in workflows
MarquessV Oct 19, 2022
d510dd8
fix typo in method name
MarquessV Oct 19, 2022
619dea4
make sure program isn't compiled if it's been cached
MarquessV Oct 20, 2022
ef30631
remove extraneous failing test that unnaturally overwrites private value
MarquessV Oct 20, 2022
acca6d7
pylint: initialize all instance params in __init__
MarquessV Oct 20, 2022
9ea5832
increase EXECUTION_TIMEOUT
MarquessV Oct 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ PennyLane Forest Plugin
.. header-start-inclusion-marker-do-not-remove

The PennyLane Forest plugin allows different Rigetti devices to work with
PennyLane --- the wavefunction simulator, and the Quantum Virtual Machine (QVM).
PennyLane --- the wavefunction simulator, the Quantum Virtual Machine (QVM), and Quantum Processing Units (QPUs).

`pyQuil <https://pyquil.readthedocs.io>`__ is a Python library for quantum programming using the
quantum instruction language (Quil) --- resulting quantum programs can be executed using the
`Rigetti Forest SDK <https://pyquil-docs.rigetti.com/en/stable/>`__ and the `Rigetti QCS
`Rigetti Forest SDK <https://pyquil-docs.rigetti.com/en/stable/>`__ and `Rigetti Quantum Cloud Services (QCS)
<https://qcs.rigetti.com/>`__.

`PennyLane <https://pennylane.readthedocs.io>`__ is a cross-platform Python library for quantum machine
Expand All @@ -46,23 +46,14 @@ The plugin documentation can be found here: `<https://docs.pennylane.ai/projects
Features
========

* Provides three devices to be used with PennyLane: ``forest.numpy_wavefunction``,
``forest.wavefunction``, and ``forest.qvm``. These provide access to the pyQVM
Numpy wavefunction simulator, Forest wavefunction simulator, and quantum
virtual machine (QVM) respectively.
* Provides four devices to be used with PennyLane: ``forest.numpy_wavefunction``,
``forest.wavefunction``, ``forest.qvm``, and ``forest.qpu``. These provide access to the pyQVM
Numpy wavefunction simulator, pyQuil wavefunction simulator, quantum
virtual machine (QVM), and quantum processing units (QPUs) respectively.


* All provided devices support all core qubit PennyLane operations and observables.


* Provides custom PennyLane operations to cover additional pyQuil operations:
``ISWAP``, ``PSWAP``, and ``CPHASE``. Every custom operation supports analytic
differentiation.

* Combine Forest and the Rigetti Cloud Services with PennyLane's automatic differentiation and
optimization.


.. installation-start-inclusion-marker-do-not-remove

Installation
Expand All @@ -86,14 +77,12 @@ Dependencies

PennyLane-Forest requires the following libraries be installed:

* `Python <http://python.org/>`__ >=3.6
* `Python <http://python.org/>`__ >=3.7

as well as the following Python packages:

* `PennyLane <http://pennylane.readthedocs.io/>`__
* `pyQuil <https://pyquil-docs.rigetti.com/en/stable/>`__ >=2.16, <2.28.3

Note that the latest PyQuil version 3.0 is not currently supported.
* `PennyLane <http://pennylane.readthedocs.io/>`__ >=0.15.0
* `pyQuil <https://pyquil-docs.rigetti.com/en/stable/>`__ >=3.3.1, <4.0.0

If you currently do not have Python 3 installed, we recommend
`Anaconda for Python 3 <https://www.anaconda.com/download/>`__, a distributed version
Expand All @@ -105,11 +94,11 @@ Forest software development kit (SDK):

* `Forest SDK <https://pyquil-docs.rigetti.com/en/stable/>`__

Alternatively, you may sign up for Rigetti's Quantum Cloud Services (QCS) to acquire a Quantum Machine
Image (QMI) which will allow you to compile your quantum code and run on real quantum processing units (QPUs),
or on a preinstalled QVM. Note that this requires a valid QCS account.
Alternatively, you may sign up for Rigetti's Quantum Cloud Services (QCS) which will allow you to compile your
quantum code and run on real QPUs. Note that this requires a valid QCS account and the QCS CLI:

* `Quantum Cloud Services <https://docs.rigetti.com/en/>`__
* `QCS <https://docs.rigetti.com/en/>`__
* `QCS CLI <https://docs.rigetti.com/qcs/guides/using-the-qcs-cli>`__

Tests
~~~~~
Expand Down
13 changes: 1 addition & 12 deletions doc/devices/numpy_wavefunction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,4 @@ array([0.97517033, 0.04904283])
Supported operations
~~~~~~~~~~~~~~~~~~~~

All Forest devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with
the exception of the PennyLane ``QubitStateVector`` state preparation operation.

In addition, PennyLane-Forest provides the following PyQuil-specific operations for PennyLane.
These are all importable from :mod:`pennylane_forest.ops <.ops>`.

These operations include:

.. autosummary::
pennylane_forest.ops.CPHASE
pennylane_forest.ops.ISWAP
pennylane_forest.ops.PSWAP
All Forest devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with the exception of the PennyLane ``QubitStateVector`` state preparation operation.
53 changes: 10 additions & 43 deletions doc/devices/qpu.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
:orphan:

The QPU device
MarquessV marked this conversation as resolved.
Show resolved Hide resolved
==============

The intention of the ``forest.qpu`` device is to construct a device that will allow for execution on an actual QPU.
Constructing and using this device is very similar to very similar in design and implementation as the
``forest.qvm`` device, with slight differences at initialization, such as not supporting the keyword argument ``noisy``.
Constructing and using this device is very similar in design and implementation as the ``forest.qvm`` device, with
slight differences at initialization, such as not supporting the keyword argument ``noisy``.

In addition, ``forest.qpu`` also accepts the optional ``active_reset`` keyword argument:

Expand All @@ -21,7 +19,7 @@ Usage
A QPU device can be created via:

>>> import pennylane as qml
>>> dev_qpu = qml.device('forest.qpu', device='Aspen-8', shots=1000)
>>> dev_qpu = qml.device('forest.qpu', device='Aspen-M-2', shots=1000)

Note that additional Quil gates not provided directly in PennyLane are importable from :mod:`~.ops`.
An example that demonstrates the use of the native :class:`~.PSWAP` plugin gate is this:
Expand Down Expand Up @@ -51,46 +49,15 @@ We can then integrate the quantum hardware and PennyLane's automatic differentia
Supported operations
~~~~~~~~~~~~~~~~~~~~

All devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with
he exception of the PennyLane ``QubitStateVector`` state preparation operation.

In addition, PennyLane-Forest provides the following PyQuil-specific operations for PennyLane.
These are all importable from :mod:`pennylane_forest.ops <.ops>`.

These operations include:

.. autosummary::
pennylane_forest.ops.CPHASE
pennylane_forest.ops.ISWAP
pennylane_forest.ops.PSWAP

Device options
~~~~~~~~~~~~~~
All devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with the exception of the PennyLane ``QubitStateVector`` state preparation operation.

On initialization, the PennyLane-Forest devices accept additional keyword
arguments beyond the PennyLane default device arguments.

``forest_url`` (*str*)
the Forest URL server. Can also be set by
the environment variable ``FOREST_SERVER_URL``, or in the ``~/.qcs_config``
configuration file. Default value is ``"https://forest-server.qcs.rigetti.com"``.

``qvm_url`` (*str*)
the QVM server URL. Can also be set by the environment
variable ``QVM_URL``, or in the ``~/.forest_config`` configuration file.
Default value is ``"http://127.0.0.1:5000"``.

``compiler_url`` (*str*)
the compiler server URL. Can also be set by the environment
variable ``COMPILER_URL``, or in the ``~/.forest_config`` configuration file.
Default value is ``"http://127.0.0.1:6000"``.
MarquessV marked this conversation as resolved.
Show resolved Hide resolved
quilc server configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

If using the downloadable Forest SDK with the default server configurations
for the QVM and the Quil compiler (i.e., you launch them with the commands
``qvm -S`` and ``quilc -R``), then you will not need to set these keyword arguments.

Likewise, if you are running PennyLane using the Rigetti Quantum Cloud Service (QCS)
on a provided QMI, these environment variables are set automatically and will also
not need to be passed in PennyLane.
for the Quil compiler (i.e., ``quilc -R``), then no special configuration is needed.
If using a non-default port or host for the server, see the
`pyQuil configuration documentation <https://pyquil-docs.rigetti.com/en/stable/advanced_usage.html#pyquil-configuration>`_
for details on how to override the default values.
47 changes: 2 additions & 45 deletions doc/devices/qvm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,7 @@ Printing out the results of the three device expectation values:
Supported operations
~~~~~~~~~~~~~~~~~~~~

All devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with
he exception of the PennyLane ``QubitStateVector`` state preparation operation.

In addition, PennyLane-Forest provides the following PyQuil-specific operations for PennyLane.
These are all importable from :mod:`pennylane_forest.ops <.ops>`.

These operations include:

.. autosummary::
pennylane_forest.ops.CPHASE
pennylane_forest.ops.ISWAP
pennylane_forest.ops.PSWAP
All devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with the exception of the PennyLane ``QubitStateVector`` state preparation operation.

Supported observables
~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -190,36 +179,4 @@ After measuring the qubit state, we can determine the probability :math:`P_0` of

MarquessV marked this conversation as resolved.
Show resolved Hide resolved
This process is done automatically behind the scenes in the QVM device when ``qml.expval(qml.Hermitian)`` is returned.




Device options
~~~~~~~~~~~~~~

On initialization, the PennyLane-Forest devices accept additional keyword
arguments beyond the PennyLane default device arguments.

``forest_url`` (*str*)
the Forest URL server. Can also be set by
the environment variable ``FOREST_SERVER_URL``, or in the ``~/.qcs_config``
configuration file. Default value is ``"https://forest-server.qcs.rigetti.com"``.

``qvm_url`` (*str*)
the QVM server URL. Can also be set by the environment
variable ``QVM_URL``, or in the ``~/.forest_config`` configuration file.
Default value is ``"http://127.0.0.1:5000"``.

``compiler_url`` (*str*)
the compiler server URL. Can also be set by the environment
variable ``COMPILER_URL``, or in the ``~/.forest_config`` configuration file.
Default value is ``"http://127.0.0.1:6000"``.
MarquessV marked this conversation as resolved.
Show resolved Hide resolved

.. note::

If using the downloadable Forest SDK with the default server configurations
for the QVM and the Quil compiler (i.e., you launch them with the commands
``qvm -S`` and ``quilc -R``), then you will not need to set these keyword arguments.

Likewise, if you are running PennyLane using the Rigetti Quantum Cloud Service (QCS)
on a provided QMI, these environment variables are set automatically and will also
not need to be passed in PennyLane.
.. include:: ./qvm_and_quilc_server_configuration.rst
11 changes: 11 additions & 0 deletions doc/devices/qvm_and_quilc_server_configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
QVM and quilc server configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::

If using the downloadable Forest SDK with the default server configurations
for the QVM and the Quil compiler (i.e., you launch them with the commands
``qvm -S`` and ``quilc -R``), then no special configuration is needed.
If using a non-default port or host for either of the servers, see the
`pyQuil configuration documentation <https://pyquil-docs.rigetti.com/en/stable/advanced_usage.html#pyquil-configuration>`_
for details on how to override the default values.
44 changes: 2 additions & 42 deletions doc/devices/wavefunction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,49 +50,9 @@ You can then execute the circuit like any other function to get the quantum mech
>>> circuit(0.2, 0.1, 0.3)
array([0.97517033, 0.04904283])

Device options
~~~~~~~~~~~~~~

On initialization, the PennyLane-Forest devices accept additional keyword
arguments beyond the PennyLane default device arguments.

``forest_url`` (*str*)
the Forest URL server. Can also be set by
the environment variable ``FOREST_SERVER_URL``, or in the ``~/.qcs_config``
configuration file. Default value is ``"https://forest-server.qcs.rigetti.com"``.

``qvm_url`` (*str*)
the QVM server URL. Can also be set by the environment
variable ``QVM_URL``, or in the ``~/.forest_config`` configuration file.
Default value is ``"http://127.0.0.1:5000"``.

``compiler_url`` (*str*)
the compiler server URL. Can also be set by the environment
variable ``COMPILER_URL``, or in the ``~/.forest_config`` configuration file.
Default value is ``"http://127.0.0.1:6000"``.
MarquessV marked this conversation as resolved.
Show resolved Hide resolved

.. note::

If using the downloadable Forest SDK with the default server configurations
for the QVM and the Quil compiler (i.e., you launch them with the commands
``qvm -S`` and ``quilc -R``), then you will not need to set these keyword arguments.

Likewise, if you are running PennyLane using the Rigetti Quantum Cloud Service (QCS)
on a provided QMI, these environment variables are set automatically and will also
not need to be passed in PennyLane.

Supported operations
~~~~~~~~~~~~~~~~~~~~

All devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with
he exception of the PennyLane ``QubitStateVector`` state preparation operation.

In addition, PennyLane-Forest provides the following PyQuil-specific operations for PennyLane.
These are all importable from :mod:`pennylane_forest.ops <.ops>`.

These operations include:
All devices support all PennyLane `operations and observables <https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-operations>`_, with the exception of the PennyLane ``QubitStateVector`` state preparation operation.

.. autosummary::
pennylane_forest.ops.CPHASE
pennylane_forest.ops.ISWAP
pennylane_forest.ops.PSWAP
.. include:: ./qvm_and_quilc_server_configuration.rst
19 changes: 12 additions & 7 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ Currently, PennyLane-Forest provides these Forest devices for PennyLane:

.. title-card::
:name: 'forest.numpy_wavefunction'
:description: Forest's Numpy wavefunction simulator backend.
:description: pyQuil's Numpy wavefunction simulator backend.
:link: devices/numpy_wavefunction.html

.. title-card::
:name: 'forest.wavefunction'
:description: The Forest SDK wavefunction simulator backend.
:description: The QCS wavefunction simulator backend.
:link: devices/wavefunction.html

.. title-card::
:name: 'forest.qvm'
:description: Forest's QVM and pyQuil pyQVM simulator.
:description: QCS QVM and pyQuil pyQVM simulator.
:link: devices/qvm.html

.. title-card::
:name: 'forest.qpu'
:description: QCS QPU.
:link: devices/qpu.html

.. raw:: html

<div style='clear:both'></div>
Expand All @@ -45,20 +50,19 @@ Check out these demos to see the PennyLane-Forest plugin in action:
<div class="row">

.. title-card::
MarquessV marked this conversation as resolved.
Show resolved Hide resolved
:name: Ensemble classification with Forest and Qiskit devices
:figure: <img src="https://pennylane.ai/qml/_images/ensemble_diagram.png" width="100%" />
:name: Ensemble classification with QCS and Qiskit devices
:description: Use two QPUs in parallel to help solve a machine learning classification problem.
:link: https://pennylane.ai/qml/demos/ensemble_multi_qpu.html

.. title-card::
:name: PyTorch and noisy devices
:figure: <img src="https://pennylane.ai/qml/_images/bloch.gif" width="100%" />
:description: Use PyTorch and a noisy QVM to see how optimization responds to noisy qubits.
:link: https://pennylane.ai/qml/demos/pytorch_noise.html

.. raw:: html

</div></div><div style='clear:both'> <br/>


You can also try it out using any of the qubit based `demos from the PennyLane documentation
<https://pennylane.ai/qml/demonstrations.html>`_, for example the tutorial on
`qubit rotation <https://pennylane.ai/qml/demos/tutorial_qubit_rotation.html>`_.
Expand Down Expand Up @@ -89,6 +93,7 @@ hardware access.
devices/numpy_wavefunction
devices/wavefunction
devices/qvm
devices/qpu

.. toctree::
:maxdepth: 1
Expand Down
1 change: 1 addition & 0 deletions pennylane_forest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
===============
"""
from .ops import CPHASE, ISWAP, PSWAP
from .qpu import QPUDevice
from .qvm import QVMDevice
from .wavefunction import WavefunctionDevice
from .numpy_wavefunction import NumpyWavefunctionDevice
Expand Down
Loading