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

Compatibility with 1.0 for devices #493

Merged
merged 57 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6f2c067
remove deprecated installation syntax from test yaml
lillian542 Mar 8, 2024
39d1c37
run all the test vs Qiskit 1.0
lillian542 Mar 8, 2024
ffc33e3
update to only raise error for BasicAer
lillian542 Mar 8, 2024
4629ac4
add missing import
lillian542 Mar 8, 2024
0c257c5
reorganize test parameterization for 1.0
lillian542 Mar 8, 2024
39f040b
remove unused import
lillian542 Mar 8, 2024
281088e
add a BasicSimulator device
lillian542 Mar 8, 2024
c6328eb
import BasicSimulatorDevice
lillian542 Mar 8, 2024
72163a6
update combinations of test devices and backends
lillian542 Mar 8, 2024
75447df
update devices and backends in integration tests
lillian542 Mar 8, 2024
0ee569b
update tests for incompatible devices and versions
lillian542 Mar 8, 2024
714f263
update QiskitDevice tests to use IBMQ instead of BasicAer
lillian542 Mar 8, 2024
7a9f31e
tweak QiskitDevice for compatibility with BasicSimulator
lillian542 Mar 8, 2024
8cae9f9
fix bad relative import path
lillian542 Mar 8, 2024
9f36d27
Merge branch 'master' into compatibility
lillian542 Mar 28, 2024
ee4a0cd
skip devices in conftest with incompatible provider-backend combinat…
lillian542 Mar 28, 2024
79a2880
qasm_simulator is just qasm_simulator for old qiskit too now
lillian542 Mar 28, 2024
4d3996a
more fixes for combinations of providers and backends
lillian542 Mar 28, 2024
8435386
move import to top level
lillian542 Apr 1, 2024
9989ad3
update to supported backends in test_qiskit_device.py
lillian542 Apr 1, 2024
0065480
correct Regex pattern for error test
lillian542 Apr 1, 2024
9032d2b
update providers and backends in test_integration.py
lillian542 Apr 1, 2024
652adfb
trigger ci
lillian542 Apr 1, 2024
3268f65
use provider that doesn't requre token
lillian542 Apr 1, 2024
4747883
run device integration tests with 1.0
lillian542 Apr 1, 2024
8c2c528
correct backend for 1.0 device integration tests
lillian542 Apr 1, 2024
ec6da21
upload 1.0 test results to codecov
lillian542 Apr 1, 2024
61ad265
add IBMQ tests with 1.0
lillian542 Apr 1, 2024
aae375e
Merge branch 'master' into compatibility
lillian542 Apr 1, 2024
767dbf4
add basicsim device to documentation
lillian542 Apr 1, 2024
c5c0886
update install instructions
lillian542 Apr 2, 2024
a793665
update changelog
lillian542 Apr 2, 2024
452114c
update basicsim documentation
lillian542 Apr 2, 2024
1ac068a
update docstring for basicsim
lillian542 Apr 2, 2024
24a8957
cutoff for basicaer is 0.46 instead of 0.45.3
lillian542 Apr 2, 2024
e545e4c
remove whitespace
lillian542 Apr 2, 2024
77aabab
black formatting
lillian542 Apr 2, 2024
754eee4
indicate partial version number
lillian542 Apr 2, 2024
57736a4
small docs update
lillian542 Apr 2, 2024
bfcd346
Apply suggestions from code review
lillian542 Apr 3, 2024
fe0dc6d
rearrange order of device cards on docs page
lillian542 Apr 3, 2024
c75ef36
docs updates
lillian542 Apr 3, 2024
36855c0
Update doc/devices/basicsim.rst
lillian542 Apr 3, 2024
3058267
add reference
lillian542 Apr 3, 2024
655166a
correct reference
lillian542 Apr 3, 2024
e6a9180
maybe it doesn't like underscores?
lillian542 Apr 3, 2024
ec65874
update reference
lillian542 Apr 3, 2024
0125bab
update refs
lillian542 Apr 3, 2024
e1664eb
add custom analytic not supported msg for BasicProvider device
lillian542 Apr 3, 2024
094afba
update warning
lillian542 Apr 3, 2024
05735df
remove unused import
lillian542 Apr 3, 2024
1db98aa
remove kwarg section of basic_simulator docstring
lillian542 Apr 10, 2024
e0f8af5
trigger ci
lillian542 Apr 10, 2024
647d64c
Unpin Qiskit where relevant (#508)
lillian542 Apr 10, 2024
ef9c832
Merge branch 'master' into compatibility
lillian542 Apr 10, 2024
1feb916
add codecov token for 1.0 tests
lillian542 Apr 10, 2024
ec9bae5
add codecov token for 1.0 tests one more place
lillian542 Apr 10, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/ibmq_tests_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: IBMQ integration tests with Qiskit 1.0
on:
schedule:
- cron: '1 0 * * 0,4' # At 01:00 on Sunday and Thursday.
workflow_dispatch:

jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.9]

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci0.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
pip freeze

- name: Install Plugin
run: |
pip install git+https://github.com/PennyLaneAI/pennylane-qiskit.git@${{ github.ref }}
pip freeze

- name: Run tests
# Only run IBMQ and Runtime tests (skipped otherwise)
run: python -m pytest tests -k 'test_ibmq.py or test_runtime.py' --cov=pennylane_qiskit --cov-report=term-missing --cov-report=xml -p no:warnings --tb=native
env:
IBMQX_TOKEN: ${{ secrets.IBMQX_TOKEN_TEST }}
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-ci.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
pip freeze

- name: Install Plugin
run: |
python setup.py bdist_wheel
pip install dist/PennyLane*.whl
pip install git+https://github.com/PennyLaneAI/pennylane-qiskit.git@${{ github.ref }}
pip freeze

- name: Run tests
# Skip IBMQ and Runtime tests as they depend on IBMQ's availability and
Expand Down
53 changes: 47 additions & 6 deletions .github/workflows/tests_qiskit_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,57 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-ci0.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
pip freeze

- name: Install Plugin
run: |
pip install git+https://github.com/PennyLaneAI/pennylane-qiskit.git@${{ github.ref }}
pip freeze

- name: Run standard Qiskit plugin tests
# Run the standard tests with the most recent version of Qiskit
run: python -m pytest tests -k 'not test_ibmq.py and not test_runtime.py' --cov=pennylane_qiskit --cov-report=term-missing --cov-report=xml -p no:warnings --tb=native

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml

integration-tests:
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci0.txt
pip install wheel pytest pytest-cov pytest-mock pytest-benchmark flaky --upgrade

- name: Install Plugin
run: |
python setup.py bdist_wheel
pip install dist/PennyLane*.whl

- name: Run Qiskit converter tests
# Test conversion to PennyLane with Qiskit 1.0.0
run: python -m pytest tests/test_converter.py
- name: Run tests
run: |
pl-device-test --device=qiskit.basicsim --tb=short --skip-ops --shots=20000 --device-kwargs backend=basic_simulator
pl-device-test --device=qiskit.aer --tb=short --skip-ops --shots=20000 --device-kwargs backend=qasm_simulator
pl-device-test --device=qiskit.aer --tb=short --skip-ops --shots=None --device-kwargs backend=statevector_simulator
pl-device-test --device=qiskit.aer --tb=short --skip-ops --shots=None --device-kwargs backend=unitary_simulator
mudit2812 marked this conversation as resolved.
Show resolved Hide resolved

- name: Run temporary tests
# tests that test intermediate functionality, will be removed when everything is fully compatible with 1.0
run: python -m pytest tests/test_new_qiskit_temp.py
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### New features since last release

* Support is added for using the plugin devices with Qiskit 1.0. As the backend provider ``qiskit.BasicAer``
is no longer supported by Qiskit in 1.0, this added support does not extend to the ``"qiskit.aer"`` device.
Instead, a ``"qiskit.basicsim"`` device is added, with the new Qiskit implementation of a Python simulator
device, ``BasicSimulator``, as the backend.
[(#493)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/493)

### Improvements 🛠

### Breaking changes 💔
Expand All @@ -15,6 +21,7 @@
### Contributors ✍️

This release contains contributions from (in alphabetical order):
Lillian M. A. Frederiksen

---
# Release 0.35.1
Expand Down
15 changes: 3 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,15 @@ Installation of this plugin, as well as all dependencies, can be done using ``pi

.. code-block:: bash

pip install "qiskit<0.46"
pip install pennylane-qiskit

If you prefer to use Qiskit 1.0, you can omit the first line above and instead consult the
`Qiskit installation guide <https://docs.quantum.ibm.com/start/install>`__, which includes
details on how to migrate to 1.0 if you already have Qiskit installed.
Note that only conversion to PennyLane is supported with Qiskit 1.0; support
for devices with 1.0 be available in a later release of the plugin.

To test that the PennyLane-Qiskit plugin is working correctly you can run

.. code-block:: bash

make test

in the source folder. Tests restricted to a specific provider can be run by executing
``make test-basicaer``, ``make test-aer``, and ``make test-ibmq``.
in the source folder.

.. note::

Expand All @@ -88,9 +80,8 @@ in the source folder. Tests restricted to a specific provider can be run by exec
`new IBMProvider <https://qiskit.org/ecosystem/ibm-provider/stubs/qiskit_ibm_provider.IBMProvider.html>`_

If this is the case, running ``make test`` also executes tests on the ``ibmq`` device.
By default tests on the ``ibmq`` device run with ``ibmq_qasm_simulator`` backend
and those done by the ``basicaer`` and ``aer`` device are run with the ``qasm_simulator``
backend. At the time of writing this means that the test are "free".
By default, tests on the ``ibmq`` device run with ``ibmq_qasm_simulator`` backend. At
the time of writing this means that the test are "free".
Comment on lines +83 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we will do here regarding this announcement 🤔 We might need to migrate to using the local integration tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these remote tests being run in the plugin test matrix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are running in the plugin matrix. And yes, we've started seeing warnings about that when running the tests.

Probably we will want to change our default backend for devices that currently use the ibmq_qasm_simulator to be the aer_simulator instead, since that's one of their recommended options in their migration documentation.

For our test, I think almost everything using the ibmq_qasm_simulator can also just be replaced with the aer_simulator for now. The fake providers and backends sound nice long-term, but just using aer_simulator should be pretty quick fix to keep our tests working in the meantime.

Please verify that this is also the case for your account.

.. installation-end-inclusion-marker-do-not-remove
Expand Down
2 changes: 2 additions & 0 deletions doc/devices/aer.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _aer device page:

The Aer device
==============
The ``qiskit.aer`` device provided by the PennyLane-Qiskit plugin allows you to use PennyLane
Expand Down
6 changes: 6 additions & 0 deletions doc/devices/basicaer.rst
trbromley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
The BasicAer device
===================

.. note::

Qiskit discontinued their ``BasicAer`` device in the 1.0 release, so this device
is only available for lower versions of Qiskit. For a simple Python simulator
compatible with Qiskit 1.0, use the :ref:`BasicSim device <basicsim device page>` instead.

While the ``'qiskit.aer'`` device is the standard go-to simulator that is provided along
the Qiskit main package installation, there exists a natively included python simulator
that is slower but will work usually without the need to install other dependencies
Expand Down
24 changes: 24 additions & 0 deletions doc/devices/basicsim.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _basicsim device page:

The BasicSim device
lillian542 marked this conversation as resolved.
Show resolved Hide resolved
===================

Qiskit comes packed with a
`basic pure-Python simulator <https://docs.quantum.ibm.com/api/qiskit/qiskit.providers.basic_provider.BasicSimulator>`_
that can be accessed in this plugin through:

.. code-block:: python

import pennylane as qml
dev = qml.device('qiskit.basicsim', wires=2)

This device uses the Qiskit ``BasicSimulator`` backend from the
`basic_provider <https://docs.quantum.ibm.com/api/qiskit/providers_basic_provider>`_ module in Qiskit.

.. note::

The `Qiskit Aer <https://qiskit.github.io/qiskit-aer/>`_ device
provides a fast simulator that is also capable of simulating
noise. It is available as :ref:`"qiskit.aer" <aer device page>`, but the backend must be
installed separately with ``pip install qiskit-aer``.

21 changes: 14 additions & 7 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ can be accessed straightaway in PennyLane, without the need to import new packag
Devices
~~~~~~~

Currently, there are three different devices available:
The following devices are available:

.. title-card::
:name: 'qiskit.aer'
Expand All @@ -27,25 +27,31 @@ Currently, there are three different devices available:
:link: devices/basicaer.html

.. title-card::
:name: 'qiskit.ibmq'
:description: Allows integration with qiskit's hardware backends, and hardware-specific simulators.
:link: devices/ibmq.html
:name: 'qiskit.basicsim'
:description: A simple local Python simulator running the Qiskit ``BasicSimulator``.
:link: devices/basicsim.html

.. title-card::
:name: 'qiskit.ibmq.circuit_runner'
:description: Allows integration with qiskit's circuit runner runtime program.
:description: Allows integration with Qiskit's circuit runner runtime program.
:link: devices/runtime.html

.. title-card::
:name: 'qiskit.ibmq.sampler'
:description: Allows integration with qiskit's sampler runtime program.
:description: Allows integration with Qiskit's sampler runtime program.
:link: devices/runtime.html

.. title-card::
:name: 'qiskit.remote'
:description: Allows integration with any qiskit backend.
:description: Allows integration with any Qiskit backend.
:link: devices/remote.html

.. title-card::
:name: 'qiskit.ibmq'
:description: Allows integration with Qiskit's hardware backends, and hardware-specific simulators.
:link: devices/ibmq.html


.. raw:: html

<div style='clear:both'></div>
Expand Down Expand Up @@ -133,6 +139,7 @@ hardware access.

devices/aer
devices/basicaer
devices/basicsim
devices/ibmq
devices/runtime
devices/remote
Expand Down
2 changes: 1 addition & 1 deletion pennylane_qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from ._version import __version__
from .aer import AerDevice
from .basic_aer import BasicAerDevice
from .basic_aer import BasicAerDevice, BasicSimulatorDevice
from .ibmq import IBMQDevice
from .remote import RemoteDevice
from .converter import load, load_pauli_op, load_qasm, load_qasm_from_file
Expand Down
63 changes: 56 additions & 7 deletions pennylane_qiskit/basic_aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@

from .qiskit_device import QiskitDevice

if Version(qiskit.__version__) >= Version("1.0.0"):
from qiskit.providers.basic_provider import BasicProvider


class BasicAerDevice(QiskitDevice):
"""A PennyLane device for the native Python Qiskit simulator.
"""A PennyLane device for the native Python Qiskit simulator BasicAer.

Please see the `Qiskit documentations <https://qiskit.org/documentation/>`_
further information on the backend options and transpile options.
Expand All @@ -38,7 +41,7 @@ class BasicAerDevice(QiskitDevice):
Args:
wires (int or Iterable[Number, str]]): Number of subsystems represented by the device,
or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
or strings (``['ancilla', 'q1', 'q2']``).
or strings (``['aux_wire', 'q1', 'q2']``).
backend (str): the desired backend
shots (int or None): number of circuit evaluations/random samples used
to estimate expectation values and variances of observables. For statevector backends,
Expand All @@ -54,14 +57,60 @@ class BasicAerDevice(QiskitDevice):

def __init__(self, wires, shots=1024, backend="qasm_simulator", **kwargs):

max_ver = Version("0.45.3")
max_ver = Version("0.46", partial=True)

if Version(qiskit.__version__) > max_ver:
raise RuntimeError(
f"The devices in the PennyLane Qiskit plugin are currently only compatible "
f"with versions of Qiskit below 0.46. You have version {qiskit.__version__} "
f"installed. Please downgrade Qiskit to use the devices. The devices will be "
f"updated in the coming weeks to be compatible with Qiskit 1.0!"
f"Qiskit has discontinued the BasicAer device, so it can only be used in"
f"versions of Qiskit below 1.0. You have version {qiskit.__version__} "
f"installed. For a Python simulator, use the 'qiskit.basicsim' device "
f"instead. Alternatively, you can downgrade Qiskit to use the "
f"'qiskit.basicaer' device."
trbromley marked this conversation as resolved.
Show resolved Hide resolved
)

super().__init__(wires, provider=qiskit.BasicAer, backend=backend, shots=shots, **kwargs)


class BasicSimulatorDevice(QiskitDevice):
"""A PennyLane device for the native Python Qiskit simulator.

For more information on the ``BasicSimulator`` backend options and transpile options, please visit the
`BasicProvider documentation <https://docs.quantum.ibm.com/api/qiskit/providers_basic_provider>`_.
These options can be passed to this plugin device as keyword arguments.

Args:
wires (int or Iterable[Number, str]]): Number of subsystems represented by the device,
or iterable that contains unique labels for the subsystems as numbers (i.e., ``[-1, 0, 2]``)
or strings (``['aux_wire', 'q1', 'q2']``).
trbromley marked this conversation as resolved.
Show resolved Hide resolved
backend (str): the desired backend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the other option be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there is no other option here, but they add/change backends sometimes. Our default format for the device init functions so far has been that we don't worry about that - users can check backend options and pass what they want from the list of available backends. The list of available backends is in this case is ["basic_simulator"]. Maybe this should move to kwargs though? It's just here to match the other device signatures right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'd be a bit confused about the backend option. If I put backend='aer_simulator', things wouldn't work?

I'm happy to leave this in for now though, as the precedent is already set in other devices.

shots (int or None): number of circuit evaluations/random samples used
to estimate expectation values and variances of observables. For statevector backends,
setting to ``None`` results in computing statistics like expectation values and variances analytically.
trbromley marked this conversation as resolved.
Show resolved Hide resolved

Keyword Args:
name (str): The name of the circuit. Default ``'circuit'``.
compile_backend (BaseBackend): The backend used for compilation. If you wish
to simulate a device compliant circuit, you can specify a backend here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the only two kwargs one might want to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but we generally haven't documented allowed kwargs, because they are really determined by Qiskit, are backend-dependent, and we just pass them through. We don't have a complete list of options. I'll go over them and make sure we aren't missing any PennyLane specific ones though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't come up with any other PennyLane kwargs we would want to include here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'm thinking we remove these two, since I don't understand how or why I'd want to use them 😆

"""

short_name = "qiskit.basicsim"

analytic_warning_message = (
"The plugin does not currently support analytic calculation of expectations, variances "
"and probabilities with the BasicProvider backend {}. Such statistics obtained from this "
"device are estimates based on samples."
)

def __init__(self, wires, shots=1024, backend="basic_simulator", **kwargs):

min_version = Version("1.0.0")

if Version(qiskit.__version__) < min_version:
raise RuntimeError(
f"The 'qiskit.simulator' device is not compatible with version of Qiskit prior "
f"to 1.0. You have version {qiskit.__version__} installed. For a Python simulator, "
f"use the 'qiskit.basicaer' device instead. Alternatively, upgrade Qiskit "
f"(see https://docs.quantum.ibm.com/start/install) to use the 'qiskit.basicsim' device."
)

super().__init__(wires, provider=BasicProvider(), backend=backend, shots=shots, **kwargs)
Loading
Loading