From 6cac8d3240bffc097b13d3c9b6c951d117c3524d Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 30 Aug 2024 11:28:14 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20fix=20mypy=20warning=20by=20maki?= =?UTF-8?q?ng=20typing=20more=20explicit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- src/mqt/qcec/compilation_flow_profiles.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/mqt/qcec/compilation_flow_profiles.py b/src/mqt/qcec/compilation_flow_profiles.py index 9e87b48c..03e401f3 100644 --- a/src/mqt/qcec/compilation_flow_profiles.py +++ b/src/mqt/qcec/compilation_flow_profiles.py @@ -4,12 +4,15 @@ from enum import Enum, unique from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any import numpy as np from qiskit import QuantumCircuit, transpile from qiskit import __version__ as qiskit_version +if TYPE_CHECKING: + from numpy.typing import NDArray + @unique class AncillaMode(Enum): @@ -307,22 +310,20 @@ def check_recurrence(seq: list[int], order: int = 2) -> list[int] | None: if len(seq) < (2 * order + 1): return None - mat, f = [], [] - for i in range(order): - mat.append(seq[i : i + order]) - f.append(seq[i + order]) + mat = np.array([seq[i : i + order] for i in range(order)], dtype=int) + f = np.array([seq[i + order] for i in range(order)], dtype=int) if np.linalg.det(mat) == 0: return None - coeffs = np.linalg.inv(mat).dot(f) + coefficients: NDArray[np.float64] = np.linalg.inv(mat).dot(f) for i in range(2 * order, len(seq)): - predict = np.sum(coeffs * np.array(seq[i - order : i])) + predict: float = np.sum(coefficients * np.array(seq[i - order : i], dtype=float)) if abs(predict - seq[i]) > 10 ** (-2): return None - return list(coeffs) + return list(coefficients) def find_continuation(