Skip to content

Commit

Permalink
🚨 Fix new warnings revealed by clang-tidy 18 (#462)
Browse files Browse the repository at this point in the history
## Description

This PR aims to fix all the new warnings that were introduced in
clang-tidy versions 18, which have been enabled with the switch to the
`mqt-workflows@v1.0.0`.

The first commit, which will later be reverted, just triggers a full
clang-tidy run on the whole codebase.

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.
  • Loading branch information
burgholzer committed Aug 9, 2024
2 parents b717265 + bede18e commit 79a864b
Show file tree
Hide file tree
Showing 99 changed files with 1,996 additions and 1,695 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
2 changes: 1 addition & 1 deletion cmake/try_z3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <iostream>
#include <z3.h>
#include <z3_api.h> // IWYU pragma: keep

int main() {
std::cout << Z3_get_full_version();
Expand Down
96 changes: 48 additions & 48 deletions include/Architecture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include <utility>
#include <vector>

constexpr std::uint8_t GATES_OF_BIDIRECTIONAL_SWAP = 3U;
constexpr std::uint8_t GATES_OF_BIDIRECTIONAL_SWAP = 3U;
constexpr std::uint8_t GATES_OF_UNIDIRECTIONAL_SWAP = 7U;
constexpr std::uint8_t GATES_OF_DIRECTION_REVERSE = 4U;
constexpr std::uint8_t GATES_OF_TELEPORTATION = 7U;
constexpr std::uint8_t GATES_OF_DIRECTION_REVERSE = 4U;
constexpr std::uint8_t GATES_OF_TELEPORTATION = 7U;

constexpr std::uint32_t COST_SINGLE_QUBIT_GATE = 1;
constexpr std::uint32_t COST_CNOT_GATE = 10;
constexpr std::uint32_t COST_MEASUREMENT = 10;
constexpr std::uint32_t COST_CNOT_GATE = 10;
constexpr std::uint32_t COST_MEASUREMENT = 10;
constexpr std::uint32_t COST_UNIDIRECTIONAL_SWAP =
3 * COST_CNOT_GATE + 4 * COST_SINGLE_QUBIT_GATE;
constexpr std::uint32_t COST_BIDIRECTIONAL_SWAP = 3 * COST_CNOT_GATE;
Expand All @@ -47,7 +47,7 @@ class Architecture {
public:
Property() = default;

[[nodiscard]] auto& get(const KeyType& key) { return props[key]; }
[[nodiscard]] auto& get(const KeyType& key) { return props[key]; }
[[nodiscard]] const auto& get(const KeyType& key) const {
return props.at(key);
}
Expand All @@ -58,7 +58,7 @@ class Architecture {
[[nodiscard, gnu::pure]] bool available(const KeyType& key) const {
return props.find(key) != props.end();
}
void clear() { props.clear(); }
void clear() { props.clear(); }
[[nodiscard]] bool empty() const { return props.empty(); }

protected:
Expand All @@ -72,27 +72,27 @@ class Architecture {
void setName(const std::string& propertiesName) { name = propertiesName; }

[[nodiscard]] std::uint16_t getNqubits() const { return nq; }
void setNqubits(std::uint16_t nqs) { nq = nqs; }
void setNqubits(std::uint16_t nqs) { nq = nqs; }

Property<std::uint16_t, Property<qc::OpType, double>> singleQubitErrorRate;
Property<std::uint16_t,
Property<std::uint16_t, Property<qc::OpType, double>>>
twoQubitErrorRate;
Property<std::uint16_t, double> readoutErrorRate;
Property<std::uint16_t, double> t1Time;
Property<std::uint16_t, double> t2Time;
Property<std::uint16_t, double> qubitFrequency;
twoQubitErrorRate;
Property<std::uint16_t, double> readoutErrorRate;
Property<std::uint16_t, double> t1Time;
Property<std::uint16_t, double> t2Time;
Property<std::uint16_t, double> qubitFrequency;
Property<std::uint16_t, std::string> calibrationDate;

// convenience functions
void setSingleQubitErrorRate(std::uint16_t qubit,
void setSingleQubitErrorRate(std::uint16_t qubit,
const std::string& operation,
double errorRate) {
double errorRate) {
singleQubitErrorRate.get(qubit).set(qc::opTypeFromString(operation),
errorRate);
}
[[nodiscard]] double
getSingleQubitErrorRate(std::uint16_t qubit,
getSingleQubitErrorRate(std::uint16_t qubit,
const std::string& operation) const {
return singleQubitErrorRate.get(qubit).get(
qc::opTypeFromString(operation));
Expand All @@ -109,7 +109,7 @@ class Architecture {
}

void setTwoQubitErrorRate(std::uint16_t qubit1, std::uint16_t qubit2,
double errorRate,
double errorRate,
const std::string& operation = "cx") {
twoQubitErrorRate.get(qubit1).get(qubit2).set(
qc::opTypeFromString(operation), errorRate);
Expand Down Expand Up @@ -151,7 +151,7 @@ class Architecture {
return json;
}

json["name"] = name;
json["name"] = name;
json["qubits"] = {};
for (std::uint16_t i = 0U; i < nq; ++i) {
auto& qubitProperties = json["qubits"][std::to_string(i)];
Expand Down Expand Up @@ -200,7 +200,7 @@ class Architecture {
[[nodiscard]] std::string toString() const { return json().dump(2); }

protected:
std::string name;
std::string name;
std::uint16_t nq{};
};

Expand All @@ -226,7 +226,7 @@ class Architecture {
const Properties& props);

[[nodiscard]] std::uint16_t getNqubits() const { return nqubits; }
void setNqubits(std::uint16_t nQ) { nqubits = nQ; }
void setNqubits(std::uint16_t nQ) { nqubits = nQ; }

[[nodiscard]] const std::string& getName() const { return name; }
void setName(const std::string& architectureName) { name = architectureName; }
Expand Down Expand Up @@ -412,12 +412,12 @@ class Architecture {
}

void reset() {
name = "";
name = "";
nqubits = 0;
couplingMap.clear();
distanceTable.clear();
distanceTableReversals.clear();
isBidirectional = true;
isBidirectional = true;
isUnidirectional = true;
properties.clear();
fidelityAvailable = false;
Expand Down Expand Up @@ -450,13 +450,13 @@ class Architecture {
}

std::uint64_t minimumNumberOfSwaps(std::vector<std::uint16_t>& permutation,
std::int64_t limit = -1);
void minimumNumberOfSwaps(std::vector<std::uint16_t>& permutation,
std::vector<Edge>& swaps);
std::int64_t limit = -1);
void minimumNumberOfSwaps(std::vector<std::uint16_t>& permutation,
std::vector<Edge>& swaps);

struct Node {
std::uint64_t nswaps = 0U;
std::vector<Edge> swaps;
std::uint64_t nswaps = 0U;
std::vector<Edge> swaps;
std::unordered_map<std::uint16_t, std::uint16_t> permutation;

void print(std::ostream& out) {
Expand All @@ -477,17 +477,17 @@ class Architecture {
getCouplingLimit(const std::set<std::uint16_t>& qubitChoice) const;

void getHighestFidelityCouplingMap(std::uint16_t subsetSize,
CouplingMap& reducedMap) const;
CouplingMap& reducedMap) const;
[[nodiscard]] std::vector<QubitSubset>
getAllConnectedSubsets(std::uint16_t subsetSize) const;
void getReducedCouplingMaps(std::uint16_t subsetSize,
getAllConnectedSubsets(std::uint16_t subsetSize) const;
void getReducedCouplingMaps(std::uint16_t subsetSize,
std::vector<CouplingMap>& couplingMaps) const;
void getReducedCouplingMap(const QubitSubset& qubitChoice,
CouplingMap& reducedMap) const;
CouplingMap& reducedMap) const;
[[nodiscard]] static double
getAverageArchitectureFidelity(const CouplingMap& cm,
const QubitSubset& qubitChoice,
const Properties& props);
const Properties& props);

[[nodiscard]] static QubitSubset getQubitSet(const CouplingMap& cm);
[[nodiscard]] static std::vector<std::uint16_t>
Expand All @@ -502,10 +502,10 @@ class Architecture {
static void printCouplingMap(const CouplingMap& cm, std::ostream& os);

protected:
std::string name;
std::string name;
std::uint16_t nqubits = 0;
CouplingMap couplingMap;
CouplingMap currentTeleportations;
CouplingMap couplingMap;
CouplingMap currentTeleportations;

/** true if the coupling map contains no unidirectional edges */
bool isBidirectional = true;
Expand All @@ -515,17 +515,17 @@ class Architecture {
// unidirectional, and coupling maps containing both bidirectional and
// unidirectional edges are neither bidirectional nor unidirectional

Matrix distanceTable;
Matrix distanceTableReversals;
Matrix distanceTable;
Matrix distanceTableReversals;
std::vector<std::pair<std::int16_t, std::int16_t>> teleportationQubits;
Properties properties;
bool fidelityAvailable = false;
Matrix fidelityTable;
std::vector<double> singleQubitFidelities;
std::vector<double> singleQubitFidelityCosts;
Matrix twoQubitFidelityCosts;
Matrix swapFidelityCosts;
std::vector<Matrix> fidelityDistanceTables;
Properties properties;
bool fidelityAvailable = false;
Matrix fidelityTable;
std::vector<double> singleQubitFidelities;
std::vector<double> singleQubitFidelityCosts;
Matrix twoQubitFidelityCosts;
Matrix swapFidelityCosts;
std::vector<Matrix> fidelityDistanceTables;

void createDistanceTable();
void createFidelityTable();
Expand All @@ -538,10 +538,10 @@ class Architecture {
const std::set<Edge>& teleportations) const;

static std::size_t findCouplingLimit(const CouplingMap& cm,
std::uint16_t nQubits);
std::uint16_t nQubits);
static std::size_t
findCouplingLimit(const CouplingMap& cm, std::uint16_t nQubits,
const std::set<std::uint16_t>& qubitChoice);
findCouplingLimit(const CouplingMap& cm, std::uint16_t nQubits,
const std::set<std::uint16_t>& qubitChoice);
static void findCouplingLimit(
std::uint16_t node, std::uint16_t curSum,
const std::vector<std::unordered_set<std::uint16_t>>& connections,
Expand Down
28 changes: 18 additions & 10 deletions include/DataLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
#pragma once

#include "Architecture.hpp"
#include "Mapper.hpp"
#include "Definitions.hpp"
#include "MappingResults.hpp"
#include "QuantumComputation.hpp"
#include "operations/CompoundOperation.hpp"
#include "utils.hpp"

#include <array>
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <map>
#include <string>
#include <utility>
#include <vector>

class DataLogger {
public:
Expand Down Expand Up @@ -43,10 +51,10 @@ class DataLogger {
const std::vector<std::uint16_t>& singleQubitMultiplicity,
const std::map<std::pair<std::uint16_t, std::uint16_t>,
std::pair<std::uint16_t, std::uint16_t>>&
twoQubitMultiplicity,
twoQubitMultiplicity,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& initialLayout,
std::size_t finalNodeId, double finalCostFixed, double finalCostHeur,
double finalLookaheadPenalty,
double finalLookaheadPenalty,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& finalLayout,
const std::vector<Exchange>& finalSwaps, std::size_t finalSearchDepth);
void splitLayer();
Expand All @@ -66,14 +74,14 @@ class DataLogger {
void close();

protected:
std::string dataLoggingPath;
Architecture* architecture;
std::uint16_t nqubits;
qc::QuantumComputation inputCircuit;
qc::RegisterNames qregs{};
qc::RegisterNames cregs{};
std::string dataLoggingPath;
Architecture* architecture;
std::uint16_t nqubits;
qc::QuantumComputation inputCircuit;
qc::RegisterNames qregs;
qc::RegisterNames cregs;
std::vector<std::ofstream> searchNodesLogFiles; // 1 per layer
bool deactivated = false;
bool deactivated = false;

void openNewLayer(std::size_t layer);
};
Loading

0 comments on commit 79a864b

Please sign in to comment.