Skip to content

Commit 104a25c

Browse files
authored
🚨 Fix new warnings revealed by clang-tidy 18 (#401)
1 parent e190bb4 commit 104a25c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+618
-480
lines changed

.clang-format

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
BasedOnStyle: LLVM
2-
AlignConsecutiveAssignments: Consecutive
3-
AlignConsecutiveDeclarations: Consecutive
42
IncludeBlocks: Regroup
5-
KeepEmptyLinesAtTheStartOfBlocks: false
63
PointerAlignment: Left
7-
SpacesInContainerLiterals: false

include/Configuration.hpp

+26-26
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ class Configuration {
2525
struct Execution {
2626
dd::fp numericalTolerance = dd::RealNumber::eps;
2727

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

3232
bool runConstructionChecker = false;
33-
bool runSimulationChecker = true;
34-
bool runAlternatingChecker = true;
35-
bool runZXChecker = true;
33+
bool runSimulationChecker = true;
34+
bool runAlternatingChecker = true;
35+
bool runZXChecker = true;
3636
};
3737

3838
// configuration options for pre-check optimizations
3939
struct Optimizations {
40-
bool fuseSingleQubitGates = true;
41-
bool reconstructSWAPs = true;
40+
bool fuseSingleQubitGates = true;
41+
bool reconstructSWAPs = true;
4242
bool removeDiagonalGatesBeforeMeasure = false;
43-
bool transformDynamicCircuit = false;
44-
bool reorderOperations = true;
45-
bool backpropagateOutputPermutation = false;
46-
bool elidePermutations = true;
43+
bool transformDynamicCircuit = false;
44+
bool reorderOperations = true;
45+
bool backpropagateOutputPermutation = false;
46+
bool elidePermutations = true;
4747
};
4848

4949
// configuration options for application schemes
@@ -56,30 +56,30 @@ class Configuration {
5656
ApplicationSchemeType::Proportional;
5757

5858
// options for the gate cost application scheme
59-
std::string profile;
59+
std::string profile;
6060
CostFunction costFunction = &legacyCostFunction;
6161
};
6262

6363
struct Functionality {
64-
double traceThreshold = 1e-8;
65-
bool checkPartialEquivalence = false;
64+
double traceThreshold = 1e-8;
65+
bool checkPartialEquivalence = false;
6666
};
6767

6868
// configuration options for the simulation scheme
6969
struct Simulation {
70-
double fidelityThreshold = 1e-8;
71-
std::size_t maxSims = computeMaxSims();
72-
StateType stateType = StateType::ComputationalBasis;
73-
std::size_t seed = 0U;
74-
bool storeCEXinput = false;
75-
bool storeCEXoutput = false;
70+
double fidelityThreshold = 1e-8;
71+
std::size_t maxSims = computeMaxSims();
72+
StateType stateType = StateType::ComputationalBasis;
73+
std::size_t seed = 0U;
74+
bool storeCEXinput = false;
75+
bool storeCEXoutput = false;
7676

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

9393
struct Parameterized {
94-
double parameterizedTol = 1e-12;
94+
double parameterizedTol = 1e-12;
9595
std::size_t nAdditionalInstantiations = 0;
9696
};
9797

98-
Execution execution{};
98+
Execution execution{};
9999
Optimizations optimizations{};
100-
Application application{};
100+
Application application{};
101101
Functionality functionality{};
102-
Simulation simulation{};
102+
Simulation simulation{};
103103
Parameterized parameterized{};
104104

105105
[[nodiscard]] bool anythingToExecute() const noexcept;

include/EquivalenceCheckingManager.hpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
#include "EquivalenceCriterion.hpp"
1010
#include "QuantumComputation.hpp"
1111
#include "ThreadSafeQueue.hpp"
12+
#include "checker/EquivalenceChecker.hpp"
1213
#include "checker/dd/DDSimulationChecker.hpp"
14+
#include "checker/dd/applicationscheme/ApplicationScheme.hpp"
15+
#include "checker/dd/applicationscheme/GateCostApplicationScheme.hpp"
1316
#include "checker/dd/simulation/StateGenerator.hpp"
17+
#include "checker/dd/simulation/StateType.hpp"
1418
#include "dd/ComplexNumbers.hpp"
1519
#include "dd/DDDefinitions.hpp"
1620

@@ -54,11 +58,11 @@ class EquivalenceCheckingManager {
5458

5559
EquivalenceCriterion equivalence = EquivalenceCriterion::NoInformation;
5660

57-
std::size_t startedSimulations = 0U;
61+
std::size_t startedSimulations = 0U;
5862
std::size_t performedSimulations = 0U;
59-
dd::CVec cexInput;
60-
dd::CVec cexOutput1;
61-
dd::CVec cexOutput2;
63+
dd::CVec cexInput;
64+
dd::CVec cexOutput1;
65+
dd::CVec cexOutput2;
6266
std::size_t performedInstantiations = 0U;
6367

6468
nlohmann::json checkerResults = nlohmann::json::array();
@@ -85,7 +89,7 @@ class EquivalenceCheckingManager {
8589
}
8690
[[nodiscard]] std::string toString() const { return json().dump(2); }
8791
friend std::ostream&
88-
operator<<(std::ostream& os,
92+
operator<<(std::ostream& os,
8993
const EquivalenceCheckingManager::Results& res) {
9094
return os << res.toString();
9195
}
@@ -107,7 +111,7 @@ class EquivalenceCheckingManager {
107111
return results.equivalence;
108112
}
109113
[[nodiscard]] Configuration getConfiguration() const { return configuration; }
110-
[[nodiscard]] Results getResults() const { return results; }
114+
[[nodiscard]] Results getResults() const { return results; }
111115

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

139143
void disableAllCheckers() {
140144
configuration.execution.runConstructionChecker = false;
141-
configuration.execution.runZXChecker = false;
142-
configuration.execution.runSimulationChecker = false;
143-
configuration.execution.runAlternatingChecker = false;
145+
configuration.execution.runZXChecker = false;
146+
configuration.execution.runSimulationChecker = false;
147+
configuration.execution.runAlternatingChecker = false;
144148
}
145149

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

253257
StateGenerator stateGenerator;
254-
std::mutex stateGeneratorMutex;
258+
std::mutex stateGeneratorMutex;
255259

256-
bool done{false};
257-
std::condition_variable doneCond;
258-
std::mutex doneMutex;
260+
bool done{false};
261+
std::condition_variable doneCond;
262+
std::mutex doneMutex;
259263
std::vector<std::unique_ptr<EquivalenceChecker>> checkers;
260264

261265
Results results{};
@@ -315,7 +319,7 @@ class EquivalenceCheckingManager {
315319
/// once it is done.
316320
/// \return A future that can be used to wait for the checker to finish.
317321
template <class Checker>
318-
std::future<void> asyncRunChecker(const std::size_t id,
322+
std::future<void> asyncRunChecker(const std::size_t id,
319323
ThreadSafeQueue<std::size_t>& queue) {
320324
static_assert(std::is_base_of_v<EquivalenceChecker, Checker>,
321325
"Checker must be derived from EquivalenceChecker");

include/EquivalenceCriterion.hpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55

66
#pragma once
77

8-
#include <exception>
8+
#include <cstdint>
99
#include <iostream>
10+
#include <string>
1011

1112
namespace ec {
12-
enum class EquivalenceCriterion {
13-
NotEquivalent = 0,
14-
Equivalent = 1,
15-
NoInformation = 2,
16-
ProbablyEquivalent = 3,
13+
enum class EquivalenceCriterion : std::uint8_t {
14+
NotEquivalent = 0,
15+
Equivalent = 1,
16+
NoInformation = 2,
17+
ProbablyEquivalent = 3,
1718
EquivalentUpToGlobalPhase = 4,
18-
EquivalentUpToPhase = 5,
19-
ProbablyNotEquivalent = 6
19+
EquivalentUpToPhase = 5,
20+
ProbablyNotEquivalent = 6
2021
};
2122

2223
inline std::string toString(const EquivalenceCriterion& criterion) noexcept {
@@ -65,7 +66,7 @@ inline EquivalenceCriterion fromString(const std::string& criterion) noexcept {
6566
return EquivalenceCriterion::NoInformation;
6667
}
6768

68-
inline std::istream& operator>>(std::istream& in,
69+
inline std::istream& operator>>(std::istream& in,
6970
EquivalenceCriterion& criterion) {
7071
std::string token;
7172
in >> token;
@@ -79,7 +80,7 @@ inline std::istream& operator>>(std::istream& in,
7980
return in;
8081
}
8182

82-
inline std::ostream& operator<<(std::ostream& out,
83+
inline std::ostream& operator<<(std::ostream& out,
8384
const EquivalenceCriterion& criterion) {
8485
out << toString(criterion);
8586
return out;

include/ThreadSafeQueue.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ template <typename T> class ThreadSafeQueue {
3838
auto p = std::make_unique<Node>();
3939
{
4040
const std::lock_guard tailLock(tailMutex);
41-
tail->data = data;
41+
tail->data = data;
4242
Node* const newTail = p.get();
43-
tail->next = std::move(p);
44-
tail = newTail;
43+
tail->next = std::move(p);
44+
tail = newTail;
4545
}
4646
dataCond.notify_one();
4747
}
@@ -52,13 +52,13 @@ template <typename T> class ThreadSafeQueue {
5252

5353
private:
5454
struct Node {
55-
std::shared_ptr<T> data;
55+
std::shared_ptr<T> data;
5656
std::unique_ptr<Node> next;
5757
};
58-
std::mutex headMutex;
59-
std::unique_ptr<Node> head = std::make_unique<Node>();
60-
std::mutex tailMutex;
61-
Node* tail;
58+
std::mutex headMutex;
59+
std::unique_ptr<Node> head = std::make_unique<Node>();
60+
std::mutex tailMutex;
61+
Node* tail;
6262
std::condition_variable dataCond;
6363

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

6969
auto popHead() {
7070
auto oldHead = std::move(head);
71-
head = std::move(oldHead->next);
71+
head = std::move(oldHead->next);
7272
return oldHead;
7373
}
7474

include/checker/EquivalenceChecker.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EquivalenceChecker {
2020
public:
2121
EquivalenceChecker(const qc::QuantumComputation& circ1,
2222
const qc::QuantumComputation& circ2,
23-
Configuration config) noexcept
23+
Configuration config) noexcept
2424
: qc1(&circ1), qc2(&circ2),
2525
nqubits(std::max(qc1->getNqubits(), qc2->getNqubits())),
2626
configuration(std::move(config)) {};
@@ -50,7 +50,7 @@ class EquivalenceChecker {
5050
Configuration configuration;
5151

5252
EquivalenceCriterion equivalence = EquivalenceCriterion::NoInformation;
53-
double runtime{};
53+
double runtime{};
5454

5555
private:
5656
std::atomic<bool> done{false};

include/checker/dd/DDAlternatingChecker.hpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@
55

66
#pragma once
77

8+
#include "Configuration.hpp"
89
#include "DDEquivalenceChecker.hpp"
910
#include "DDPackageConfigs.hpp"
11+
#include "EquivalenceCriterion.hpp"
12+
#include "QuantumComputation.hpp"
1013
#include "applicationscheme/LookaheadApplicationScheme.hpp"
14+
#include "dd/Package_fwd.hpp"
1115

1216
#include <nlohmann/json_fwd.hpp>
17+
#include <utility>
1318

1419
namespace ec {
1520
class DDAlternatingChecker final
1621
: public DDEquivalenceChecker<qc::MatrixDD, AlternatingDDPackageConfig> {
1722
public:
1823
DDAlternatingChecker(const qc::QuantumComputation& circ1,
1924
const qc::QuantumComputation& circ2,
20-
ec::Configuration config)
25+
ec::Configuration config)
2126
: DDEquivalenceChecker(circ1, circ2, std::move(config)) {
2227
// gates from the second circuit shall be applied "from the right"
2328
taskManager2.flipDirection();
@@ -47,10 +52,10 @@ class DDAlternatingChecker final
4752
private:
4853
qc::MatrixDD functionality{};
4954

50-
void initialize() override;
51-
void execute() override;
52-
void finish() override;
53-
void postprocess() override;
55+
void initialize() override;
56+
void execute() override;
57+
void finish() override;
58+
void postprocess() override;
5459
EquivalenceCriterion checkEquivalence() override;
5560

5661
// at some point this routine should probably make its way into the QFR

include/checker/dd/DDConstructionChecker.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DDConstructionChecker final
2323
public:
2424
DDConstructionChecker(const qc::QuantumComputation& circ1,
2525
const qc::QuantumComputation& circ2,
26-
ec::Configuration config)
26+
ec::Configuration config)
2727
: DDEquivalenceChecker(circ1, circ2, std::move(config)) {
2828
if (this->configuration.application.constructionScheme ==
2929
ApplicationSchemeType::Lookahead) {

include/checker/dd/DDEquivalenceChecker.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DDEquivalenceChecker : public EquivalenceChecker {
2424
public:
2525
DDEquivalenceChecker(const qc::QuantumComputation& circ1,
2626
const qc::QuantumComputation& circ2,
27-
Configuration config)
27+
Configuration config)
2828
: EquivalenceChecker(circ1, circ2, std::move(config)),
2929
dd(std::make_unique<dd::Package<Config>>(nqubits)),
3030
taskManager1(TaskManager<DDType, Config>(circ1, *dd)),

0 commit comments

Comments
 (0)