Skip to content

Commit

Permalink
🎨 pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Oct 19, 2023
1 parent 80e9307 commit 020c017
Show file tree
Hide file tree
Showing 22 changed files with 2,350 additions and 2,089 deletions.
3 changes: 1 addition & 2 deletions docs/source/Mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions docs/source/library/Visualization.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Visualization
===========================

All visualization functionality is bundled in the sub-module :code:`mqt.qmap.visualization`.
All visualization functionality is bundled in the sub-module :code:`mqt.qmap.visualization`.

Search graph visualization
############################
Expand All @@ -11,6 +11,6 @@ Closing the :code:`SearchVisualizer` object will cleanup the data logged during

.. note::
:code:`visualize_search_graph` returns an IPython display object and therefore requires to be executed in a jupyter notebook or jupyter lab environment.

.. currentmodule:: mqt.qmap.visualization
.. autoclass:: SearchVisualizer
.. autoclass:: SearchVisualizer
36 changes: 18 additions & 18 deletions include/Architecture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class Architecture {
couplingMap = cm;
createDistanceTable();
}

bool isEdgeConnected(const Edge& edge) const {
return couplingMap.find(edge) != couplingMap.end();
}
Expand All @@ -259,7 +259,7 @@ class Architecture {
properties = props;
createFidelityTable();
}

[[nodiscard]] bool isFidelityAvailable() const { return fidelityAvailable; }

[[nodiscard]] const std::vector<Matrix>& getFidelityDistanceTables() const {
Expand All @@ -268,8 +268,9 @@ class Architecture {
}
return fidelityDistanceTables;
}

[[nodiscard]] const Matrix& getFidelityDistanceTable(std::size_t skipEdges) const {

[[nodiscard]] const Matrix&
getFidelityDistanceTable(std::size_t skipEdges) const {
if (!fidelityAvailable) {
throw QMAPException("No fidelity data available.");
}
Expand All @@ -278,13 +279,12 @@ class Architecture {
}
return fidelityDistanceTables.at(skipEdges);
}

[[nodiscard]] const Matrix& getFidelityDistanceTable() const {
return getFidelityDistanceTable(0);
}

[[nodiscard]] double fidelityDistance(std::uint16_t q1,
std::uint16_t q2,
[[nodiscard]] double fidelityDistance(std::uint16_t q1, std::uint16_t q2,
std::size_t skipEdges) const {
if (!fidelityAvailable) {
throw QMAPException("No fidelity data available.");
Expand All @@ -310,7 +310,7 @@ class Architecture {
if (!fidelityAvailable) {
throw QMAPException("No fidelity data available.");
}
return fidelityTable;
return fidelityTable;
}

[[nodiscard]] const std::vector<double>& getSingleQubitFidelities() const {
Expand All @@ -319,7 +319,7 @@ class Architecture {
}
return singleQubitFidelities;
}

[[nodiscard]] const std::vector<double>& getSingleQubitFidelityCosts() const {
if (!fidelityAvailable) {
throw QMAPException("No fidelity data available.");
Expand All @@ -336,7 +336,7 @@ class Architecture {
}
return singleQubitFidelityCosts.at(qbit);
}

[[nodiscard]] const Matrix& getTwoQubitFidelityCosts() const {
if (!fidelityAvailable) {
throw QMAPException("No fidelity data available.");
Expand All @@ -357,7 +357,7 @@ class Architecture {
}
return twoQubitFidelityCosts.at(q1).at(q2);
}

[[nodiscard]] const Matrix& getSwapFidelityCosts() const {
if (!fidelityAvailable) {
throw QMAPException("No fidelity data available.");
Expand Down Expand Up @@ -483,14 +483,14 @@ class Architecture {
bool isBidirectional = true;
Matrix distanceTable = {};
std::vector<std::pair<std::int16_t, std::int16_t>> teleportationQubits{};
Properties properties = {};
bool fidelityAvailable = false;
Matrix fidelityTable = {};
Properties properties = {};
bool fidelityAvailable = false;
Matrix fidelityTable = {};
std::vector<double> singleQubitFidelities = {};
std::vector<double> singleQubitFidelityCosts = {};
Matrix twoQubitFidelityCosts= {};
Matrix swapFidelityCosts = {};
std::vector<Matrix> fidelityDistanceTables = {};
std::vector<double> singleQubitFidelityCosts = {};
Matrix twoQubitFidelityCosts = {};
Matrix swapFidelityCosts = {};
std::vector<Matrix> fidelityDistanceTables = {};

void createDistanceTable();
void createFidelityTable();
Expand Down
61 changes: 32 additions & 29 deletions include/DataLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

class DataLogger {
public:
DataLogger(const std::string& path,
Architecture& arch,
DataLogger(const std::string& path, Architecture& arch,
qc::QuantumComputation& qc)
: dataLoggingPath(path), architecture(arch), inputCircuit(qc) {
: dataLoggingPath(path), architecture(arch), inputCircuit(qc) {
nqubits = architecture.getNqubits();
initLog();
logArchitecture(architecture);
Expand All @@ -30,26 +29,29 @@ class DataLogger {
cregs.push_back(std::make_pair("c", "c[" + std::to_string(i) + "]"));
}
}

void initLog();
void clearLog();
void logArchitecture(Architecture& arch);
void logSearchNode(std::size_t layer, std::size_t nodeId,
std::size_t parentId, double costFixed, double costHeur,
double lookaheadPenalty,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& qubits,
bool validMapping,
const std::vector<std::vector<Exchange>>& swaps,
std::size_t depth);
void logFinalizeLayer(std::size_t layer, const qc::CompoundOperation& ops,
std::vector<std::uint16_t> singleQubitMultiplicity,
std::map<std::pair<std::uint16_t, std::uint16_t>, std::pair<std::uint16_t, std::uint16_t>> twoQubitMultiplicity,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& initialLayout,
std::size_t finalNodeId, double finalCostFixed,
double finalCostHeur, double finalLookaheadPenalty,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& finalLayout,
const std::vector<std::vector<Exchange>>& finalSwaps,
std::size_t finalSearchDepth);
void logSearchNode(std::size_t layer, std::size_t nodeId,
std::size_t parentId, double costFixed, double costHeur,
double lookaheadPenalty,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& qubits,
bool validMapping,
const std::vector<std::vector<Exchange>>& swaps,
std::size_t depth);
void logFinalizeLayer(
std::size_t layer, const qc::CompoundOperation& ops,
std::vector<std::uint16_t> singleQubitMultiplicity,
std::map<std::pair<std::uint16_t, std::uint16_t>,
std::pair<std::uint16_t, std::uint16_t>>
twoQubitMultiplicity,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& initialLayout,
std::size_t finalNodeId, double finalCostFixed, double finalCostHeur,
double finalLookaheadPenalty,
const std::array<std::int16_t, MAX_DEVICE_QUBITS>& finalLayout,
const std::vector<std::vector<Exchange>>& finalSwaps,
std::size_t finalSearchDepth);
void logMappingResult(MappingResults& result);
void logInputCircuit(qc::QuantumComputation& qc) {
qc.dump(dataLoggingPath + "/input.qasm", qc::Format::OpenQASM);
Expand All @@ -59,15 +61,16 @@ class DataLogger {
}
// TODO: layering, initial layout
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);
};
};
4 changes: 2 additions & 2 deletions include/Mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <string>
#include <unordered_set>

constexpr std::int16_t DEFAULT_POSITION = -1;
constexpr double INITIAL_FIDELITY = 1.0;
constexpr std::int16_t DEFAULT_POSITION = -1;
constexpr double INITIAL_FIDELITY = 1.0;

class Mapper {
protected:
Expand Down
12 changes: 6 additions & 6 deletions include/MappingResults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ struct MappingResults {

resultJSON["config"] = config.json();

auto& stats = resultJSON["statistics"];
stats["timeout"] = timeout;
stats["mapping_time"] = time;
stats["arch"] = architecture;
stats["layers"] = input.layers;
stats["swaps"] = output.swaps;
auto& stats = resultJSON["statistics"];
stats["timeout"] = timeout;
stats["mapping_time"] = time;
stats["arch"] = architecture;
stats["layers"] = input.layers;
stats["swaps"] = output.swaps;
stats["total_fidelity"] = output.totalFidelity;
if (config.method == Method::Exact) {
stats["direction_reverse"] = output.directionReverse;
Expand Down
8 changes: 4 additions & 4 deletions include/configuration/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ struct Configuration {
bool postMappingOptimizations = true;

bool addMeasurementsToMappedCircuit = true;
bool swapOnFirstLayer = false;
bool swapOnFirstLayer = false;

bool verbose = false;
bool debug = false;
bool verbose = false;
bool debug = false;
std::string dataLoggingPath = "";

// map to particular subgraph of architecture (in exact mapper)
Expand Down Expand Up @@ -75,7 +75,7 @@ struct Configuration {

[[nodiscard]] nlohmann::json json() const;
[[nodiscard]] std::string toString() const { return json().dump(2); }

bool dataLoggingEnabled() const { return !dataLoggingPath.empty(); }

void setTimeout(const std::size_t sec) { timeout = sec; }
Expand Down
Loading

0 comments on commit 020c017

Please sign in to comment.