Skip to content

Commit b10e8cb

Browse files
authored
[SDS-1088] Qiskit 46 support (#167)
* qiskit 46 support * github actions warnings solved * github action repair * deprecated workflows
1 parent 567cd59 commit b10e8cb

File tree

11 files changed

+152
-111
lines changed

11 files changed

+152
-111
lines changed

.github/workflows/github-ci.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: SDK build and test
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
pull_request:
8+
branches:
9+
- dev
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: true
16+
max-parallel: 3
17+
matrix:
18+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install Dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install --upgrade .[qiskit,projectq,dev] coveralls
32+
33+
- name: Run Tests
34+
run: |
35+
echo "running unit tests"
36+
coverage run --source="./src/quantuminspire" -m unittest discover -s src/tests -t src -v
37+
echo "running mypy"
38+
MYPYPATH=./src mypy --strict --ignore-missing-imports -p quantuminspire
39+
echo "running pylint"
40+
pylint quantuminspire || true
41+
echo "running examples"
42+
python ./docs/examples/example_projectq_entangle.py
43+
python ./docs/examples/example_projectq_grover.py
44+
python ./docs/examples/example_qiskit_conditional.py
45+
python ./docs/examples/example_qiskit_entangle.py
46+
echo "running notebooks"
47+
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 docs/examples/example_projectq.ipynb
48+
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 docs/examples/grover_algorithm_qi.ipynb
49+
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 docs/examples/qi-performance-test.ipynb
50+
env:
51+
API_URL: https://api.quantum-inspire.com
52+
QI_TOKEN: ${{ secrets.QI_TOKEN }}

.github/workflows/nightly.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212

1313
steps:
1414
- name: Checkout Quantum Inspire SDK
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616
- name: Clone Qiskit-terra
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1818
with:
1919
repository: qiskit/qiskit-terra
2020
path: qiskit-terra
2121
- name: Set up Python 3.8
22-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: 3.8
2525
- name: pip install prerequisites

.travis.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

docs/examples/example_projectq.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"output_type": "stream",
7474
"text": [
7575
"Measured 0,0,0,0,0\n",
76-
"Probabilities: {'10001': 0.525390625, '00000': 0.474609375}\n",
76+
"Probabilities: {'10001': 0.4892578125, '00000': 0.5107421875}\n",
7777
"version 1.0\n",
7878
"# cQASM generated by Quantum Inspire <class 'quantuminspire.projectq.backend_qx.QIBackend'> class\n",
7979
"qubits 5\n",
@@ -132,8 +132,8 @@
132132
"name": "stdout",
133133
"output_type": "stream",
134134
"text": [
135-
"Measured 1,0,0,0,1\n",
136-
"Probabilities: {'10001': 0.501953125, '00000': 0.498046875}\n",
135+
"Measured 0,0,0,0,0\n",
136+
"Probabilities: {'00000': 0.505859375, '10001': 0.494140625}\n",
137137
"version 1.0\n",
138138
"# cQASM generated by Quantum Inspire <class 'quantuminspire.projectq.backend_qx.QIBackend'> class\n",
139139
"qubits 5\n",
@@ -219,9 +219,9 @@
219219
"name": "python",
220220
"nbconvert_exporter": "python",
221221
"pygments_lexer": "ipython3",
222-
"version": "3.8.6"
222+
"version": "3.12.2"
223223
}
224224
},
225225
"nbformat": 4,
226-
"nbformat_minor": 2
226+
"nbformat_minor": 4
227227
}

docs/examples/example_qiskit_conditional.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"""
1414
import os
1515

16-
from qiskit import BasicAer, execute
16+
from qiskit import transpile
17+
from qiskit.providers.basic_provider import BasicProvider
1718
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
1819

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

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

5052
print("\nResult from the local Qiskit simulator backend:\n")
51-
backend = BasicAer.get_backend("qasm_simulator")
52-
job = execute(qc, backend=backend, shots=1024)
53+
backend = BasicProvider().get_backend(name="basic_simulator") # qasm_simulator
54+
qc = transpile(qc, backend=backend)
55+
job = backend.run(qc, shots=1024)
56+
5357
result = job.result()
5458
print(result.get_counts(qc))

docs/examples/example_qiskit_entangle.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515
import os
1616

17-
from qiskit import execute
17+
from qiskit import transpile
1818
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
1919

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

39-
qi_job = execute(circuit, backend=qi_backend, shots=256)
39+
circuit = transpile(circuit, backend=qi_backend)
40+
qi_job = qi_backend.run(circuit, shots=256)
4041
qi_result = qi_job.result()
4142
histogram = qi_result.get_counts(circuit)
4243
print('\nState\tCounts')

docs/examples/grover_algorithm_qi.ipynb

Lines changed: 46 additions & 23 deletions
Large diffs are not rendered by default.

docs/examples/qi-performance-test.ipynb

Lines changed: 19 additions & 9 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ def get_long_description():
5656
'Programming Language :: Python :: 3.9',
5757
'Programming Language :: Python :: 3.10',
5858
'Programming Language :: Python :: 3.11',
59+
'Programming Language :: Python :: 3.12',
5960
'License :: OSI Approved :: Apache Software License'],
6061
license='Apache 2.0',
6162
packages=['quantuminspire', 'quantuminspire.qiskit', 'quantuminspire.projectq'],
6263
install_requires=['coverage>=4.5.1', 'matplotlib>=2.1', 'pylatexenc', 'coreapi>=2.3.3', 'numpy>=1.20', 'jupyter',
63-
'nbimporter', 'qilib'],
64+
'nbimporter', 'qilib', 'setuptools'],
6465
extras_require={
65-
'qiskit': ["qiskit>=0.40.0", 'qiskit-aer'],
66-
'projectq': ["projectq>=0.4"],
67-
'dev': ['pytest>=3.3.1', "pylint", "mypy>=0.670"],
68-
'rtd': ['sphinx', 'sphinx_rtd_theme', 'nbsphinx', 'sphinx-automodapi', 'recommonmark'],
66+
"qiskit": ["qiskit>=0.46,<1.0", "qiskit-aer"],
67+
"projectq": ["projectq>=0.8.0"],
68+
"dev": ["pytest>=3.3.1", "pylint", "mypy>=0.670"],
69+
"rtd": ["sphinx", "sphinx_rtd_theme", "nbsphinx", "sphinx-automodapi", "recommonmark"],
6970
})

src/quantuminspire/qiskit/qi_job.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@
3535
class QIJob(Job): # type: ignore
3636
"""
3737
A Qiskit job that is executed on the Quantum Inspire platform. A QIJob is normally created by calling
38-
``execute`` (which triggers a `run` on the QuantumInspireBackend ``qi_backend``).
38+
``run`` on QuantumInspireBackend ``qi_backend``.
3939
40-
.. code::
40+
.. code-block:: python
4141
4242
qc = QuantumCircuit(5, 5)
4343
qc.h(0)
4444
qc.cx(0, range(1, 5))
4545
qc.measure_all()
4646
47-
job = execute(qc, qi_backend, shots=1024)
47+
qc = transpile(qc, qi_backend)
48+
job = qi_backend.run(qc, shots=1024)
4849
result = job.result()
4950
50-
The return value of ``execute`` is an instance of QIJob (Qiskit job) and is the equivalent to the Quantum
51+
The return value of ``run`` is an instance of QIJob (Qiskit job) and is the equivalent to the Quantum
5152
Inspire project. It is a container to handle one or more (asynchronous) Qiskit circuits or experiments.
5253
A Qiskit circuit is equivalent to a Quantum Inspire job.
5354
@@ -190,21 +191,21 @@ def add_job(self, job: QuantumInspireJob) -> None:
190191
""" Add a Quantum Inspire job to the list. The list contains the (Quantum Inspire) jobs created for the
191192
submitted experiments in this particular QIJob.
192193
193-
:param job: QuatumInspireJob (submitted) that has to be added to the list of jobs created for the experiments
194+
:param job: QuantumInspireJob (submitted) that has to be added to the list of jobs created for the experiments
194195
in QIJob.
195196
"""
196197
self.jobs.append(job)
197198

198199
def queue_position(self, refresh: bool = False) -> Optional[int]:
199200
"""
200201
Return the position for this Job in the Quantum Inspire queue (when in status QUEUED).
201-
Currently we don't have this info available.
202+
Currently, we don't have this info available.
202203
203204
:param refresh: If ``True``, re-query the server to get the latest value.
204-
Otherwise return the cached value, when available. Not used.
205+
Otherwise, return the cached value, when available. Not used.
205206
206207
:return:
207-
The queue position of the job. Currently None (not available).
208+
The queue position of the job. Currently, None (not available).
208209
"""
209210
return None
210211

0 commit comments

Comments
 (0)