diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a8fcc4a75..dbd6a8fa6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,26 +49,22 @@ repos: - id: rst-directive-colons - id: rst-inline-touching-normal - # Run ruff (subsumes pyupgrade, isort, flake8+plugins, and more) + # Python linting using ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.1 + rev: v0.1.3 hooks: - id: ruff args: ["--fix", "--show-fixes"] - - # Run code formatting with Black - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.10.0 # Keep in sync with blacken-docs - hooks: - - id: black-jupyter + types_or: [python, pyi, jupyter] + - id: ruff-format + types_or: [python, pyi, jupyter] # Also run Black on examples in the documentation - repo: https://github.com/adamchainz/blacken-docs rev: 1.16.0 hooks: - id: blacken-docs - additional_dependencies: - - black==23.10.0 # keep in sync with black hook + additional_dependencies: [black==23.*] # Check static types with mypy - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/docs/source/Synthesis.ipynb b/docs/source/Synthesis.ipynb index 13fc64b29..1012b44af 100644 --- a/docs/source/Synthesis.ipynb +++ b/docs/source/Synthesis.ipynb @@ -174,6 +174,7 @@ "outputs": [], "source": [ "from qiskit import QuantumCircuit\n", + "\n", "from mqt import qmap\n", "\n", "qc = QuantumCircuit(2)\n", @@ -205,6 +206,7 @@ "outputs": [], "source": [ "from qiskit import QuantumCircuit\n", + "\n", "from mqt import qmap\n", "\n", "qc = QuantumCircuit(2)\n", @@ -239,6 +241,7 @@ "outputs": [], "source": [ "from qiskit import QuantumCircuit\n", + "\n", "from mqt import qmap\n", "\n", "qc = QuantumCircuit(2)\n", diff --git a/pyproject.toml b/pyproject.toml index 4f571a54a..729f07046 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -145,9 +145,6 @@ report.exclude_also = [ 'if TYPE_CHECKING:', ] -[tool.black] -line-length = 120 - [tool.mypy] files = ["src/mqt", "test/python"] mypy_path = ["$MYPY_CONFIG_FILE_DIR/src"] @@ -165,9 +162,14 @@ ignore_missing_imports = true [tool.ruff] -include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"] -select = [ - "E", "F", "W", # flake8 +line-length = 120 +extend-include = ["*.ipynb"] +src = ["src"] +preview = true +unsafe-fixes = true + +[tool.ruff.lint] +extend-select = [ "A", # flake8-builtins "ANN", # flake8-annotations "ARG", # flake8-unused-arguments @@ -207,15 +209,11 @@ select = [ extend-ignore = [ "ANN101", # Missing type annotation for self in method "ANN102", # Missing type annotation for cls in classmethod - "E501", # Line too long (Black is enough) "PLR", # Design related pylint codes ] -src = ["src"] -flake8-unused-arguments.ignore-variadic-names = true isort.required-imports = ["from __future__ import annotations"] -line-length = 120 -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "*.pyi" = ["D"] # pydocstyle "*.ipynb" = [ "D", # pydocstyle diff --git a/src/mqt/qmap/pyqmap.pyi b/src/mqt/qmap/pyqmap.pyi index b472c0962..73261ad20 100644 --- a/src/mqt/qmap/pyqmap.pyi +++ b/src/mqt/qmap/pyqmap.pyi @@ -20,7 +20,7 @@ class Arch: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -97,7 +97,7 @@ class CommanderGrouping: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -152,7 +152,7 @@ class Encoding: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -175,7 +175,7 @@ class InitialLayout: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -200,7 +200,7 @@ class Layering: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -234,7 +234,7 @@ class Method: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -258,7 +258,7 @@ class SwapReduction: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -283,7 +283,7 @@ class TargetMetric: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... @@ -310,7 +310,7 @@ class Verbosity: def __eq__(self, other: object) -> bool: ... def __getstate__(self) -> int: ... def __hash__(self) -> int: ... - def __index__(self) -> int: ... + def __index__(self) -> int: ... # noqa: PLW3201 def __int__(self) -> int: ... def __ne__(self, other: object) -> bool: ... def __setstate__(self, state: int) -> None: ... diff --git a/src/mqt/qmap/subarchitectures.py b/src/mqt/qmap/subarchitectures.py index 210e8798b..299c95699 100644 --- a/src/mqt/qmap/subarchitectures.py +++ b/src/mqt/qmap/subarchitectures.py @@ -25,7 +25,6 @@ from . import Architecture - import contextlib import rustworkx as rx @@ -34,7 +33,6 @@ with contextlib.suppress(TypeError): Graph: TypeAlias = rx.PyGraph[int, Optional[int]] - PartialOrder = NewType("PartialOrder", Dict[Tuple[int, int], Set[Tuple[int, int]]]) #: Architectures for which precomputed orderings are available @@ -291,9 +289,7 @@ def __compute_subarch_order(self) -> None: matcher = rx.graph_vf2_mapping(parent_sg, sg, subgraph=True) # type: ignore[attr-defined] for iso in matcher: self.subarch_order[(n, i)].add((n + 1, j)) - iso_rev = {} - for key, val in iso.items(): - iso_rev[val] = key + iso_rev = {val: key for key, val in iso.items()} self.isomorphisms[(n, i)][(n + 1, j)] = iso_rev break # One isomorphism suffices