Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes Required for DD Reordering to Minimize Runtime #407

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
2990adb
setup of private repository with current status done
Jul 2, 2024
9e31e69
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Jul 2, 2024
082ccef
Control based reordering implemented
Jul 4, 2024
579f602
code cleanup and results printed to file
Jul 4, 2024
00a92a7
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Jul 5, 2024
cd8a2e4
wrote wrapper functions for parameter parsed testing.
Jul 6, 2024
105e3da
corrected time measurement, documented bug with u gate
Jul 8, 2024
fff70f2
added empty files to provide folder structure
Jul 8, 2024
9e2e8a4
collected test results
Jul 11, 2024
47e28dc
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Jul 11, 2024
3879de4
automized long time time measurements and results
Jul 15, 2024
79f9faa
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Jul 15, 2024
9b451a5
added short qasm for pattern recognition
Jul 19, 2024
17369f7
implemented structure for gate based reordering
Jul 22, 2024
cb874c8
Implemented final logic for gate/pattern based reordering
Jul 24, 2024
8aa5152
added test for executing gate/pattern based reordering
Jul 24, 2024
4ac11f4
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Jul 24, 2024
a6da074
removed all testing environment used for development, make it pull re…
Jul 24, 2024
ddf738e
Merge branch 'main' of https://github.com/Claudiaaaaaaaaa/mqt-ddsim
Jul 24, 2024
f4c6d99
🎨 pre-commit fixes
pre-commit-ci[bot] Jul 24, 2024
55ac1d1
Update src/DDMinimizer.cpp
Claudiaaaaaaaaa Jul 25, 2024
6f94a49
Update src/DDMinimizer.cpp
Claudiaaaaaaaaa Jul 25, 2024
d8b98af
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Aug 5, 2024
6f635a9
Final implementation
Claudiaaaaaaaaa Aug 13, 2024
2f4fba2
Merge branch 'main' into main
Claudiaaaaaaaaa Sep 7, 2024
246a957
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 7, 2024
c3dd9c4
removed unneccesary include
Claudiaaaaaaaaa Sep 7, 2024
136007f
Update DDMinimizer.hpp
Claudiaaaaaaaaa Sep 7, 2024
62776b4
adjusted inclues for new folder structure in mqt-core
Claudiaaaaaaaaa Sep 7, 2024
a335cad
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 7, 2024
6b2a77c
fix CodeQL suggestions
Claudiaaaaaaaaa Sep 7, 2024
2788f5b
Merge branch 'main' of https://github.com/Claudiaaaaaaaaa/mqt-ddsim
Claudiaaaaaaaaa Sep 16, 2024
00e9865
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
e36dfaa
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Sep 16, 2024
f1f8535
Added all the comments
Claudiaaaaaaaaa Sep 16, 2024
e7ef6b4
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
9e579e7
worked on issues from Lint
Sep 16, 2024
bc9fdad
Merge branch 'main' of https://github.com/Claudiaaaaaaaaa/mqt-ddsim
Sep 16, 2024
6afcacf
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
81af6e4
resolved naming issues from Lint
Sep 16, 2024
0e503b4
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
6f4a7b4
adjusted changes from .cpp
Sep 16, 2024
a56c4bf
Merge branch 'main' of https://github.com/Claudiaaaaaaaaa/mqt-ddsim
Sep 16, 2024
a4061cb
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
2e3a23b
worked on lint
Sep 16, 2024
4ab0b1e
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
e03373d
new try for linter
Sep 16, 2024
74d56c2
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 16, 2024
1fe783a
corrected typo for lint
Sep 18, 2024
12bb49d
check test format
Sep 18, 2024
2eaa4c5
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 18, 2024
e1a5b3e
check tests for current state
Sep 23, 2024
b46330d
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 23, 2024
8bc9018
added cx test
Sep 23, 2024
53200c5
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 23, 2024
4d13054
lint fixes
Sep 23, 2024
46aa58a
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 23, 2024
dfc0c83
removed io include
Sep 23, 2024
775a70f
Merge branch 'main' of https://github.com/Claudiaaaaaaaaa/mqt-ddsim
Sep 23, 2024
e4a994f
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 23, 2024
b74db3a
iostream
Sep 23, 2024
aabac4c
added more test cases
Sep 23, 2024
c31e7ec
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 23, 2024
39f426c
changed test names for lint
Sep 23, 2024
3f8c523
added final test
Sep 23, 2024
08bbc4e
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 23, 2024
6b74748
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Sep 23, 2024
08613ef
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Sep 26, 2024
39c22df
Update include/DDMinimizer.hpp
Claudiaaaaaaaaa Sep 26, 2024
1889992
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 26, 2024
e396757
Included all review changes
Sep 26, 2024
17670d1
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 26, 2024
77bc202
checked project guidelines -> ran clangd -> fixed issues
Sep 26, 2024
1bdbc4f
Merge branch 'cda-tum:main' into main
Claudiaaaaaaaaa Oct 14, 2024
3d79041
implemented changes of overseen comments
Oct 14, 2024
55364c4
🎨 pre-commit fixes
pre-commit-ci[bot] Oct 14, 2024
9d2c78b
added const for lint
Oct 14, 2024
e9db34f
small change in hopes to get token for coverage test
Oct 14, 2024
1551ada
Merge branch 'main' into main
burgholzer Oct 14, 2024
44f2ec0
✅ slightly more compact test circuit descriptions
burgholzer Oct 18, 2024
ee7eada
Merge branch 'main' into main
Claudiaaaaaaaaa Oct 28, 2024
9cab70f
implemented new suggested changes
Oct 28, 2024
375f8c4
🎨 pre-commit fixes
pre-commit-ci[bot] Oct 28, 2024
cf9bc98
ran clangd to pass pre commit check
Oct 28, 2024
893d3f9
Merge branch 'main' of https://github.com/Claudiaaaaaaaaa/mqt-ddsim
Oct 28, 2024
502d577
🎨 pre-commit fixes
pre-commit-ci[bot] Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions include/DDMinimizer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#include "Definitions.hpp"
#include "ir/Permutation.hpp"
#include "ir/QuantumComputation.hpp"

#include <cstddef>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

namespace qc {
class DDMinimizer {

public:
/**
* @brief Changes the order of qubits in a QuantumComputation to heuristically
* optimize for short running times of the DD-simulator.
* @detail Computes an initialLayout for the QuantumComputation based on a
* heuristic to optimize the running time of the DD-simulator. After that, the
* initialLayout is applied, i.e. the qubits in the QuantumComputation are
* re-ordered such that the resulting QuantumComputation's initialLayout is
* the identity again. The current implementation is based on patterns found
* in the controlled gates.
* @param QuantumComputation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param QuantumComputation
* @param param qc is the QuantumComputation to optimize the layout for

*/
static void optimizeInputPermutation(qc::QuantumComputation& qc);

/**
* @brief Computes a permutation for the QuantumComputation based on a
* heuristic to optimize the running time of the DD-simulator.
* @param QuantumComputation
* @return the qc::Permutation The computed permutation to be used as the
* initialLayout for a QuantumComputation
* @details First collects operation indices of controlled operation for
* patterns (s. makeDataStructure). Then, based on the pattern of the
* controlled gates, the layout is adjusted. If no pattern is found, the
* control based permutation is created.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param QuantumComputation
* @return the qc::Permutation The computed permutation to be used as the
* initialLayout for a QuantumComputation
* @details First collects operation indices of controlled operation for
* patterns (s. makeDataStructure). Then, based on the pattern of the
* controlled gates, the layout is adjusted. If no pattern is found, the
* control based permutation is created.
* @details First collects operation indices of controlled operation for
* patterns (s. makeDataStructure). Then, based on the pattern of the
* controlled gates, the layout is adjusted. If no pattern is found, the
* control based permutation is created.
* @param qc is the QuantumComputation to optimize the layout for
* @return the qc::Permutation The computed permutation to be used as the
* initialLayout for a QuantumComputation

*/
static qc::Permutation createGateBasedPermutation(qc::QuantumComputation& qc);

// Helper functions for createGateBasedPermutation
/**
* @brief creates a data structure for the pattern analysis of controlled gates
* @param QuantumComputation
* @return a pair of maps to save indices of controlled gates
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I would recommend the order @brief, @details, @param, @return as this conincides how the information would be displayed in docs generated by doxygen, for example.

* @details the data structure consists of two maps:
* 1. map: string of ladder (step) name to control and target bit to the index
of the operation
* 2. map: string of ladder name to vector: max index of operation for each
step or the c_x or x_c ladder
* for c_l and x_l position 0 in the vector marks the line of c(x) at 0 -> we
count the left most as the first
* for c_r and x_r position 0 in the vector marks the line of c(x) at bits - 1
-> we count theright most as the first
*
* The ladder (steps) describe the following controlled gates (c: control
qubit, x: target qubit): e.g. for three qubits
* c_x: c | 0 1 2
x | 1 2 3

* x_c: c | 1 2 3
x | 0 1 2

* c_l_1: c | 0 0 0 and c_l_2: c | 1 1 and c_l_3: c | 2
x | 1 2 3 x | 2 3 x | 3

* c_r_1: c | 3 3 3 and c_r_2: c | 2 2 and c_r_3: c | 1
x | 0 1 2 x | 0 1 x | 0

* x_l_1: c | 1 2 3 and x_l_2: c | 2 3 and x_l_3: c | 3
x | 0 0 0 x | 1 1 x | 2

* x_r_1: c | 0 1 2 and x_r_2: c | 0 1 and x_r_3: c | 0
x | 3 3 3 x | 2 2 x | 1

*/
static std::pair<
std::map<std::string, std::map<std::pair<Qubit, Qubit>, int>>,
std::map<std::string, std::vector<int>>>
makeDataStructure(qc::QuantumComputation& qc);

static void initializeDataStructure(
std::size_t bits, std::map<std::pair<Qubit, Qubit>, int>& xCMap,
std::map<std::pair<Qubit, Qubit>, int>& cXMap,
std::vector<std::map<std::pair<Qubit, Qubit>, int>>& cLMap,
std::vector<std::map<std::pair<Qubit, Qubit>, int>>& cHMap,
std::vector<std::map<std::pair<Qubit, Qubit>, int>>& xLMap,
std::vector<std::map<std::pair<Qubit, Qubit>, int>>& xHMap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I am looking at this function with very special arguments, I wonder whether it might be better to have the variables that are arguments right now as members of the class. Then, the function would not have any arguments but, when called, would still initialize the class members.

Additionally: Does that function need to be public, or can it be private? This already applies to the function above, I guess.


static int findMaxIndex(const std::map<std::pair<Qubit, Qubit>, int>& map);

// Functions to analyze the pattern of the controlled gates
static bool isFullLadder(const std::vector<int>& vec);
static std::size_t getStairCount(const std::vector<int>& vec);
static int getLadderPosition(const std::vector<int>& vec, int ladder);

// Functions to adjust the layout based on the pattern of the controlled
// gates:

/**
* @brief Helper function to reverse the layout (q: qubit, l: layer)
* @param layout
* @return the reversed layout
* @details q | 0 1 2 3 turns to q | 0 1 2 3
* l | 0 1 2 3 l | 3 2 1 0
*/
static std::vector<Qubit> reverseLayout(std::vector<Qubit>& layout);

/**
* @brief Helper function to rotate the layout to the right (q: qubit, l:
* layer)
* @param layout, stairs (number of steps to rotate)
* @return the rotated layout
* @details q | 0 1 2 3 and 1 stairs turns to q | 0 1 2 3
* l | 0 1 2 3 l | 1 2 3 0
*/
static std::vector<Qubit> rotateRight(std::vector<Qubit> layout,
std::size_t stairs);

/**
* @brief Helper function to rotate the layout to the left (q: qubit, l:
* layer)
* @param layout, stairs (number of steps to rotate)
* @return the rotated layout
* @details q | 0 1 2 3 and 2 stairs turns to q | 0 1 2 3
* l | 0 1 2 3 l | 3 0 1 2
*/
static std::vector<Qubit> rotateLeft(std::vector<Qubit> layout,
std::size_t stairs);

/**
* @brief creates a Heuristic based initialLayout for the QuantumComputation.
This implementation is based on which qubits are controlled by whichqubits
* @param QuantumComputation
* @return the qc::Permutation
* @details The function creates a map of each qubit to all the qubits it
controls.
* Based on the control to target relationship, a weight for each qubit is
calculated.
* The qubits are then sorted based on the weight in increasing order,
* each controlling qubit is placed after its targets
*/
static qc::Permutation
createControlBasedPermutation(qc::QuantumComputation& qc);

// Helper function for createControlBasedPermutation

/**
* @brief recursively adjusts the weights of the qubits based on the control
* and target qubits
* @param map of qubit to weight, current set of target qubits, current
* control qubit, overall map of control qubit to target qubits, count of
* recoursive calls
* @return adjusted map of qubit to weight
*/
static std::map<Qubit, int>
adjustWeights(std::map<Qubit, int> qubitWeights,
const std::set<Qubit>& targets, Qubit ctrl,
const std::map<Qubit, std::set<Qubit>>& controlToTargets,
int count);

/**
* @brief creates a vector of all possible permutations of the initialLayout
used for first implementation of testing all Permutations and
drawing conclusions
* @param QuantumComputation
*/
static std::vector<qc::Permutation>
createAllPermutations(qc::QuantumComputation& qc);

/**
* @brief Helper function to compute how many permutations there are for a set
* number of qubits
* @param number of Bits
*/
static std::size_t factorial(std::size_t n);

}; // class DDMinimizer
} // namespace qc
Loading
Loading