diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bc091c58..394418fc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - python-version: ["3.9", "3.10"] #3.8 + python-version: ["3.9", "3.10"] steps: - name: Checkout @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/qlasskit/qcircuit/qcircuitwrapper.py b/qlasskit/qcircuit/qcircuitwrapper.py index 980f04ca..44ea5f5d 100644 --- a/qlasskit/qcircuit/qcircuitwrapper.py +++ b/qlasskit/qcircuit/qcircuitwrapper.py @@ -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 diff --git a/test/test_qcircuit_exporters.py b/test/test_qcircuit_exporters.py index b07fb394..07f1c1e9 100644 --- a/test/test_qcircuit_exporters.py +++ b/test/test_qcircuit_exporters.py @@ -25,7 +25,6 @@ from .utils import qiskit_measure_and_count - def cx_circuit(): qc = QCircuit() a, b = qc.add_qubit(), qc.add_qubit() @@ -183,12 +182,12 @@ 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): @@ -196,7 +195,7 @@ 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)) diff --git a/test/test_qlassf_to_bqm.py b/test/test_qlassf_to_bqm.py index 0d73add4..561660ec 100644 --- a/test/test_qlassf_to_bqm.py +++ b/test/test_qlassf_to_bqm.py @@ -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() @@ -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) diff --git a/tox.ini b/tox.ini index 8cbfde70..66c90764 100644 --- a/tox.ini +++ b/tox.ini @@ -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 diff --git a/tox_3.8.ini b/tox_3.8.ini new file mode 100644 index 00000000..e9ca45ee --- /dev/null +++ b/tox_3.8.ini @@ -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} \ No newline at end of file diff --git a/tox_no_tw_and_pyqubo.ini b/tox_no_tw_and_pyqubo.ini new file mode 100644 index 00000000..437a9b45 --- /dev/null +++ b/tox_no_tw_and_pyqubo.ini @@ -0,0 +1,86 @@ +[tox] +envlist = linters,typecheck,unit-tests,coverage +requires = + tox>=4 +skipsdist=True + +; --override testenv.extras= +[testenv] +extras = +;tweedledum +deps = + sympy + numpy + matplotlib + qiskit + qiskit-aer + cirq + scipy + qutip + qutip_qip + pyqrack + qiskit-qrack-provider + pandas + pennylane + pennylane-lightning + +; 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 + +[testenv:isort] +deps = + ; {[testenv]deps} + isort +commands = + isort . + +[testenv:black] +deps = + ; {[testenv]deps} + black +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} \ No newline at end of file diff --git a/tox_no_tweedledum.ini b/tox_no_tweedledum.ini index 742d0880..d9ba194d 100644 --- a/tox_no_tweedledum.ini +++ b/tox_no_tweedledum.ini @@ -22,8 +22,8 @@ deps = qiskit-qrack-provider pandas pyqubo - pennylane==0.33.1 - pennylane-lightning==0.33.1 + pennylane + pennylane-lightning ; tweedledum