Skip to content

Commit

Permalink
🚨 Fix new warnings revealed by clang-tidy 18 (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
burgholzer authored Jun 21, 2024
1 parent e190bb4 commit 104a25c
Show file tree
Hide file tree
Showing 42 changed files with 618 additions and 480 deletions.
4 changes: 0 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
BasedOnStyle: LLVM
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
IncludeBlocks: Regroup
KeepEmptyLinesAtTheStartOfBlocks: false
PointerAlignment: Left
SpacesInContainerLiterals: false
52 changes: 26 additions & 26 deletions include/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ class Configuration {
struct Execution {
dd::fp numericalTolerance = dd::RealNumber::eps;

bool parallel = true;
bool parallel = true;
std::size_t nthreads = std::max(2U, std::thread::hardware_concurrency());
double timeout = 0.; // in seconds
double timeout = 0.; // in seconds

bool runConstructionChecker = false;
bool runSimulationChecker = true;
bool runAlternatingChecker = true;
bool runZXChecker = true;
bool runSimulationChecker = true;
bool runAlternatingChecker = true;
bool runZXChecker = true;
};

// configuration options for pre-check optimizations
struct Optimizations {
bool fuseSingleQubitGates = true;
bool reconstructSWAPs = true;
bool fuseSingleQubitGates = true;
bool reconstructSWAPs = true;
bool removeDiagonalGatesBeforeMeasure = false;
bool transformDynamicCircuit = false;
bool reorderOperations = true;
bool backpropagateOutputPermutation = false;
bool elidePermutations = true;
bool transformDynamicCircuit = false;
bool reorderOperations = true;
bool backpropagateOutputPermutation = false;
bool elidePermutations = true;
};

// configuration options for application schemes
Expand All @@ -56,30 +56,30 @@ class Configuration {
ApplicationSchemeType::Proportional;

// options for the gate cost application scheme
std::string profile;
std::string profile;
CostFunction costFunction = &legacyCostFunction;
};

struct Functionality {
double traceThreshold = 1e-8;
bool checkPartialEquivalence = false;
double traceThreshold = 1e-8;
bool checkPartialEquivalence = false;
};

// configuration options for the simulation scheme
struct Simulation {
double fidelityThreshold = 1e-8;
std::size_t maxSims = computeMaxSims();
StateType stateType = StateType::ComputationalBasis;
std::size_t seed = 0U;
bool storeCEXinput = false;
bool storeCEXoutput = false;
double fidelityThreshold = 1e-8;
std::size_t maxSims = computeMaxSims();
StateType stateType = StateType::ComputationalBasis;
std::size_t seed = 0U;
bool storeCEXinput = false;
bool storeCEXoutput = false;

// this function makes sure that the maximum number of simulations is
// configured properly.
static std::size_t computeMaxSims() {
constexpr std::size_t defaultMaxSims = 16U;
constexpr std::size_t defaultMaxSims = 16U;
constexpr std::size_t defaultConfiguredOtherCheckers = 2U;
const auto systemThreads = std::thread::hardware_concurrency();
const auto systemThreads = std::thread::hardware_concurrency();
// catch the case where hardware_concurrency() returns 0 or the other
// pre-configured checkers already use up all the available threads
if (systemThreads < defaultConfiguredOtherCheckers) {
Expand All @@ -91,15 +91,15 @@ class Configuration {
};

struct Parameterized {
double parameterizedTol = 1e-12;
double parameterizedTol = 1e-12;
std::size_t nAdditionalInstantiations = 0;
};

Execution execution{};
Execution execution{};
Optimizations optimizations{};
Application application{};
Application application{};
Functionality functionality{};
Simulation simulation{};
Simulation simulation{};
Parameterized parameterized{};

[[nodiscard]] bool anythingToExecute() const noexcept;
Expand Down
32 changes: 18 additions & 14 deletions include/EquivalenceCheckingManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
#include "EquivalenceCriterion.hpp"
#include "QuantumComputation.hpp"
#include "ThreadSafeQueue.hpp"
#include "checker/EquivalenceChecker.hpp"
#include "checker/dd/DDSimulationChecker.hpp"
#include "checker/dd/applicationscheme/ApplicationScheme.hpp"
#include "checker/dd/applicationscheme/GateCostApplicationScheme.hpp"
#include "checker/dd/simulation/StateGenerator.hpp"
#include "checker/dd/simulation/StateType.hpp"
#include "dd/ComplexNumbers.hpp"
#include "dd/DDDefinitions.hpp"

Expand Down Expand Up @@ -54,11 +58,11 @@ class EquivalenceCheckingManager {

EquivalenceCriterion equivalence = EquivalenceCriterion::NoInformation;

std::size_t startedSimulations = 0U;
std::size_t startedSimulations = 0U;
std::size_t performedSimulations = 0U;
dd::CVec cexInput;
dd::CVec cexOutput1;
dd::CVec cexOutput2;
dd::CVec cexInput;
dd::CVec cexOutput1;
dd::CVec cexOutput2;
std::size_t performedInstantiations = 0U;

nlohmann::json checkerResults = nlohmann::json::array();
Expand All @@ -85,7 +89,7 @@ class EquivalenceCheckingManager {
}
[[nodiscard]] std::string toString() const { return json().dump(2); }
friend std::ostream&
operator<<(std::ostream& os,
operator<<(std::ostream& os,
const EquivalenceCheckingManager::Results& res) {
return os << res.toString();
}
Expand All @@ -107,7 +111,7 @@ class EquivalenceCheckingManager {
return results.equivalence;
}
[[nodiscard]] Configuration getConfiguration() const { return configuration; }
[[nodiscard]] Results getResults() const { return results; }
[[nodiscard]] Results getResults() const { return results; }

// convenience functions for changing the configuration after the manager has
// been constructed: Execution: These settings may be changed to influence
Expand Down Expand Up @@ -138,9 +142,9 @@ class EquivalenceCheckingManager {

void disableAllCheckers() {
configuration.execution.runConstructionChecker = false;
configuration.execution.runZXChecker = false;
configuration.execution.runSimulationChecker = false;
configuration.execution.runAlternatingChecker = false;
configuration.execution.runZXChecker = false;
configuration.execution.runSimulationChecker = false;
configuration.execution.runAlternatingChecker = false;
}

// Optimization: Optimizations are applied during initialization. Already
Expand Down Expand Up @@ -251,11 +255,11 @@ class EquivalenceCheckingManager {
Configuration configuration{};

StateGenerator stateGenerator;
std::mutex stateGeneratorMutex;
std::mutex stateGeneratorMutex;

bool done{false};
std::condition_variable doneCond;
std::mutex doneMutex;
bool done{false};
std::condition_variable doneCond;
std::mutex doneMutex;
std::vector<std::unique_ptr<EquivalenceChecker>> checkers;

Results results{};
Expand Down Expand Up @@ -315,7 +319,7 @@ class EquivalenceCheckingManager {
/// once it is done.
/// \return A future that can be used to wait for the checker to finish.
template <class Checker>
std::future<void> asyncRunChecker(const std::size_t id,
std::future<void> asyncRunChecker(const std::size_t id,
ThreadSafeQueue<std::size_t>& queue) {
static_assert(std::is_base_of_v<EquivalenceChecker, Checker>,
"Checker must be derived from EquivalenceChecker");
Expand Down
21 changes: 11 additions & 10 deletions include/EquivalenceCriterion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

#pragma once

#include <exception>
#include <cstdint>
#include <iostream>
#include <string>

namespace ec {
enum class EquivalenceCriterion {
NotEquivalent = 0,
Equivalent = 1,
NoInformation = 2,
ProbablyEquivalent = 3,
enum class EquivalenceCriterion : std::uint8_t {
NotEquivalent = 0,
Equivalent = 1,
NoInformation = 2,
ProbablyEquivalent = 3,
EquivalentUpToGlobalPhase = 4,
EquivalentUpToPhase = 5,
ProbablyNotEquivalent = 6
EquivalentUpToPhase = 5,
ProbablyNotEquivalent = 6
};

inline std::string toString(const EquivalenceCriterion& criterion) noexcept {
Expand Down Expand Up @@ -65,7 +66,7 @@ inline EquivalenceCriterion fromString(const std::string& criterion) noexcept {
return EquivalenceCriterion::NoInformation;
}

inline std::istream& operator>>(std::istream& in,
inline std::istream& operator>>(std::istream& in,
EquivalenceCriterion& criterion) {
std::string token;
in >> token;
Expand All @@ -79,7 +80,7 @@ inline std::istream& operator>>(std::istream& in,
return in;
}

inline std::ostream& operator<<(std::ostream& out,
inline std::ostream& operator<<(std::ostream& out,
const EquivalenceCriterion& criterion) {
out << toString(criterion);
return out;
Expand Down
18 changes: 9 additions & 9 deletions include/ThreadSafeQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ template <typename T> class ThreadSafeQueue {
auto p = std::make_unique<Node>();
{
const std::lock_guard tailLock(tailMutex);
tail->data = data;
tail->data = data;
Node* const newTail = p.get();
tail->next = std::move(p);
tail = newTail;
tail->next = std::move(p);
tail = newTail;
}
dataCond.notify_one();
}
Expand All @@ -52,13 +52,13 @@ template <typename T> class ThreadSafeQueue {

private:
struct Node {
std::shared_ptr<T> data;
std::shared_ptr<T> data;
std::unique_ptr<Node> next;
};
std::mutex headMutex;
std::unique_ptr<Node> head = std::make_unique<Node>();
std::mutex tailMutex;
Node* tail;
std::mutex headMutex;
std::unique_ptr<Node> head = std::make_unique<Node>();
std::mutex tailMutex;
Node* tail;
std::condition_variable dataCond;

auto getTail() {
Expand All @@ -68,7 +68,7 @@ template <typename T> class ThreadSafeQueue {

auto popHead() {
auto oldHead = std::move(head);
head = std::move(oldHead->next);
head = std::move(oldHead->next);
return oldHead;
}

Expand Down
4 changes: 2 additions & 2 deletions include/checker/EquivalenceChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EquivalenceChecker {
public:
EquivalenceChecker(const qc::QuantumComputation& circ1,
const qc::QuantumComputation& circ2,
Configuration config) noexcept
Configuration config) noexcept
: qc1(&circ1), qc2(&circ2),
nqubits(std::max(qc1->getNqubits(), qc2->getNqubits())),
configuration(std::move(config)) {};
Expand Down Expand Up @@ -50,7 +50,7 @@ class EquivalenceChecker {
Configuration configuration;

EquivalenceCriterion equivalence = EquivalenceCriterion::NoInformation;
double runtime{};
double runtime{};

private:
std::atomic<bool> done{false};
Expand Down
15 changes: 10 additions & 5 deletions include/checker/dd/DDAlternatingChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

#pragma once

#include "Configuration.hpp"
#include "DDEquivalenceChecker.hpp"
#include "DDPackageConfigs.hpp"
#include "EquivalenceCriterion.hpp"
#include "QuantumComputation.hpp"
#include "applicationscheme/LookaheadApplicationScheme.hpp"
#include "dd/Package_fwd.hpp"

#include <nlohmann/json_fwd.hpp>
#include <utility>

namespace ec {
class DDAlternatingChecker final
: public DDEquivalenceChecker<qc::MatrixDD, AlternatingDDPackageConfig> {
public:
DDAlternatingChecker(const qc::QuantumComputation& circ1,
const qc::QuantumComputation& circ2,
ec::Configuration config)
ec::Configuration config)
: DDEquivalenceChecker(circ1, circ2, std::move(config)) {
// gates from the second circuit shall be applied "from the right"
taskManager2.flipDirection();
Expand Down Expand Up @@ -47,10 +52,10 @@ class DDAlternatingChecker final
private:
qc::MatrixDD functionality{};

void initialize() override;
void execute() override;
void finish() override;
void postprocess() override;
void initialize() override;
void execute() override;
void finish() override;
void postprocess() override;
EquivalenceCriterion checkEquivalence() override;

// at some point this routine should probably make its way into the QFR
Expand Down
2 changes: 1 addition & 1 deletion include/checker/dd/DDConstructionChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DDConstructionChecker final
public:
DDConstructionChecker(const qc::QuantumComputation& circ1,
const qc::QuantumComputation& circ2,
ec::Configuration config)
ec::Configuration config)
: DDEquivalenceChecker(circ1, circ2, std::move(config)) {
if (this->configuration.application.constructionScheme ==
ApplicationSchemeType::Lookahead) {
Expand Down
2 changes: 1 addition & 1 deletion include/checker/dd/DDEquivalenceChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DDEquivalenceChecker : public EquivalenceChecker {
public:
DDEquivalenceChecker(const qc::QuantumComputation& circ1,
const qc::QuantumComputation& circ2,
Configuration config)
Configuration config)
: EquivalenceChecker(circ1, circ2, std::move(config)),
dd(std::make_unique<dd::Package<Config>>(nqubits)),
taskManager1(TaskManager<DDType, Config>(circ1, *dd)),
Expand Down
Loading

0 comments on commit 104a25c

Please sign in to comment.