From ae5406d206524ff49d79a9dbe93518e823154479 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:46:34 +0000 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=F0=9F=AA=9D=20update=20pre-c?= =?UTF-8?q?ommit=20hooks=20(#561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 8 +- include/mqt-core/dd/UniqueTable.hpp | 3 +- include/mqt-core/ecc/Id.hpp | 6 +- src/QuantumComputation.cpp | 3 +- src/algorithms/BernsteinVazirani.cpp | 3 +- .../GoogleRandomCircuitSampling.cpp | 6 +- src/algorithms/Grover.cpp | 3 +- src/algorithms/QFT.cpp | 3 +- src/algorithms/QPE.cpp | 6 +- src/algorithms/RandomCliffordCircuit.cpp | 3 +- src/dd/Edge.cpp | 4 +- src/operations/Operation.cpp | 6 +- .../register_classic_controlled_operation.cpp | 5 +- test/unittests/test_io.cpp | 65 ++++---------- test/zx/test_zx_functionality.cpp | 84 +++++-------------- 15 files changed, 62 insertions(+), 146 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9c6a63bb0..ca9c0b8e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -58,7 +58,7 @@ repos: # Python linting using ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.2 + rev: v0.3.2 hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -68,7 +68,7 @@ repos: # Static type checking using mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 + rev: v1.9.0 hooks: - id: mypy files: ^(src/mqt|test/python) @@ -86,7 +86,7 @@ repos: # Clang-format the C++ part of the code base automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.6 + rev: v18.1.1 hooks: - id: clang-format types_or: [c++, c, cuda] @@ -125,7 +125,7 @@ repos: # Check best practices for scientific Python code - repo: https://github.com/scientific-python/cookie - rev: 2024.01.24 + rev: 2024.03.10 hooks: - id: sp-repo-review additional_dependencies: ["repo-review[cli]"] diff --git a/include/mqt-core/dd/UniqueTable.hpp b/include/mqt-core/dd/UniqueTable.hpp index f5a33b45a..75fb2282c 100644 --- a/include/mqt-core/dd/UniqueTable.hpp +++ b/include/mqt-core/dd/UniqueTable.hpp @@ -301,8 +301,7 @@ template class UniqueTable { auto q = nvars - 1U; for (auto it = tables.rbegin(); it != tables.rend(); ++it) { auto& table = *it; - std::cout << "\tq" << q << ":" - << "\n"; + std::cout << "\tq" << q << ":" << "\n"; for (std::size_t key = 0; key < table.size(); ++key) { auto p = table[key]; if (p != nullptr) { diff --git a/include/mqt-core/ecc/Id.hpp b/include/mqt-core/ecc/Id.hpp index 9ae032995..5da6445f2 100644 --- a/include/mqt-core/ecc/Id.hpp +++ b/include/mqt-core/ecc/Id.hpp @@ -9,11 +9,11 @@ class Id : public Ecc { : Ecc({ID::Id, 1, 0, "Id", {}}, std::move(qc), measureFq) {} protected: - void writeEncoding() override{}; + void writeEncoding() override {}; - void measureAndCorrect() override{}; + void measureAndCorrect() override {}; - void writeDecoding() override{}; + void writeDecoding() override {}; void mapGate(const qc::Operation& gate) override { qcMapped->emplace_back(gate.clone()); diff --git a/src/QuantumComputation.cpp b/src/QuantumComputation.cpp index be1093b27..190b139d3 100644 --- a/src/QuantumComputation.cpp +++ b/src/QuantumComputation.cpp @@ -535,8 +535,7 @@ std::ostream& QuantumComputation::print(std::ostream& os) const { for (const auto& physicalQubit : initialLayout) { auto it = outputPermutation.find(physicalQubit.first); if (it == outputPermutation.end()) { - os << "\033[31m" << std::setw(4) << "|" - << "\033[0m"; + os << "\033[31m" << std::setw(4) << "|" << "\033[0m"; } else { os << std::setw(4) << it->second; } diff --git a/src/algorithms/BernsteinVazirani.cpp b/src/algorithms/BernsteinVazirani.cpp index 55d45cacf..4fca8b258 100644 --- a/src/algorithms/BernsteinVazirani.cpp +++ b/src/algorithms/BernsteinVazirani.cpp @@ -37,8 +37,7 @@ std::ostream& BernsteinVazirani::printStatistics(std::ostream& os) const { os << "\tm: " << getNindividualOps() << "\n"; os << "\ts: " << expected << "\n"; os << "\tdynamic: " << dynamic << "\n"; - os << "--------------" - << "\n"; + os << "--------------" << "\n"; return os; } diff --git a/src/algorithms/GoogleRandomCircuitSampling.cpp b/src/algorithms/GoogleRandomCircuitSampling.cpp index 8933f06cb..307161506 100644 --- a/src/algorithms/GoogleRandomCircuitSampling.cpp +++ b/src/algorithms/GoogleRandomCircuitSampling.cpp @@ -145,10 +145,8 @@ GoogleRandomCircuitSampling::printStatistics(std::ostream& os) const { << ((layout == Rectangular) ? "Rectangular" : "Bristlecone") << "\n"; os << "\tn: " << static_cast(nqubits) << "\n"; os << "\tm: " << getNops() << "\n"; - os << "\tc: 1 + " << cycles.size() - 2 << " + 1" - << "\n"; - os << "--------------" - << "\n"; + os << "\tc: 1 + " << cycles.size() - 2 << " + 1" << "\n"; + os << "--------------" << "\n"; return os; } } // namespace qc diff --git a/src/algorithms/Grover.cpp b/src/algorithms/Grover.cpp index 3316012d3..22057fddb 100644 --- a/src/algorithms/Grover.cpp +++ b/src/algorithms/Grover.cpp @@ -110,8 +110,7 @@ std::ostream& Grover::printStatistics(std::ostream& os) const { os << "\tseed: " << seed << "\n"; os << "\tx: " << expected << "\n"; os << "\ti: " << iterations << "\n"; - os << "--------------" - << "\n"; + os << "--------------" << "\n"; return os; } } // namespace qc diff --git a/src/algorithms/QFT.cpp b/src/algorithms/QFT.cpp index 2855a3e07..dadf50c54 100644 --- a/src/algorithms/QFT.cpp +++ b/src/algorithms/QFT.cpp @@ -22,8 +22,7 @@ std::ostream& QFT::printStatistics(std::ostream& os) const { os << "\tn: " << nqubits << "\n"; os << "\tm: " << getNindividualOps() << "\n"; os << "\tdynamic: " << dynamic << "\n"; - os << "--------------" - << "\n"; + os << "--------------" << "\n"; return os; } void QFT::createCircuit() { diff --git a/src/algorithms/QPE.cpp b/src/algorithms/QPE.cpp index 1f7f473d9..a2655fd7b 100644 --- a/src/algorithms/QPE.cpp +++ b/src/algorithms/QPE.cpp @@ -48,12 +48,10 @@ std::ostream& QPE::printStatistics(std::ostream& os) const { os << "QPE Statistics:\n"; os << "\tn: " << nqubits + 1 << "\n"; os << "\tm: " << getNindividualOps() << "\n"; - os << "\tlambda: " << lambda << "π" - << "\n"; + os << "\tlambda: " << lambda << "π" << "\n"; os << "\tprecision: " << precision << "\n"; os << "\titerative: " << iterative << "\n"; - os << "--------------" - << "\n"; + os << "--------------" << "\n"; return os; } diff --git a/src/algorithms/RandomCliffordCircuit.cpp b/src/algorithms/RandomCliffordCircuit.cpp index 10b28ff17..db67dcda9 100644 --- a/src/algorithms/RandomCliffordCircuit.cpp +++ b/src/algorithms/RandomCliffordCircuit.cpp @@ -51,8 +51,7 @@ std::ostream& RandomCliffordCircuit::printStatistics(std::ostream& os) const { os << "\tm: " << getNindividualOps() << "\n"; os << "\tdepth: " << depth << "\n"; os << "\tseed: " << seed << "\n"; - os << "--------------" - << "\n"; + os << "--------------" << "\n"; return os; } diff --git a/src/dd/Edge.cpp b/src/dd/Edge.cpp index d7a9de8ea..d8e37729a 100644 --- a/src/dd/Edge.cpp +++ b/src/dd/Edge.cpp @@ -392,9 +392,7 @@ SparseCMat Edge::getSparseMatrix(const fp threshold) const { r.traverseMatrix( 1, 0ULL, 0ULL, [&mat](const std::size_t i, const std::size_t j, - const std::complex& c) { - mat[{i, j}] = c; - }, + const std::complex& c) { mat[{i, j}] = c; }, threshold); if constexpr (std::is_same_v) { diff --git a/src/operations/Operation.cpp b/src/operations/Operation.cpp index 1b0f2df18..45b9462a9 100644 --- a/src/operations/Operation.cpp +++ b/src/operations/Operation.cpp @@ -72,13 +72,11 @@ Operation::print(std::ostream& os, const Permutation& permutation, } else { os << "\033[31m"; } - os << std::setw(4) << "c" - << "\033[0m"; + os << std::setw(4) << "c" << "\033[0m"; continue; } - os << std::setw(4) << "|" - << "\033[0m"; + os << std::setw(4) << "|" << "\033[0m"; } printParameters(os); diff --git a/src/python/operations/register_classic_controlled_operation.cpp b/src/python/operations/register_classic_controlled_operation.cpp index 70e15c698..3cb9dcae4 100644 --- a/src/python/operations/register_classic_controlled_operation.cpp +++ b/src/python/operations/register_classic_controlled_operation.cpp @@ -30,9 +30,8 @@ void registerClassicControlledOperation(py::module& m) { ccop.def("__repr__", [](const qc::ClassicControlledOperation& op) { std::stringstream ss; const auto& controlReg = op.getControlRegister(); - ss << "ClassicControlledOperation(<...op...>, " - << "control_register=(" << controlReg.first << ", " << controlReg.second - << "), " + ss << "ClassicControlledOperation(<...op...>, " << "control_register=(" + << controlReg.first << ", " << controlReg.second << "), " << "expected_value=" << op.getExpectedValue() << ")"; return ss.str(); }); diff --git a/test/unittests/test_io.cpp b/test/unittests/test_io.cpp index e6e382562..096bea6ed 100644 --- a/test/unittests/test_io.cpp +++ b/test/unittests/test_io.cpp @@ -165,8 +165,7 @@ TEST_F(IO, dumpNegativeControl) { TEST_F(IO, qiskitMcxGray) { std::stringstream ss{}; - ss << "qreg q[4];" - << "mcx_gray q[0], q[1], q[2], q[3];\n"; + ss << "qreg q[4];" << "mcx_gray q[0], q[1], q[2], q[3];\n"; qc->import(ss, qc::Format::OpenQASM2); auto& gate = *(qc->begin()); std::cout << *qc << "\n"; @@ -177,8 +176,7 @@ TEST_F(IO, qiskitMcxGray) { TEST_F(IO, qiskitMcxSkipGateDefinition) { std::stringstream ss{}; - ss << "qreg q[4];" - << "gate mcx q0,q1,q2,q3 { ctrl(3) @ x q0,q1,q2,q3; }" + ss << "qreg q[4];" << "gate mcx q0,q1,q2,q3 { ctrl(3) @ x q0,q1,q2,q3; }" << "mcx q[0], q[1], q[2], q[3];\n"; qc->import(ss, qc::Format::OpenQASM2); auto& gate = *(qc->begin()); @@ -190,8 +188,7 @@ TEST_F(IO, qiskitMcxSkipGateDefinition) { TEST_F(IO, qiskitMcphase) { std::stringstream ss{}; - ss << "qreg q[4];" - << "mcphase(pi) q[0], q[1], q[2], q[3];\n"; + ss << "qreg q[4];" << "mcphase(pi) q[0], q[1], q[2], q[3];\n"; qc->import(ss, qc::Format::OpenQASM2); auto& gate = *(qc->begin()); std::cout << *qc << "\n"; @@ -215,11 +212,9 @@ TEST_F(IO, qiskitMcphaseInDeclaration) { TEST_F(IO, qiskitMcxRecursive) { std::stringstream ss{}; - ss << "qreg q[6];" - << "qreg anc[1];" + ss << "qreg q[6];" << "qreg anc[1];" << "mcx_recursive q[0], q[1], q[2], q[3], q[4];" - << "mcx_recursive q[0], q[1], q[2], q[3], q[4], q[5], anc[0];" - << "\n"; + << "mcx_recursive q[0], q[1], q[2], q[3], q[4], q[5], anc[0];" << "\n"; qc->import(ss, qc::Format::OpenQASM2); auto& gate = *(qc->begin()); std::cout << *qc << "\n"; @@ -234,8 +229,7 @@ TEST_F(IO, qiskitMcxRecursive) { TEST_F(IO, qiskitMcxVchain) { std::stringstream ss{}; - ss << "qreg q[4];" - << "qreg anc[1];" + ss << "qreg q[4];" << "qreg anc[1];" << "mcx_vchain q[0], q[1], q[2], q[3], anc[0];\n"; qc->import(ss, qc::Format::OpenQASM2); auto& gate = *(qc->begin()); @@ -280,24 +274,21 @@ TEST_F(IO, qiskitMcxVchainInDeclaration) { TEST_F(IO, qiskitMcxDuplicateQubit) { std::stringstream ss{}; - ss << "qreg q[4];" - << "qreg anc[1];" + ss << "qreg q[4];" << "qreg anc[1];" << "mcx_vchain q[0], q[0], q[2], q[3], anc[0];\n"; EXPECT_THROW(qc->import(ss, qc::Format::OpenQASM2), qasm3::CompilerError); } TEST_F(IO, qiskitMcxQubitRegister) { std::stringstream ss{}; - ss << "qreg q[4];" - << "qreg anc[1];" + ss << "qreg q[4];" << "qreg anc[1];" << "mcx_vchain q, q[0], q[2], q[3], anc[0];\n"; EXPECT_THROW(qc->import(ss, qc::Format::OpenQASM2), qasm3::CompilerError); } TEST_F(IO, barrierInDeclaration) { std::stringstream ss{}; - ss << "qreg q[1];" - << "gate foo q0 { h q0; barrier q0; h q0; }" + ss << "qreg q[1];" << "gate foo q0 { h q0; barrier q0; h q0; }" << "foo q[0];\n"; qc->import(ss, qc::Format::OpenQASM3); std::cout << *qc << "\n"; @@ -356,10 +347,7 @@ TEST_F(IO, grcsInput) { TEST_F(IO, classicControlled) { std::stringstream ss{}; - ss << "qreg q[1];" - << "creg c[1];" - << "h q[0];" - << "measure q->c;" + ss << "qreg q[1];" << "creg c[1];" << "h q[0];" << "measure q->c;" << "// test classic controlled operation\n" << "if (c==1) x q[0];\n"; EXPECT_NO_THROW(qc->import(ss, qc::Format::OpenQASM3);); @@ -409,13 +397,8 @@ TEST_F(IO, PeresdagDumpIsValid) { TEST_F(IO, printingNonUnitary) { std::stringstream ss{}; - ss << "qreg q[2];" - << "creg c[2];" - << "h q[0];" - << "reset q[0];" - << "h q[0];" - << "barrier q;" - << "measure q -> c;\n"; + ss << "qreg q[2];" << "creg c[2];" << "h q[0];" << "reset q[0];" << "h q[0];" + << "barrier q;" << "measure q -> c;\n"; EXPECT_NO_THROW(qc->import(ss, qc::Format::OpenQASM3)); std::cout << *qc << "\n"; for (const auto& op : *qc) { @@ -426,12 +409,8 @@ TEST_F(IO, printingNonUnitary) { TEST_F(IO, sxAndSxdag) { std::stringstream ss{}; - ss << "qreg q[1];" - << "creg c[1];" - << "gate test q0 { sx q0; sxdg q0;}" - << "sx q[0];" - << "sxdg q[0];" - << "test q[0];\n"; + ss << "qreg q[1];" << "creg c[1];" << "gate test q0 { sx q0; sxdg q0;}" + << "sx q[0];" << "sxdg q[0];" << "test q[0];\n"; EXPECT_NO_THROW(qc->import(ss, qc::Format::OpenQASM3)); std::cout << *qc << "\n"; auto& op1 = *(qc->begin()); @@ -450,10 +429,7 @@ TEST_F(IO, sxAndSxdag) { TEST_F(IO, unifyRegisters) { std::stringstream ss{}; - ss << "qreg q[1];" - << "qreg r[1];" - << "x q[0];" - << "x r[0];\n"; + ss << "qreg q[1];" << "qreg r[1];" << "x q[0];" << "x r[0];\n"; qc->import(ss, qc::Format::OpenQASM3); std::cout << *qc << "\n"; qc->unifyQuantumRegisters(); @@ -472,8 +448,7 @@ TEST_F(IO, unifyRegisters) { TEST_F(IO, appendMeasurementsAccordingToOutputPermutation) { std::stringstream ss{}; ss << "// o 1\n" - << "qreg q[2];" - << "x q[1];\n"; + << "qreg q[2];" << "x q[1];\n"; qc->import(ss, qc::Format::OpenQASM3); qc->appendMeasurementsAccordingToOutputPermutation(); std::cout << *qc << "\n"; @@ -490,9 +465,7 @@ TEST_F(IO, appendMeasurementsAccordingToOutputPermutation) { TEST_F(IO, appendMeasurementsAccordingToOutputPermutationAugmentRegister) { std::stringstream ss{}; ss << "// o 0 1\n" - << "qreg q[2];" - << "creg c[1];" - << "x q;\n"; + << "qreg q[2];" << "creg c[1];" << "x q;\n"; qc->import(ss, qc::Format::OpenQASM3); qc->appendMeasurementsAccordingToOutputPermutation(); std::cout << *qc << "\n"; @@ -532,9 +505,7 @@ TEST_F(IO, appendMeasurementsAccordingToOutputPermutationAugmentRegister) { TEST_F(IO, appendMeasurementsAccordingToOutputPermutationAddRegister) { std::stringstream ss{}; ss << "// o 0 1\n" - << "qreg q[2];" - << "creg d[1];" - << "x q;\n"; + << "qreg q[2];" << "creg d[1];" << "x q;\n"; qc->import(ss, qc::Format::OpenQASM3); qc->appendMeasurementsAccordingToOutputPermutation(); std::cout << *qc << "\n"; diff --git a/test/zx/test_zx_functionality.cpp b/test/zx/test_zx_functionality.cpp index 5eaded765..493d84682 100644 --- a/test/zx/test_zx_functionality.cpp +++ b/test/zx/test_zx_functionality.cpp @@ -72,68 +72,28 @@ TEST_F(ZXFunctionalityTest, complexCircuit) { std::stringstream ss{}; ss << "// i 1 0 2\n" << "// o 0 1 2\n" - << "OPENQASM 2.0;" - << "include \"qelib1.inc\";" - << "qreg q[3];" - << "sx q[0];" - << "sxdg q[0];" - << "h q[0];" - << "cx q[0],q[1];" - << "z q[1];" - << "x q[2];" - << "y q[0];" - << "rx(pi/4) q[0];" - << "rz(0.1) q[1];" - << "p(0.1) q[1];" - << "ry(pi/4) q[2];" - << "t q[0];" - << "s q[2];" - << "u2(pi/4, pi/4) q[1];" - << "u3(pi/4, pi/4, pi/4) q[2];" - << "barrier q[0],q[1],q[2];" - << "swap q[0],q[1];" - << "cz q[1],q[2];" - << "cp(pi/4) q[0],q[1];" - << "ctrl(2) @ x q[0],q[1],q[2];" - << "ctrl(2) @ z q[1],q[2],q[0];" - << "cp(pi/2) q[0], q[1];" - << "cp(pi/4) q[0], q[1];" - << "cp(pi/8) q[0], q[1];" - << "rzz(pi/4) q[0], q[1];" - << "rxx(pi/4) q[0], q[1];" - << "ryy(pi/4) q[0], q[1];" - << "rzx(pi/4) q[0], q[1];" - << "ecr q[0], q[1];" - << "dcx q[0], q[1];" - << "dcx q[1], q[0];" - << "ecr q[0], q[1];" - << "rzx(-pi/4) q[0], q[1];" - << "ryy(-pi/4) q[0], q[1];" - << "rxx(-pi/4) q[0], q[1];" - << "rzz(-pi/4) q[0], q[1];" - << "cp(-pi/8) q[0], q[1];" - << "cp(-pi/4) q[0], q[1];" - << "cp(-pi/2) q[0], q[1];" - << "ctrl(2) @ z q[1],q[2],q[0];" - << "ctrl(2) @ x q[0],q[1],q[2];" - << "cp(-pi/4) q[0],q[1];" - << "cz q[1],q[2];" - << "cx q[1],q[0];" - << "cx q[0],q[1];" - << "cx q[1],q[0];" - << "u3(-pi/4,-pi/4,-pi/4) q[2];" - << "u2(-5*pi/4,3*pi/4) q[1];" - << "sdg q[2];" - << "tdg q[0];" - << "ry(-pi/4) q[2];" - << "p(-0.1) q[1];" - << "rz(-0.1) q[1];" - << "rx(-pi/4) q[0];" - << "y q[0];" - << "x q[2];" - << "z q[1];" - << "cx q[0],q[1];" - << "h q[0];\n"; + << "OPENQASM 2.0;" << "include \"qelib1.inc\";" << "qreg q[3];" + << "sx q[0];" << "sxdg q[0];" << "h q[0];" << "cx q[0],q[1];" << "z q[1];" + << "x q[2];" << "y q[0];" << "rx(pi/4) q[0];" << "rz(0.1) q[1];" + << "p(0.1) q[1];" << "ry(pi/4) q[2];" << "t q[0];" << "s q[2];" + << "u2(pi/4, pi/4) q[1];" << "u3(pi/4, pi/4, pi/4) q[2];" + << "barrier q[0],q[1],q[2];" << "swap q[0],q[1];" << "cz q[1],q[2];" + << "cp(pi/4) q[0],q[1];" << "ctrl(2) @ x q[0],q[1],q[2];" + << "ctrl(2) @ z q[1],q[2],q[0];" << "cp(pi/2) q[0], q[1];" + << "cp(pi/4) q[0], q[1];" << "cp(pi/8) q[0], q[1];" + << "rzz(pi/4) q[0], q[1];" << "rxx(pi/4) q[0], q[1];" + << "ryy(pi/4) q[0], q[1];" << "rzx(pi/4) q[0], q[1];" << "ecr q[0], q[1];" + << "dcx q[0], q[1];" << "dcx q[1], q[0];" << "ecr q[0], q[1];" + << "rzx(-pi/4) q[0], q[1];" << "ryy(-pi/4) q[0], q[1];" + << "rxx(-pi/4) q[0], q[1];" << "rzz(-pi/4) q[0], q[1];" + << "cp(-pi/8) q[0], q[1];" << "cp(-pi/4) q[0], q[1];" + << "cp(-pi/2) q[0], q[1];" << "ctrl(2) @ z q[1],q[2],q[0];" + << "ctrl(2) @ x q[0],q[1],q[2];" << "cp(-pi/4) q[0],q[1];" + << "cz q[1],q[2];" << "cx q[1],q[0];" << "cx q[0],q[1];" << "cx q[1],q[0];" + << "u3(-pi/4,-pi/4,-pi/4) q[2];" << "u2(-5*pi/4,3*pi/4) q[1];" + << "sdg q[2];" << "tdg q[0];" << "ry(-pi/4) q[2];" << "p(-0.1) q[1];" + << "rz(-0.1) q[1];" << "rx(-pi/4) q[0];" << "y q[0];" << "x q[2];" + << "z q[1];" << "cx q[0],q[1];" << "h q[0];\n"; qc.import(ss, qc::Format::OpenQASM3); EXPECT_TRUE(zx::FunctionalityConstruction::transformableToZX(&qc));