diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06b4b1af..2ce1f552 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -73,7 +73,7 @@ repos: # Static type checking using mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.17.1 + rev: v1.18.2 hooks: - id: mypy files: ^(python/mqt|test/python) @@ -116,7 +116,7 @@ repos: # Check for spelling - repo: https://github.com/crate-ci/typos - rev: v1.36.3 + rev: v1.38.0 hooks: - id: typos @@ -131,7 +131,7 @@ repos: # Check best practices for scientific Python code - repo: https://github.com/scientific-python/cookie - rev: 2024.08.19 + rev: 2025.10.01 hooks: - id: sp-repo-review additional_dependencies: ["repo-review[cli]"] @@ -146,7 +146,7 @@ repos: # Check the pyproject.toml file - repo: https://github.com/henryiii/validate-pyproject-schema-store - rev: 2025.09.12 + rev: 2025.10.03 hooks: - id: validate-pyproject diff --git a/include/dd/MDDPackage.hpp b/include/dd/MDDPackage.hpp index 7e28a0c6..b9b3dbd1 100644 --- a/include/dd/MDDPackage.hpp +++ b/include/dd/MDDPackage.hpp @@ -141,8 +141,8 @@ class MDDPackage { RefCount refCount{}; // reference count, how many active dd are using // the node QuantumRegister - varIndx{}; // variable index (nonterminal) value (-1 for terminal), - // index in the circuit endianness 0 from below + varIndex{}; // variable index (nonterminal) value (-1 for terminal), + // index in the circuit endianness 0 from below static vNode terminalNode; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) @@ -338,22 +338,22 @@ class MDDPackage { auto& uniqueTable = getUniqueTable(); Edge newEdge{uniqueTable.getNode(), Complex::one}; - newEdge.nextNode->varIndx = varidx; + newEdge.nextNode->varIndex = varidx; newEdge.nextNode->edges = edges; assert(newEdge.nextNode->refCount == 0); for ([[maybe_unused]] const auto& edge : edges) { - assert(edge.nextNode->varIndx == varidx - 1 || edge.isTerminal()); + assert(edge.nextNode->varIndex == varidx - 1 || edge.isTerminal()); } // normalize it newEdge = normalize(newEdge, cached); - assert(newEdge.nextNode->varIndx == varidx || newEdge.isTerminal()); + assert(newEdge.nextNode->varIndex == varidx || newEdge.isTerminal()); // look it up in the unique tables auto lookedUpEdge = uniqueTable.lookup(newEdge, false); - assert(lookedUpEdge.nextNode->varIndx == varidx || + assert(lookedUpEdge.nextNode->varIndex == varidx || lookedUpEdge.isTerminal()); // set specific node properties for matrices @@ -372,7 +372,7 @@ class MDDPackage { std::vector> edges{}; // edges out of this node mNode* next{}; // used to link nodes in unique table RefCount refCount{}; // reference count - QuantumRegister varIndx{}; // variable index (nonterminal) value (-1 + QuantumRegister varIndex{}; // variable index (nonterminal) value (-1 // for terminal) bool symmetric = false; // node is symmetric bool identity = false; // node resembles identity @@ -781,11 +781,11 @@ class MDDPackage { QuantumRegister newSuccessor = 0; if (x.isTerminal()) { - newSuccessor = y.nextNode->varIndx; + newSuccessor = y.nextNode->varIndex; } else { - newSuccessor = x.nextNode->varIndx; - if (!y.isTerminal() && y.nextNode->varIndx > newSuccessor) { - newSuccessor = y.nextNode->varIndx; + newSuccessor = x.nextNode->varIndex; + if (!y.isTerminal() && y.nextNode->varIndex > newSuccessor) { + newSuccessor = y.nextNode->varIndex; } } @@ -797,7 +797,7 @@ class MDDPackage { for (auto i = 0U; i < x.nextNode->edges.size(); i++) { Edge e1{}; - if (!x.isTerminal() && x.nextNode->varIndx == newSuccessor) { + if (!x.isTerminal() && x.nextNode->varIndex == newSuccessor) { e1 = x.nextNode->edges.at(i); if (e1.weight != Complex::zero) { @@ -811,7 +811,7 @@ class MDDPackage { } Edge e2{}; - if (!y.isTerminal() && y.nextNode->varIndx == newSuccessor) { + if (!y.isTerminal() && y.nextNode->varIndex == newSuccessor) { e2 = y.nextNode->edges.at(i); if (e2.weight != Complex::zero) { @@ -826,12 +826,12 @@ class MDDPackage { edgeSum.at(i) = add2(e1, e2); - if (!x.isTerminal() && x.nextNode->varIndx == newSuccessor && + if (!x.isTerminal() && x.nextNode->varIndex == newSuccessor && e1.weight != Complex::zero) { complexNumber.returnToCache(e1.weight); } - if (!y.isTerminal() && y.nextNode->varIndx == newSuccessor && + if (!y.isTerminal() && y.nextNode->varIndex == newSuccessor && e2.weight != Complex::zero) { complexNumber.returnToCache(e2.weight); } @@ -862,10 +862,10 @@ class MDDPackage { QuantumRegister var = -1; if (!x.isTerminal()) { - var = x.nextNode->varIndx; + var = x.nextNode->varIndex; } - if (!y.isTerminal() && (y.nextNode->varIndx) > var) { - var = y.nextNode->varIndx; + if (!y.isTerminal() && (y.nextNode->varIndex) > var) { + var = y.nextNode->varIndex; } RightOperand e = multiply2(x, y, var, start); @@ -934,8 +934,8 @@ class MDDPackage { ResultEdge resultEdge{}; - if (x.nextNode->varIndx == var && - x.nextNode->varIndx == y.nextNode->varIndx) { + if (x.nextNode->varIndex == var && + x.nextNode->varIndex == y.nextNode->varIndex) { if (x.nextNode->identity) { if constexpr (std::is_same_v) { // additionally check if y is the identity in case of matrix @@ -982,19 +982,19 @@ class MDDPackage { const std::size_t rows = x.isTerminal() ? 1U - : registersSizes.at(static_cast(x.nextNode->varIndx)); + : registersSizes.at(static_cast(x.nextNode->varIndex)); const std::size_t cols = (std::is_same_v) ? y.isTerminal() ? 1U : registersSizes.at(static_cast( - y.nextNode->varIndx)) + y.nextNode->varIndex)) : 1U; const std::size_t multiplicationBoundary = x.isTerminal() ? (y.isTerminal() ? 1U : registersSizes.at(static_cast( - y.nextNode->varIndx))) - : registersSizes.at(static_cast(x.nextNode->varIndx)); + y.nextNode->varIndex))) + : registersSizes.at(static_cast(x.nextNode->varIndex)); std::vector edge(multiplicationBoundary * cols, ResultEdge::zero); @@ -1006,14 +1006,14 @@ class MDDPackage { for (auto k = 0U; k < multiplicationBoundary; k++) { LEdge e1{}; - if (!x.isTerminal() && x.nextNode->varIndx == var) { + if (!x.isTerminal() && x.nextNode->varIndex == var) { e1 = x.nextNode->edges.at(rows * i + k); } else { e1 = xCopy; } REdge e2{}; - if (!y.isTerminal() && y.nextNode->varIndx == var) { + if (!y.isTerminal() && y.nextNode->varIndex == var) { e2 = y.nextNode->edges.at(j + cols * k); } else { e2 = yCopy; @@ -1067,9 +1067,9 @@ class MDDPackage { [[maybe_unused]] const auto before = complexNumber.cacheCount(); - auto circWidth = x.nextNode->varIndx; - if (y.nextNode->varIndx > circWidth) { - circWidth = y.nextNode->varIndx; + auto circWidth = x.nextNode->varIndex; + if (y.nextNode->varIndex > circWidth) { + circWidth = y.nextNode->varIndex; } const ComplexValue ip = innerProduct(x, y, static_cast(circWidth + 1)); @@ -1119,13 +1119,13 @@ class MDDPackage { for (auto i = 0U; i < registersSizes.at(static_cast(width)); i++) { vEdge e1{}; - if (!x.isTerminal() && x.nextNode->varIndx == width) { + if (!x.isTerminal() && x.nextNode->varIndex == width) { e1 = x.nextNode->edges.at(i); } else { e1 = xCopy; } vEdge e2{}; - if (!y.isTerminal() && y.nextNode->varIndx == width) { + if (!y.isTerminal() && y.nextNode->varIndex == width) { e2 = y.nextNode->edges.at(i); e2.weight = ComplexNumbers::conj(e2.weight); } else { @@ -1207,30 +1207,30 @@ class MDDPackage { std::vector> newEdges(x.nextNode->edges.size(), dd::Edge::zero); - for (auto i = 0U; - i < registersSizes.at(static_cast(x.nextNode->varIndx)); + for (auto i = 0U; i < registersSizes.at( + static_cast(x.nextNode->varIndex)); i++) { newEdges.at(i + i * (registersSizes.at(static_cast( - x.nextNode->varIndx)))) = y; + x.nextNode->varIndex)))) = y; } - auto idx = incIdx ? static_cast(y.nextNode->varIndx + 1) - : y.nextNode->varIndx; + auto idx = incIdx ? static_cast(y.nextNode->varIndex + 1) + : y.nextNode->varIndex; auto e = makeDDNode(idx, newEdges); - for (auto i = 0; i < x.nextNode->varIndx; ++i) { + for (auto i = 0; i < x.nextNode->varIndex; ++i) { std::vector> eSucc(e.nextNode->edges.size(), dd::Edge::zero); for (auto j = 0U; j < - registersSizes.at(static_cast(e.nextNode->varIndx)); + registersSizes.at(static_cast(e.nextNode->varIndex)); j++) { eSucc.at(j + j * (registersSizes.at(static_cast( - e.nextNode->varIndx)))) = e; + e.nextNode->varIndex)))) = e; } - idx = incIdx ? static_cast(e.nextNode->varIndx + 1) - : e.nextNode->varIndx; + idx = incIdx ? static_cast(e.nextNode->varIndex + 1) + : e.nextNode->varIndex; e = makeDDNode(idx, eSucc); } @@ -1247,9 +1247,9 @@ class MDDPackage { edge.at(i) = kronecker2(x.nextNode->edges.at(i), y, incIdx); } - auto idx = incIdx ? static_cast(y.nextNode->varIndx + - x.nextNode->varIndx + 1) - : x.nextNode->varIndx; + auto idx = incIdx ? static_cast(y.nextNode->varIndex + + x.nextNode->varIndex + 1) + : x.nextNode->varIndex; auto e = makeDDNode(idx, edge, true); ComplexNumbers::mul(e.weight, e.weight, x.weight); computeTable.insert(x, y, {e.nextNode, e.weight}); @@ -1593,7 +1593,7 @@ class MDDPackage { ComplexNumbers::mul(tempCompNumb, tempCompNumb, currentEdge.weight); const auto tmp = static_cast(pathElements.at(static_cast( - currentEdge.nextNode->varIndx)) - + currentEdge.nextNode->varIndex)) - '0'); assert(tmp <= currentEdge.nextNode->edges.size()); currentEdge = currentEdge.nextNode->edges.at(tmp); @@ -1810,7 +1810,7 @@ class MDDPackage { private: // check whether node represents a symmetric matrix or the identity void checkSpecialMatrices(mNode* node) { - if (node->varIndx == -1) { + if (node->varIndex == -1) { return; } @@ -1818,7 +1818,7 @@ class MDDPackage { node->symmetric = false; // assume symmetric // check if matrix is symmetric - auto basicDim = registersSizes.at(static_cast(node->varIndx)); + auto basicDim = registersSizes.at(static_cast(node->varIndex)); for (auto i = 0UL; i < basicDim; i++) { if (!node->edges.at(i * basicDim + i).nextNode->symmetric) { @@ -1891,7 +1891,7 @@ class MDDPackage { std::vector newEdge{}; auto basicDim = - registersSizes.at(static_cast(edge.nextNode->varIndx)); + registersSizes.at(static_cast(edge.nextNode->varIndex)); // transpose sub-matrices and rearrange as required for (auto i = 0U; i < basicDim; i++) { @@ -1901,7 +1901,7 @@ class MDDPackage { } } // create new top node - result = makeDDNode(edge.nextNode->varIndx, newEdge); + result = makeDDNode(edge.nextNode->varIndex, newEdge); // adjust top weight auto c = complexNumber.getTemporary(); ComplexNumbers::mul(c, result.weight, edge.weight); @@ -1930,7 +1930,7 @@ class MDDPackage { std::vector newEdge(edge.nextNode->edges.size(), dd::Edge::zero); auto basicDim = - registersSizes.at(static_cast(edge.nextNode->varIndx)); + registersSizes.at(static_cast(edge.nextNode->varIndex)); // conjugate transpose submatrices and rearrange as required for (auto i = 0U; i < basicDim; ++i) { @@ -1940,7 +1940,7 @@ class MDDPackage { } } // create new top node - result = makeDDNode(edge.nextNode->varIndx, newEdge); + result = makeDDNode(edge.nextNode->varIndex, newEdge); auto c = complexNumber.getTemporary(); // adjust top weight including conjugate diff --git a/include/dd/UniqueTable.hpp b/include/dd/UniqueTable.hpp index 1f4a919a..340fff5e 100644 --- a/include/dd/UniqueTable.hpp +++ b/include/dd/UniqueTable.hpp @@ -101,12 +101,12 @@ class UniqueTable { lookups++; const auto key = static_cast(hash(e.nextNode)); - const auto v = e.nextNode->varIndx; + const auto v = e.nextNode->varIndex; // successors of a node shall either have successive variable numbers // or be terminals for ([[maybe_unused]] const auto& edge : e.nextNode->edges) { - assert(edge.nextNode->varIndx == v - 1 || edge.isTerminal()); + assert(edge.nextNode->varIndex == v - 1 || edge.isTerminal()); } Node* p = tables[static_cast(v)][key]; @@ -120,12 +120,12 @@ class UniqueTable { hits++; // variables should stay the same - assert(p->varIndx == e.nextNode->varIndx); + assert(p->varIndex == e.nextNode->varIndex); // successors of a node shall either have successive variable // numbers or be terminals for ([[maybe_unused]] const auto& edge : e.nextNode->edges) { - assert(edge.nextNode->varIndx == v - 1 || edge.isTerminal()); + assert(edge.nextNode->varIndex == v - 1 || edge.isTerminal()); } return {p, e.weight}; diff --git a/python/mqt/qudits/compiler/twodit/variational_twodit_compilation/opt/optimizer.py b/python/mqt/qudits/compiler/twodit/variational_twodit_compilation/opt/optimizer.py index 1b866b8c..ff017a19 100755 --- a/python/mqt/qudits/compiler/twodit/variational_twodit_compilation/opt/optimizer.py +++ b/python/mqt/qudits/compiler/twodit/variational_twodit_compilation/opt/optimizer.py @@ -31,10 +31,10 @@ class Optimizer: OBJ_FIDELITY: float = 1e-4 SINGLE_DIM_0: int = 0 SINGLE_DIM_1: int = 0 - TARGET_GATE: NDArray[typing.Any] = np.ndarray([]) + TARGET_GATE: NDArray[np.complex128] = np.array([]) MAX_NUM_LAYERS: int = 0 # (2 * SINGLE_DIM_0 * SINGLE_DIM_1) - X_SOLUTION: typing.ClassVar = [] - FUN_SOLUTION: typing.ClassVar = [] + X_SOLUTION: NDArray[np.float64] = np.array([]) + FUN_SOLUTION: float = 0.0 @classmethod def set_class_variables( @@ -50,8 +50,8 @@ def set_class_variables( cls.SINGLE_DIM_1 = dim_1 cls.TARGET_GATE = target cls.MAX_NUM_LAYERS = layers if layers > 0 else (2 * dim_0 * dim_1 if dim_0 > 0 and dim_1 > 0 else 0) - cls.X_SOLUTION = [] - cls.FUN_SOLUTION = [] + cls.X_SOLUTION = np.array([]) + cls.FUN_SOLUTION = 0.0 @staticmethod def bounds_assigner( @@ -126,7 +126,7 @@ def solve_anneal( cls, bounds: list[tuple[float, float]], ansatz_type: str, - result_queue: multiprocessing.Queue[tuple[float, list[float]]], + result_queue: multiprocessing.Queue[tuple[float, NDArray[np.float64]]], ) -> None: try: if ansatz_type == "MS": # MS is 0 diff --git a/python/mqt/qudits/quantum_circuit/circuit.py b/python/mqt/qudits/quantum_circuit/circuit.py index 4e6ea1c5..3fd5f816 100644 --- a/python/mqt/qudits/quantum_circuit/circuit.py +++ b/python/mqt/qudits/quantum_circuit/circuit.py @@ -128,7 +128,7 @@ def __init__(self, *args: int | QuantumRegister | list[int] | None) -> None: @classmethod def get_qasm_set(cls) -> dict[str, str]: - return cast("dict[str, str]", cls.qasm_to_gate_set_dict) + return cls.qasm_to_gate_set_dict @property def dimensions(self) -> list[int]: