Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️🪝 update pre-commit hooks #605

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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.4.3
rev: v0.4.4
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down Expand Up @@ -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: v18.1.4
rev: v18.1.5
hooks:
- id: clang-format
types_or: [c++, c, cuda]
Expand Down
3 changes: 2 additions & 1 deletion include/mqt-core/dd/UniqueTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ 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
3 changes: 2 additions & 1 deletion src/QuantumComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ 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: 2 additions & 1 deletion src/algorithms/BernsteinVazirani.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ 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: 4 additions & 2 deletions src/algorithms/GoogleRandomCircuitSampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ 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: 2 additions & 1 deletion src/algorithms/Grover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ 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: 2 additions & 1 deletion src/algorithms/QFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ 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: 4 additions & 2 deletions src/algorithms/QPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ 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: 2 additions & 1 deletion src/algorithms/RandomCliffordCircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ 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
3 changes: 2 additions & 1 deletion src/na/NAComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ auto NAComputation::toString() const -> std::string {
std::stringstream ss;
ss << "init at ";
for (const auto& p : initialPositions) {
ss << "(" << p->x << ", " << p->y << ")" << ", ";
ss << "(" << p->x << ", " << p->y << ")"
<< ", ";
}
ss.seekp(-2, std::ios_base::end);
ss << ";\n";
Expand Down
6 changes: 4 additions & 2 deletions src/operations/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ std::ostream& 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 @@ -25,8 +25,9 @@ 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
3 changes: 2 additions & 1 deletion test/python/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import locale
import sys
from pathlib import Path

Expand Down Expand Up @@ -30,7 +31,7 @@ def test_loading_quantum_computation() -> None:
def test_loading_file() -> None:
"""Test whether importing a simple QASM file works."""
qasm = "qreg q[2];\ncreg c[2];\nh q[0];\ncx q[0], q[1];\nmeasure q -> c;\n"
with Path("test.qasm").open("w") as f:
with Path("test.qasm").open("w", encoding=locale.getpreferredencoding(False)) as f:
f.write(qasm)

# load the file
Expand Down
65 changes: 47 additions & 18 deletions test/unittests/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ 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 @@ -176,7 +177,8 @@ 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 @@ -188,7 +190,8 @@ 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 @@ -212,9 +215,11 @@ 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 @@ -229,7 +234,8 @@ 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 @@ -274,21 +280,24 @@ 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 @@ -347,7 +356,10 @@ 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 @@ -397,8 +409,13 @@ 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 @@ -409,8 +426,12 @@ 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 @@ -429,7 +450,10 @@ 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 @@ -448,7 +472,8 @@ 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 @@ -465,7 +490,9 @@ 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 @@ -505,7 +532,9 @@ 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
Loading