From f6ffcdfc9cff7a813be589540ff3ee476a8c308f Mon Sep 17 00:00:00 2001 From: nikhilkhatri Date: Mon, 14 Oct 2024 16:50:32 +0100 Subject: [PATCH 1/2] Fix CI collection --- .github/workflows/build_test.yml | 10 +++------- lambeq/backend/converters/tk.py | 2 +- lambeq/backend/grammar.py | 4 +++- pyproject.toml | 1 + setup.cfg | 2 +- tests/training/test_pennylane_model.py | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 06e9a5c4..dd4e8571 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -59,10 +59,6 @@ jobs: run: pip install . - name: Check package import works run: python -c 'import lambeq' - - name: Install downgraded Qiskit (for compatibility reasons) - # This should be removed once the following PR is merged: - # https://github.com/PennyLaneAI/pennylane-qiskit/pull/493 - run: pip install 'qiskit<1' pytket-qiskit qiskit-ibm-runtime - name: Install extra dependencies and tester run: pip install .[extras] .[test] - name: Locate bobcat pre-trained model cache @@ -77,10 +73,10 @@ jobs: - name: Test with pytest run: > coverage run --source=${{ env.SRC_DIR }} - --module pytest ${{ env.SRC_DIR }} ${{ env.TEST_DIR }} - --doctest-modules + --module pytest ${{ env.TEST_DIR }} --durations=50 --ignore=${{ env.TEST_DIR }}/text2diagram/test_depccg_parser.py + --ignore=${{ env.TEST_DIR }}/training/test_torchquantum_model.py - name: Coverage report run: coverage report -m type_check: @@ -97,7 +93,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install dependencies with type hints - run: python -m pip install numpy pytket spacy torch types-PyYAML types-Pillow ipython + run: python -m pip install "numpy<2.0" "matplotlib>=3.8" pytket spacy torch types-PyYAML types-Pillow ipython - name: Install type checker run: python -m pip install mypy - name: Type check with mypy diff --git a/lambeq/backend/converters/tk.py b/lambeq/backend/converters/tk.py index 9d4acc77..5b1efb05 100644 --- a/lambeq/backend/converters/tk.py +++ b/lambeq/backend/converters/tk.py @@ -419,7 +419,7 @@ def box_and_offset_from_tk(tk_gate) -> tuple[Diagram, int]: left = circuit.cod[:offset] right = circuit.cod[offset + len(box.dom):] circuit = circuit >> left @ box @ right - circuit = circuit >> Id().tensor(*( # type: ignore[arg-type] + circuit = circuit >> Id().tensor(*( Bra(bras[i]) if i in bras else Discard() if x == qubit else Id(bit) for i, x in enumerate(circuit.cod))) diff --git a/lambeq/backend/grammar.py b/lambeq/backend/grammar.py index 2aab6381..82c145c8 100644 --- a/lambeq/backend/grammar.py +++ b/lambeq/backend/grammar.py @@ -244,7 +244,9 @@ def rotate(self, z: int) -> Self: return replace(self, z=self.z + z) else: objects = reversed(self.objects) if z % 2 == 1 else self.objects - return type(self)(objects=[ob.rotate(z) for ob in objects]) + return type(self)( + objects=[ob.rotate(z) + for ob in objects]) # type: ignore[union-attr] def unwind(self) -> Self: return self.rotate(-self.z) diff --git a/pyproject.toml b/pyproject.toml index aeb6e2fc..a9bc35f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,3 +44,4 @@ strict_optional = false [tool.setuptools_scm] write_to = "lambeq/version.py" + diff --git a/setup.cfg b/setup.cfg index dfb0bb1e..5c709357 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,7 @@ packages = lambeq.tokeniser lambeq.training install_requires = - matplotlib >= 3.1.2 + matplotlib >= 3.8 packaging pillow >= 6.2.1 pytket >= 1.31.0 diff --git a/tests/training/test_pennylane_model.py b/tests/training/test_pennylane_model.py index 86b5312e..7af1f4f0 100644 --- a/tests/training/test_pennylane_model.py +++ b/tests/training/test_pennylane_model.py @@ -198,7 +198,7 @@ def test_backends(): >> Cup(N, N.r) @ Id(S))) diagrams = [diagram] - from qiskit.providers.aer.noise import NoiseModel + from qiskit_aer.noise import NoiseModel noise_model = NoiseModel() backend_config = {'backend': 'qiskit.aer', From c63d8d69157c57b336e942b95697c13e6cc81f34 Mon Sep 17 00:00:00 2001 From: nikhilkhatri Date: Mon, 14 Oct 2024 17:01:40 +0100 Subject: [PATCH 2/2] Remove redundant type ignores around matplotlib --- lambeq/backend/drawing/mat_backend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambeq/backend/drawing/mat_backend.py b/lambeq/backend/drawing/mat_backend.py index a07867c2..923036b6 100644 --- a/lambeq/backend/drawing/mat_backend.py +++ b/lambeq/backend/drawing/mat_backend.py @@ -20,9 +20,9 @@ from __future__ import annotations -from matplotlib.patches import PathPatch # type: ignore[import-not-found] -from matplotlib.path import Path # type: ignore[import-not-found] -import matplotlib.pyplot as plt # type: ignore[import-not-found] +from matplotlib.patches import PathPatch +from matplotlib.path import Path +import matplotlib.pyplot as plt from lambeq.backend.drawing.drawable import DrawableDiagram from lambeq.backend.drawing.drawing_backend import (COLORS, DEFAULT_MARGINS,