From 4a4d96233aeb95ad36169192fba28ebf96423875 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 9 Oct 2024 17:27:34 +0200 Subject: [PATCH] fix: :recycle: Fix mypy issues --- pyproject.toml | 4 ++-- src/mqt/qubomaker/graph.py | 4 ++-- src/mqt/qubomaker/pathfinder/cost_functions.py | 2 +- tests/resources/graph/graph | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1693ad5..8de85be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,7 +114,7 @@ report.exclude_also = [ [tool.mypy] mypy_path = "$MYPY_CONFIG_FILE_DIR/src,$MYPY_CONFIG_FILE_DIR/stubs" files = ["src", "tests"] -python_version = "3.8" +python_version = "3.9" strict = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] warn_unreachable = true @@ -122,7 +122,7 @@ explicit_package_bases = true pretty = true [[tool.mypy.overrides]] -module = ["types-Pillow", "jsonschema", "tsplib95.*", "ipywidgets.*", "IPython.*", "qiskit.*", "qiskit_algorithms.*", "matplotlib.*", "networkx.*", "mqt.ddsim.*", "joblib.*", "qiskit_optimization.*", "docplex.*", "typing_extensions.*"] +module = ["types-Pillow", "jsonschema", "tsplib95.*", "ipywidgets.*", "IPython.*", "qiskit.*", "qiskit_algorithms.*", "matplotlib.*", "networkx.*", "mqt.ddsim.*", "joblib.*", "qiskit_optimization.*", "docplex.*", "typing_extensions.*", "numpy.*"] ignore_missing_imports = true [tool.ruff] diff --git a/src/mqt/qubomaker/graph.py b/src/mqt/qubomaker/graph.py index 19de119..4e495d6 100644 --- a/src/mqt/qubomaker/graph.py +++ b/src/mqt/qubomaker/graph.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Tuple, Union +from typing import TYPE_CHECKING, Tuple, Union, cast import networkx as nx import numpy as np @@ -162,7 +162,7 @@ def __eq__(self, value: object) -> bool: """ if not isinstance(value, Graph): return False - return np.array_equal(self.adjacency_matrix, value.adjacency_matrix) + return cast(bool, np.array_equal(self.adjacency_matrix, value.adjacency_matrix)) def __hash__(self) -> int: """Returns the hash of the graph. diff --git a/src/mqt/qubomaker/pathfinder/cost_functions.py b/src/mqt/qubomaker/pathfinder/cost_functions.py index 64b976f..65de0ae 100644 --- a/src/mqt/qubomaker/pathfinder/cost_functions.py +++ b/src/mqt/qubomaker/pathfinder/cost_functions.py @@ -1284,7 +1284,7 @@ def get_variable_function(p: Any, v: Any, i: Any, _n: int = 0) -> sp.Expr: @override def get_formula_domain_wall(self, graph: Graph, settings: pathfinder.PathFindingQUBOGeneratorSettings) -> sp.Expr: general = self.get_formula_general(graph, settings, FormulaHelpers.get_encoding_variable_domain_wall) - enforce_domain_wall_penalty = ( + enforce_domain_wall_penalty: sp.Expr = ( 2 * settings.max_path_length * np.max(graph.adjacency_matrix) + graph.n_vertices**2 ) # This ensures that the domain wall condition (x_i = 0 -> x_{i+1} = 0) is not broken to achieve better cost in other cost functions. diff --git a/tests/resources/graph/graph b/tests/resources/graph/graph index 6a04315..0bea677 100644 --- a/tests/resources/graph/graph +++ b/tests/resources/graph/graph @@ -2,4 +2,4 @@ 0. 0. 0. 3. 0. 0. 0. 0. 0. 2. 0. 0. 0. 0. 5. -1. 0. 0. 0. 0. \ No newline at end of file +1. 0. 0. 0. 0.