Skip to content

Commit

Permalink
⬆️🪝 update pre-commit hooks (cda-tum#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] authored Mar 12, 2024
1 parent 414fe24 commit ae5406d
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 146 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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]"]
3 changes: 1 addition & 2 deletions include/mqt-core/dd/UniqueTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ template <class Node, std::size_t NBUCKET = 32768> 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) {
Expand Down
6 changes: 3 additions & 3 deletions include/mqt-core/ecc/Id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions src/QuantumComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/BernsteinVazirani.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions src/algorithms/GoogleRandomCircuitSampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ GoogleRandomCircuitSampling::printStatistics(std::ostream& os) const {
<< ((layout == Rectangular) ? "Rectangular" : "Bristlecone") << "\n";
os << "\tn: " << static_cast<std::size_t>(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
3 changes: 1 addition & 2 deletions src/algorithms/Grover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/algorithms/QFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 2 additions & 4 deletions src/algorithms/QPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/RandomCliffordCircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions src/dd/Edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ SparseCMat Edge<Node>::getSparseMatrix(const fp threshold) const {
r.traverseMatrix(
1, 0ULL, 0ULL,
[&mat](const std::size_t i, const std::size_t j,
const std::complex<fp>& c) {
mat[{i, j}] = c;
},
const std::complex<fp>& c) { mat[{i, j}] = c; },
threshold);

if constexpr (std::is_same_v<Node, dNode>) {
Expand Down
6 changes: 2 additions & 4 deletions src/operations/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
65 changes: 18 additions & 47 deletions test/unittests/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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());
Expand All @@ -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";
Expand All @@ -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";
Expand All @@ -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());
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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););
Expand Down Expand Up @@ -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) {
Expand All @@ -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());
Expand All @@ -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();
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
Loading

0 comments on commit ae5406d

Please sign in to comment.