-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Lukas Burgholzer <[email protected]> Signed-off-by: ClaudiaDuenzinger <[email protected]>
Co-authored-by: Lukas Burgholzer <[email protected]> Signed-off-by: ClaudiaDuenzinger <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #407 +/- ##
=======================================
- Coverage 92.4% 92.4% -0.1%
=======================================
Files 37 38 +1
Lines 2731 2943 +212
Branches 310 363 +53
=======================================
+ Hits 2526 2722 +196
- Misses 205 221 +16
*This pull request uses carry forward flags. Click here to find out more.
|
Signed-off-by: ClaudiaDuenzinger <[email protected]>
Signed-off-by: ClaudiaDuenzinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Claudiaaaaaaaaa, many thanks for this PR. Overall it looks very good already, especially, all the test pass already. That is really good. I went through your code in quite some detail and left a couple of comments. At first glance it looks like a lot but some you can just apply by clicking on accept
if you agree. Once again, thank you for your effort. Your work is highly appreciated.
Co-authored-by: Yannick Stade <[email protected]> Signed-off-by: ClaudiaDuenzinger <[email protected]>
@Claudiaaaaaaaaa Edit: This should hopefully be fixed by #448. Edit 2: apparently, it wasn't fixed 😢 |
(mainly to trigger CI with the new workflows) Signed-off-by: burgholzer <[email protected]>
Ok, the CI errors should be resolved now. They were due to a regression in the codecov action that would request an OIDC token even from forks (which do not have the right permissions). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Claudiaaaaaaaaa,
This looks pretty good right now. I only found two major concerns, the rest is just nitpicking. Would you be kind and shed some light on my questions? Thanks for your awesome job.
include/DDMinimizer.hpp
Outdated
* 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param QuantumComputation | |
* @param param qc is the QuantumComputation to optimize the layout for |
include/DDMinimizer.hpp
Outdated
* @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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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 |
include/DDMinimizer.hpp
Outdated
* @param QuantumComputation | ||
* @return a pair of maps to save indices of controlled gates |
There was a problem hiding this comment.
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.
include/DDMinimizer.hpp
Outdated
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); |
There was a problem hiding this comment.
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.
src/DDMinimizer.cpp
Outdated
std::vector<Qubit> layer(bits); | ||
for (qc::Qubit i = 0; i < bits; i++) { | ||
layer[i] = i; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand the use of layer
. If I am not mistaken, layer
serves as an identity mapping.
If you have trouble with converting std::size_t
to qc::Qubit
you can use cast functions, e.g., static_cast<qc::Qubit>(...)
.
src/DDMinimizer.cpp
Outdated
int maxIndex = -1; // Initialize to the smallest possible value | ||
|
||
for (const auto& entry : map) { | ||
if (entry.second == -1) { | ||
maxIndex = -1; | ||
break; | ||
} | ||
if (entry.second > maxIndex) { | ||
maxIndex = entry.second; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the name of the function and the code, I expect that it returns the maximum value
of all key
, value
pairs (even though findMaxIndex
might be missleading since Index
would suggest key not value).
I do not understand why the maxIndex
is reset to -1 if the value
of -1 is encountered. Is there a reason for that? If yes, I think then the output of the function depends on the order the map returns the elements which can be arbitrary and the return value should be independent from the order. However, maybe I am overseeing here something. Then let me know.
src/DDMinimizer.cpp
Outdated
if (count == static_cast<int>(controlToTargets.size())) { | ||
return qubitWeights; | ||
} | ||
// recoursively increase all the weights of the control qubits where the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// recoursively increase all the weights of the control qubits where the | |
// recursively increase all the weights of the control qubits where the |
@burgholzer, this code looks quite clean right now. I just submitted another review that, however, only contains very few requests. Perhaps, if you find the time, you can also already have a look. |
Description
The running time of DDs depends on the order of the nodes in the diagram. In the package DDsim we implement a tool that tries to find the optimal or near-optimal order of nodes resulting in the minimal running time. All changes required in MQT-core are contained in this PR.
Checklist: