Skip to content

Commit

Permalink
Compatibility with 1.0 for devices (PennyLaneAI#493)
Browse files Browse the repository at this point in the history
* remove deprecated installation syntax from test yaml

* run all the test vs Qiskit 1.0

* update to only raise error for BasicAer

* add missing import

* reorganize test parameterization for 1.0

* remove unused import

* add a BasicSimulator device

* import BasicSimulatorDevice

* update combinations of test devices and backends

* update devices and backends in integration tests

* update tests for incompatible devices and versions

* update QiskitDevice tests to use IBMQ instead of BasicAer

* tweak QiskitDevice for compatibility with BasicSimulator

* fix bad relative import path

* skip devices in  conftest with incompatible provider-backend combinations

* qasm_simulator is just qasm_simulator for old qiskit too now

* more fixes for combinations of providers and backends

* move import to top level

* update to supported backends in test_qiskit_device.py

* correct Regex pattern for error test

* update providers and backends in test_integration.py

* trigger ci

* use provider that doesn't requre token

* run device integration tests with 1.0

* correct backend for 1.0 device integration tests

* upload 1.0 test results to codecov

* add IBMQ tests with 1.0

* add basicsim device to documentation

* update install instructions

* update changelog

* update basicsim documentation

* update docstring for basicsim

* cutoff for basicaer is 0.46 instead of 0.45.3

* remove whitespace

* black formatting

* indicate partial version number

* small docs update

* Apply suggestions from code review

Co-authored-by: Thomas R. Bromley <[email protected]>

* rearrange order of device cards on docs page

* docs updates

* Update doc/devices/basicsim.rst

Co-authored-by: Thomas R. Bromley <[email protected]>

* add reference

* correct reference

* maybe it doesn't like underscores?

* update reference

* update refs

* add custom analytic not supported msg for BasicProvider device

* update warning

* remove unused import

* remove kwarg section of basic_simulator docstring

* trigger ci

* Unpin Qiskit where relevant (PennyLaneAI#508)

* update to use requirements-ci and requirements-ci-legacy

* unpin qiskit-ibm-runtime

* add explicit qiskit-ibm-runtime requirement

* unpin in upload yaml

* update changelog

* add codecov token for 1.0 tests

* add codecov token for 1.0 tests one more place

---------

Co-authored-by: Thomas R. Bromley <[email protected]>
  • Loading branch information
lillian542 and trbromley authored Apr 10, 2024
1 parent 18c3c7a commit e3f9482
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ibmq_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci.txt
pip install -r requirements-ci-legacy.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
pip freeze
Expand Down
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-ci.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 }}
9 changes: 5 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci.txt
pip install -r requirements-ci-legacy.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 Expand Up @@ -69,7 +70,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci.txt
pip install -r requirements-ci-legacy.txt
pip install wheel pytest pytest-cov pytest-mock pytest-benchmark flaky --upgrade
- name: Install Plugin
Expand Down
57 changes: 50 additions & 7 deletions .github/workflows/tests_qiskit_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,61 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-ci0.txt
pip install -r requirements-ci.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@v4
with:
token: ${{ secrets.codecov_token }}
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-ci.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
- 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@v4
with:
token: ${{ secrets.codecov_token }}
file: ./coverage.xml
2 changes: 1 addition & 1 deletion .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Build and install Plugin
run: |
python -m pip install --upgrade pip wheel
pip install 'qiskit<0.46'
pip install qiskit
python setup.py bdist_wheel
pip install dist/PennyLane*.whl
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@

### 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 🛠

* Following updates to allow device compatibility with Qiskit 1.0, the version of `qiskit-ibm-runtime` is
no longer capped.
[(#508)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/508)

* The test suite now runs with the most recent `qiskit` and `qiskit-ibm-runtime`, and well as with
`'qiskit==0.45'` and `qiskit-ibm-runtime<0.21` to monitor backward-compatibility.
[(#508)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/508)

### Breaking changes 💔

### Deprecations 👋
Expand All @@ -15,6 +29,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".
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
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
===================

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
Loading

0 comments on commit e3f9482

Please sign in to comment.