Skip to content

Commit

Permalink
🚨 Fix new warnings revealed by clang-tidy 18 (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
burgholzer authored May 29, 2024
1 parent 12330f7 commit 42005a9
Show file tree
Hide file tree
Showing 185 changed files with 1,371 additions and 370 deletions.
5 changes: 2 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FormatStyle: file

Checks: |
clang-diagnostic-*,
clang-analyzer-*,
-clang-analyzer-core.NullDereference,
boost-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
clang-analyzer-*,
-clang-analyzer-core.NullDereference,
clang-diagnostic-*,
cppcoreguidelines-*,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-special-member-functions,
Expand Down
20 changes: 14 additions & 6 deletions eval/eval_dd_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@
#include "algorithms/WState.hpp"
#include "dd/Benchmark.hpp"
#include "dd/FunctionalityConstruction.hpp"
#include "dd/Package.hpp"
#include "dd/statistics/PackageStatistics.hpp"
#include "nlohmann/json.hpp"

#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstddef>
#include <exception>
#include <fstream>
#include <ios>
#include <iostream>
#include <memory>
#include <nlohmann/json.hpp>
#include <string>
#include <utility>

namespace dd {

static const std::string FILENAME_START = "results_";
static const std::string FILENAME_END = ".json";

static constexpr std::size_t SEED = 42U;

class BenchmarkDDPackage {
protected:
void verifyAndSave(const std::string& name, const std::string& type,
qc::QuantumComputation& qc, const Experiment& exp) {

const std::string& filename = FILENAME_START + inputFilename + FILENAME_END;
const std::string& filename = "results_" + inputFilename + ".json";

nlohmann::json j;
nlohmann::basic_json<> j;
std::fstream file(filename, std::ios::in | std::ios::out | std::ios::ate);
if (!file.is_open()) {
std::ofstream outputFile(filename);
Expand Down
2 changes: 0 additions & 2 deletions include/mqt-core/CircuitOptimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
#include "QuantumComputation.hpp"
#include "operations/Operation.hpp"

#include <array>
#include <cstddef>
#include <memory>
#include <unordered_set>

namespace qc {

Expand Down
4 changes: 2 additions & 2 deletions include/mqt-core/Permutation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace qc {
class Permutation : public std::map<Qubit, Qubit> {
public:
[[nodiscard]] inline Controls apply(const Controls& controls) const {
[[nodiscard]] Controls apply(const Controls& controls) const {
if (empty()) {
return controls;
}
Expand All @@ -20,7 +20,7 @@ class Permutation : public std::map<Qubit, Qubit> {
}
return c;
}
[[nodiscard]] inline Targets apply(const Targets& targets) const {
[[nodiscard]] Targets apply(const Targets& targets) const {
if (empty()) {
return targets;
}
Expand Down
52 changes: 26 additions & 26 deletions include/mqt-core/QuantumComputation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
#include "Definitions.hpp"
#include "operations/ClassicControlledOperation.hpp"
#include "operations/CompoundOperation.hpp"
#include "operations/Control.hpp"
#include "operations/Expression.hpp"
#include "operations/NonUnitaryOperation.hpp"
#include "operations/OpType.hpp"
#include "operations/StandardOperation.hpp"
#include "operations/SymbolicOperation.hpp"

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <random>
#include <sstream>
#include <string>
#include <unordered_set>
#include <utility>
#include <variant>
#include <vector>

namespace qc {
Expand All @@ -33,17 +39,17 @@ class QuantumComputation {
friend class CircuitOptimizer;

protected:
std::vector<std::unique_ptr<Operation>> ops{};
std::vector<std::unique_ptr<Operation>> ops;
std::size_t nqubits = 0;
std::size_t nclassics = 0;
std::size_t nancillae = 0;
std::string name;

// register names are used as keys, while the values are `{startIndex,
// length}` pairs
QuantumRegisterMap qregs{};
ClassicalRegisterMap cregs{};
QuantumRegisterMap ancregs{};
QuantumRegisterMap qregs;
ClassicalRegisterMap cregs;
QuantumRegisterMap ancregs;

std::mt19937_64 mt;
std::size_t seed = 0;
Expand Down Expand Up @@ -328,8 +334,8 @@ class QuantumComputation {
Permutation initialLayout{};
Permutation outputPermutation{};

std::vector<bool> ancillary{};
std::vector<bool> garbage{};
std::vector<bool> ancillary;
std::vector<bool> garbage;

[[nodiscard]] std::size_t getNindividualOps() const;
[[nodiscard]] std::size_t getNsingleQubitOps() const;
Expand Down Expand Up @@ -553,7 +559,7 @@ class QuantumComputation {
OP_NAME_TO_TYPE.at(#op)); \
}

DEFINE_TWO_TARGET_OPERATION(swap)
DEFINE_TWO_TARGET_OPERATION(swap) // NOLINT: bugprone-exception-escape
DEFINE_TWO_TARGET_OPERATION(dcx)
DEFINE_TWO_TARGET_OPERATION(ecr)
DEFINE_TWO_TARGET_OPERATION(iswap)
Expand Down Expand Up @@ -709,16 +715,13 @@ class QuantumComputation {

void import(const std::string& filename);
void import(const std::string& filename, Format format);
void import(std::istream& is, Format format) {
import(std::move(is), format);
}
void import(std::istream&& is, Format format);
void import(std::istream& is, Format format);
void initializeIOMapping();
// append measurements to the end of the circuit according to the tracked
// output permutation
void appendMeasurementsAccordingToOutputPermutation(
const std::string& registerName = "c");
// search for current position of target value in map and afterwards exchange
// search for current position of target value in map and afterward exchange
// it with the value at new position
static void findAndSWAP(Qubit targetValue, Qubit newPosition,
Permutation& map) {
Expand All @@ -731,7 +734,7 @@ class QuantumComputation {
}

// this function augments a given circuit by additional registers
void addQubitRegister(std::size_t, const std::string& regName = "q");
void addQubitRegister(std::size_t nq, const std::string& regName = "q");
void addClassicalRegister(std::size_t nc, const std::string& regName = "c");
void addAncillaryRegister(std::size_t nq, const std::string& regName = "anc");
// a function to combine all quantum registers (qregs and ancregs) into a
Expand Down Expand Up @@ -819,15 +822,12 @@ class QuantumComputation {
static std::ostream& printPermutation(const Permutation& permutation,
std::ostream& os = std::cout);

virtual void dump(const std::string& filename, Format format);
virtual void dump(const std::string& filename);
virtual void dump(std::ostream& of, Format format) {
dump(std::move(of), format);
}
virtual void dump(std::ostream&& of, Format format);
void dump(const std::string& filename, Format format);
void dump(const std::string& filename);
void dump(std::ostream& of, Format format);
void dumpOpenQASM2(std::ostream& of) { dumpOpenQASM(of, false); }
void dumpOpenQASM3(std::ostream& of) { dumpOpenQASM(of, true); }
virtual void dumpOpenQASM(std::ostream& of, bool openQasm3);
void dumpOpenQASM(std::ostream& of, bool openQasm3);

/**
* @brief Returns the OpenQASM representation of the circuit
Expand Down Expand Up @@ -902,7 +902,7 @@ class QuantumComputation {
// Modifiers (pass-through)
void clear() noexcept { ops.clear(); }
// NOLINTNEXTLINE(readability-identifier-naming)
void pop_back() { return ops.pop_back(); }
void pop_back() { ops.pop_back(); }
void resize(std::size_t count) { ops.resize(count); }
iterator erase(const_iterator pos) { return ops.erase(pos); }
iterator erase(const_iterator first, const_iterator last) {
Expand All @@ -920,7 +920,7 @@ class QuantumComputation {

// NOLINTNEXTLINE(readability-identifier-naming)
template <class T, class... Args> void emplace_back(Args&&... args) {
ops.emplace_back(std::make_unique<T>(args...));
ops.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
}

// NOLINTNEXTLINE(readability-identifier-naming)
Expand Down
10 changes: 7 additions & 3 deletions include/mqt-core/algorithms/BernsteinVazirani.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#pragma once

#include <QuantumComputation.hpp>
#include <bitset>
#include "Definitions.hpp"
#include "QuantumComputation.hpp"

#include <cstddef>
#include <ostream>
#include <string>

namespace qc {
class BernsteinVazirani : public QuantumComputation {
public:
BitString s = 0;
std::size_t bitwidth = 1;
bool dynamic = false;
std::string expected{};
std::string expected;

explicit BernsteinVazirani(const BitString& hiddenString, bool dyn = false);
explicit BernsteinVazirani(std::size_t nq, bool dyn = false);
Expand Down
4 changes: 3 additions & 1 deletion include/mqt-core/algorithms/Entanglement.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <QuantumComputation.hpp>
#include "QuantumComputation.hpp"

#include <cstddef>

namespace qc {
class Entanglement : public QuantumComputation {
Expand Down
31 changes: 22 additions & 9 deletions include/mqt-core/algorithms/GoogleRandomCircuitSampling.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
#pragma once

#include <QuantumComputation.hpp>
#include <chrono>
#include "Definitions.hpp"
#include "QuantumComputation.hpp"
#include "operations/Operation.hpp"

#include <cstddef>
#include <cstdint>
#include <memory>
#include <ostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

namespace qc {
enum Layout { Rectangular, Bristlecone };
enum Layout : std::uint8_t { Rectangular, Bristlecone };

class GoogleRandomCircuitSampling : public QuantumComputation {
public:
std::vector<std::vector<std::unique_ptr<Operation>>> cycles{};
std::vector<std::vector<std::unique_ptr<Operation>>> cycles;
Layout layout = Rectangular;
std::string pathPrefix =
"../../../Benchmarks/GoogleRandomCircuitSampling/inst/";

explicit GoogleRandomCircuitSampling(const std::string& filename);

GoogleRandomCircuitSampling(std::string prefix, std::uint16_t device,
std::uint16_t depth, std::uint16_t instance);
[[maybe_unused]] GoogleRandomCircuitSampling(std::string prefix,
std::uint16_t device,
std::uint16_t depth,
std::uint16_t instance);

GoogleRandomCircuitSampling(std::string prefix, std::uint16_t x,
std::uint16_t y, std::uint16_t depth,
std::uint16_t instance);
[[maybe_unused]] GoogleRandomCircuitSampling(std::string prefix,
std::uint16_t x, std::uint16_t y,
std::uint16_t depth,
std::uint16_t instance);

void importGRCS(const std::string& filename);

Expand Down
9 changes: 5 additions & 4 deletions include/mqt-core/algorithms/Grover.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#pragma once

#include "Definitions.hpp"
#include "QuantumComputation.hpp"

#include <bitset>
#include <functional>
#include <random>
#include <cstddef>
#include <ostream>
#include <string>

namespace qc {
class Grover : public QuantumComputation {
public:
std::size_t seed = 0;
BitString targetValue = 0;
std::size_t iterations = 1;
std::string expected{};
std::string expected;
std::size_t nDataQubits{};

explicit Grover(std::size_t nq, std::size_t s = 0);
Expand Down
3 changes: 3 additions & 0 deletions include/mqt-core/algorithms/QFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "QuantumComputation.hpp"

#include <cstddef>
#include <ostream>

namespace qc {
class QFT : public QuantumComputation {
public:
Expand Down
4 changes: 4 additions & 0 deletions include/mqt-core/algorithms/QPE.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once

#include "Definitions.hpp"
#include "QuantumComputation.hpp"

#include <cstddef>
#include <ostream>

namespace qc {
class QPE : public QuantumComputation {
public:
Expand Down
8 changes: 6 additions & 2 deletions include/mqt-core/algorithms/RandomCliffordCircuit.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#include <QuantumComputation.hpp>
#include "Definitions.hpp"
#include "QuantumComputation.hpp"

#include <cstddef>
#include <cstdint>
#include <functional>
#include <random>
#include <ostream>

namespace qc {
class RandomCliffordCircuit : public QuantumComputation {
Expand Down
3 changes: 2 additions & 1 deletion include/mqt-core/algorithms/WState.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <QuantumComputation.hpp>
#include "Definitions.hpp"
#include "QuantumComputation.hpp"

namespace qc {
class WState : public QuantumComputation {
Expand Down
4 changes: 2 additions & 2 deletions include/mqt-core/datastructures/DirectedAcyclicGraph.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "Definitions.hpp"
#include "DirectedGraph.hpp"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <cstddef>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <vector>

namespace qc {

Expand Down
Loading

0 comments on commit 42005a9

Please sign in to comment.