Skip to content

Commit

Permalink
[SDS-1088] Qiskit 46 support (#167)
Browse files Browse the repository at this point in the history
* qiskit 46 support

* github actions warnings solved

* github action repair

* deprecated workflows
  • Loading branch information
QFer authored Feb 16, 2024
1 parent 567cd59 commit b10e8cb
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 111 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/github-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: SDK build and test

on:
push:
branches:
- dev
pull_request:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 3
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

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

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade .[qiskit,projectq,dev] coveralls
- name: Run Tests
run: |
echo "running unit tests"
coverage run --source="./src/quantuminspire" -m unittest discover -s src/tests -t src -v
echo "running mypy"
MYPYPATH=./src mypy --strict --ignore-missing-imports -p quantuminspire
echo "running pylint"
pylint quantuminspire || true
echo "running examples"
python ./docs/examples/example_projectq_entangle.py
python ./docs/examples/example_projectq_grover.py
python ./docs/examples/example_qiskit_conditional.py
python ./docs/examples/example_qiskit_entangle.py
echo "running notebooks"
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 docs/examples/example_projectq.ipynb
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 docs/examples/grover_algorithm_qi.ipynb
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 docs/examples/qi-performance-test.ipynb
env:
API_URL: https://api.quantum-inspire.com
QI_TOKEN: ${{ secrets.QI_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:

steps:
- name: Checkout Quantum Inspire SDK
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Clone Qiskit-terra
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: qiskit/qiskit-terra
path: qiskit-terra
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: pip install prerequisites
Expand Down
51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions docs/examples/example_projectq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"output_type": "stream",
"text": [
"Measured 0,0,0,0,0\n",
"Probabilities: {'10001': 0.525390625, '00000': 0.474609375}\n",
"Probabilities: {'10001': 0.4892578125, '00000': 0.5107421875}\n",
"version 1.0\n",
"# cQASM generated by Quantum Inspire <class 'quantuminspire.projectq.backend_qx.QIBackend'> class\n",
"qubits 5\n",
Expand Down Expand Up @@ -132,8 +132,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Measured 1,0,0,0,1\n",
"Probabilities: {'10001': 0.501953125, '00000': 0.498046875}\n",
"Measured 0,0,0,0,0\n",
"Probabilities: {'00000': 0.505859375, '10001': 0.494140625}\n",
"version 1.0\n",
"# cQASM generated by Quantum Inspire <class 'quantuminspire.projectq.backend_qx.QIBackend'> class\n",
"qubits 5\n",
Expand Down Expand Up @@ -219,9 +219,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
12 changes: 8 additions & 4 deletions docs/examples/example_qiskit_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"""
import os

from qiskit import BasicAer, execute
from qiskit import transpile
from qiskit.providers.basic_provider import BasicProvider
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit

from quantuminspire.credentials import get_authentication
Expand All @@ -40,15 +41,18 @@
qc.measure(q[1], c1)
qc.measure(q[2], c2)

qi_job = execute(qc, backend=qi_backend, shots=1024)
qc = transpile(qc, backend=qi_backend)
qi_job = qi_backend.run(qc, shots=1024)
qi_result = qi_job.result()
histogram = qi_result.get_counts(qc)
print("\nResult from the remote Quantum Inspire backend:\n")
print('State\tCounts')
[print('{0}\t{1}'.format(state, counts)) for state, counts in histogram.items()]

print("\nResult from the local Qiskit simulator backend:\n")
backend = BasicAer.get_backend("qasm_simulator")
job = execute(qc, backend=backend, shots=1024)
backend = BasicProvider().get_backend(name="basic_simulator") # qasm_simulator
qc = transpile(qc, backend=backend)
job = backend.run(qc, shots=1024)

result = job.result()
print(result.get_counts(qc))
5 changes: 3 additions & 2 deletions docs/examples/example_qiskit_entangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
import os

from qiskit import execute
from qiskit import transpile
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit

from quantuminspire.credentials import get_authentication
Expand All @@ -36,7 +36,8 @@
circuit.cx(q[0], q[1])
circuit.measure(q, b)

qi_job = execute(circuit, backend=qi_backend, shots=256)
circuit = transpile(circuit, backend=qi_backend)
qi_job = qi_backend.run(circuit, shots=256)
qi_result = qi_job.result()
histogram = qi_result.get_counts(circuit)
print('\nState\tCounts')
Expand Down
69 changes: 46 additions & 23 deletions docs/examples/grover_algorithm_qi.ipynb

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions docs/examples/qi-performance-test.ipynb

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ def get_long_description():
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'License :: OSI Approved :: Apache Software License'],
license='Apache 2.0',
packages=['quantuminspire', 'quantuminspire.qiskit', 'quantuminspire.projectq'],
install_requires=['coverage>=4.5.1', 'matplotlib>=2.1', 'pylatexenc', 'coreapi>=2.3.3', 'numpy>=1.20', 'jupyter',
'nbimporter', 'qilib'],
'nbimporter', 'qilib', 'setuptools'],
extras_require={
'qiskit': ["qiskit>=0.40.0", 'qiskit-aer'],
'projectq': ["projectq>=0.4"],
'dev': ['pytest>=3.3.1', "pylint", "mypy>=0.670"],
'rtd': ['sphinx', 'sphinx_rtd_theme', 'nbsphinx', 'sphinx-automodapi', 'recommonmark'],
"qiskit": ["qiskit>=0.46,<1.0", "qiskit-aer"],
"projectq": ["projectq>=0.8.0"],
"dev": ["pytest>=3.3.1", "pylint", "mypy>=0.670"],
"rtd": ["sphinx", "sphinx_rtd_theme", "nbsphinx", "sphinx-automodapi", "recommonmark"],
})
17 changes: 9 additions & 8 deletions src/quantuminspire/qiskit/qi_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@
class QIJob(Job): # type: ignore
"""
A Qiskit job that is executed on the Quantum Inspire platform. A QIJob is normally created by calling
``execute`` (which triggers a `run` on the QuantumInspireBackend ``qi_backend``).
``run`` on QuantumInspireBackend ``qi_backend``.
.. code::
.. code-block:: python
qc = QuantumCircuit(5, 5)
qc.h(0)
qc.cx(0, range(1, 5))
qc.measure_all()
job = execute(qc, qi_backend, shots=1024)
qc = transpile(qc, qi_backend)
job = qi_backend.run(qc, shots=1024)
result = job.result()
The return value of ``execute`` is an instance of QIJob (Qiskit job) and is the equivalent to the Quantum
The return value of ``run`` is an instance of QIJob (Qiskit job) and is the equivalent to the Quantum
Inspire project. It is a container to handle one or more (asynchronous) Qiskit circuits or experiments.
A Qiskit circuit is equivalent to a Quantum Inspire job.
Expand Down Expand Up @@ -190,21 +191,21 @@ def add_job(self, job: QuantumInspireJob) -> None:
""" Add a Quantum Inspire job to the list. The list contains the (Quantum Inspire) jobs created for the
submitted experiments in this particular QIJob.
:param job: QuatumInspireJob (submitted) that has to be added to the list of jobs created for the experiments
:param job: QuantumInspireJob (submitted) that has to be added to the list of jobs created for the experiments
in QIJob.
"""
self.jobs.append(job)

def queue_position(self, refresh: bool = False) -> Optional[int]:
"""
Return the position for this Job in the Quantum Inspire queue (when in status QUEUED).
Currently we don't have this info available.
Currently, we don't have this info available.
:param refresh: If ``True``, re-query the server to get the latest value.
Otherwise return the cached value, when available. Not used.
Otherwise, return the cached value, when available. Not used.
:return:
The queue position of the job. Currently None (not available).
The queue position of the job. Currently, None (not available).
"""
return None

Expand Down
2 changes: 1 addition & 1 deletion src/tests/quantuminspire/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_qi_job_invalid_job_identifier(self):
api.get_job.side_effect = ErrorMessage('TestMock')
job_identifier = 1
self.assertRaises(ValueError, QuantumInspireJob, api, job_identifier)
api.get_job.called_once()
api.get_job.assert_called_once()

def test_check_status(self):
expected = 'RUNNING'
Expand Down

0 comments on commit b10e8cb

Please sign in to comment.