Skip to content

Commit

Permalink
Fixing ci (#44)
Browse files Browse the repository at this point in the history
Fix CI for 3.8 and 3.12
  • Loading branch information
dakk authored Apr 30, 2024
1 parent 23a53b8 commit ec56031
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 26 deletions.
72 changes: 61 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
python-version: ["3.9", "3.10"] #3.8
python-version: ["3.9", "3.10"]

steps:
- name: Checkout
Expand All @@ -25,12 +25,38 @@ jobs:
- name: Run tests
run: tox -e unit-tests #--override testenv.deps+=tweedledum --override testenv.extras=tweedledum

unit-tests-3_8:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.8"]

steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install dependencies
run: pip install tox

- name: Run tests
run: |
rm test/test_qcircuit_exporters.py
rm test/test_qlassf_to_bqm.py
tox -c tox_3.8.ini -e unit-tests
unit-tests-notw:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11"] #, "3.12"]
python-version: ["3.11"]

steps:
- name: Checkout
Expand All @@ -47,19 +73,43 @@ jobs:
- name: Run tests
run: tox -c tox_no_tweedledum.ini -e unit-tests


unit-tests-notw-nopyqubo:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.12"]

steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install dependencies
run: |
pip install tox
- name: Run tests
run: tox -c tox_no_tw_and_pyqubo.ini -e unit-tests

linters:
runs-on: ubuntu-latest
container:
image: cimg/python:3.8
image: cimg/python:3.11

steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install dependencies
run: pip install tox
Expand All @@ -70,16 +120,16 @@ jobs:
# coverage:
# runs-on: ubuntu-latest
# container:
# image: cimg/python:3.8
# image: cimg/python:3.11

# steps:
# - name: Checkout
# uses: actions/checkout@v2

# - name: Set up Python 3.8
# - name: Set up Python 3.11
# uses: actions/setup-python@v2
# with:
# python-version: 3.8
# python-version: 3.11

# - name: Install dependencies
# run: pip install tox
Expand All @@ -90,16 +140,16 @@ jobs:
typecheck:
runs-on: ubuntu-latest
container:
image: cimg/python:3.8
image: cimg/python:3.11

steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install dependencies
run: pip install tox
Expand Down
2 changes: 1 addition & 1 deletion qlasskit/qcircuit/qcircuitwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self):
@property
def num_qubits(self):
return self._qcircuit.num_qubits

@property
def num_gates(self):
return self._qcircuit.num_gates
Expand Down
13 changes: 6 additions & 7 deletions test/test_qcircuit_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from .utils import qiskit_measure_and_count


def cx_circuit():
qc = QCircuit()
a, b = qc.add_qubit(), qc.add_qubit()
Expand Down Expand Up @@ -183,20 +182,20 @@ def test_export_cirq_gate(self):


@parameterized_class(
("qc", "result"),
("qc", "result", "wires"),
[
(cx_circuit(), [0, 0, 0, 1]),
(ccx_circuit(), [0, 0, 0, 0, 0, 0, 0, 1]),
(bell_circuit(), [0.5, 0, 0, 0.5]),
(qft_circuit(), [1, 0, 0, 0, 0, 0, 0, 0]),
(cx_circuit(), [0, 0, 0, 1], 2),
(ccx_circuit(), [0, 0, 0, 0, 0, 0, 0, 1], 3),
(bell_circuit(), [0.5, 0, 0, 0.5], 2),
(qft_circuit(), [1, 0, 0, 0, 0, 0, 0, 0], 3),
],
)
class TestQCircuitExportPennylane(unittest.TestCase):
def test_export_pennylane_circuit(self):
tape = self.qc.export("circuit", "pennylane")
tape = qml.tape.QuantumTape(tape.operations, [qml.probs()])

dev = qml.device("default.qubit", wires=2)
dev = qml.device("default.qubit", wires=self.wires)
r = qml.execute([tape], dev, gradient_fn=None)

self.assertEqual(len(r[0]), len(self.result))
Expand Down
23 changes: 20 additions & 3 deletions test/test_qlassf_to_bqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# import os
import sys
import unittest

import dimod
import neal

from qlasskit import qlassf
from qlasskit.bqm import decode_samples

# pyqubo doesn't work on python 3.12
DISABLE_BQM_TESTS = False

# os.getenv("GITHUB_ACTIONS") and
if sys.version_info.major == 3 and sys.version_info.minor == 12:
try:
import dimod
import neal
except:
DISABLE_BQM_TESTS = True
else:
import dimod
import neal


def sample_bqm(bqm, reads=10):
sa = neal.SimulatedAnnealingSampler()
Expand All @@ -33,6 +46,10 @@ def sample_qubo(qubo):


class TestQlassfToBQM(unittest.TestCase):
def setUp(self):
if DISABLE_BQM_TESTS:
self.skipTest("Skipping this test")

def test_to_bqm_1(self):
f = "def test(a: bool) -> bool:\n\treturn not a"
qf = qlassf(f, to_compile=False)
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ deps =
pandas
tweedledum
pyqubo
pennylane==0.33.1
pennylane-lightning==0.33.1
pennylane
pennylane-lightning

commands =
python -I -m build --wheel -C=--build-option=-- -C=--build-option=-- -C=--build-option=-j4
Expand Down
79 changes: 79 additions & 0 deletions tox_3.8.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[tox]
envlist = linters,typecheck,unit-tests,coverage
requires =
tox>=4
skipsdist=True

[testenv]
extras = tweedledum
deps =
sympy
numpy
matplotlib
qiskit
qiskit-aer
scipy
pyqrack
qiskit-qrack-provider
pandas
tweedledum

commands =
python -I -m build --wheel -C=--build-option=-- -C=--build-option=-- -C=--build-option=-j4

[testenv:coverage]
deps =
{[testenv]deps}
pytest
pytest-cov
parameterized
commands =
pytest --cov-report term-missing --cov-report html --cov-report xml --cov=qlasskit

[testenv:unit-tests]
deps =
{[testenv]deps}
pytest
parameterized
commands =
pytest #-rP

[testenv:flake8]
deps =
; {[testenv]deps}
flake8
commands =
flake8 ./qlasskit
flake8 ./test

[testenv:isort]
deps =
; {[testenv]deps}
isort
commands =
isort .

[testenv:black]
deps =
; {[testenv]deps}
black[jupyter]
commands =
black .

[testenv:typecheck]
deps =
; {[testenv]deps}
mypy
types-setuptools
commands =
mypy --check-untyped-defs qlasskit

[testenv:linters]
deps =
{[testenv:isort]deps}
{[testenv:black]deps}
{[testenv:flake8]deps}
commands =
{[testenv:isort]commands}
{[testenv:black]commands}
{[testenv:flake8]commands}
Loading

0 comments on commit ec56031

Please sign in to comment.