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

Conversation

Claudiaaaaaaaaa
Copy link

@Claudiaaaaaaaaa Claudiaaaaaaaaa commented Jul 24, 2024

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:

  • The pull request only contains commits that are related to it.
  • I have added appropriate tests and documentation.
  • I have made sure that all CI jobs on GitHub pass.
  • The pull request introduces no new warnings and follows the project's style guidelines.

src/DDMinimizer.cpp Outdated Show resolved Hide resolved
src/DDMinimizer.cpp Outdated Show resolved Hide resolved
Claudiaaaaaaaaa and others added 3 commits July 25, 2024 13:27
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]>
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 94.31280% with 12 lines in your changes missing coverage. Please review.

Project coverage is 92.4%. Comparing base (c085296) to head (502d577).

Files with missing lines Patch % Lines
src/DDMinimizer.cpp 94.3% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           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     
Flag Coverage Δ *Carryforward flag
cpp 94.1% <94.3%> (-0.2%) ⬇️ Carriedforward from 375f8c4
python 87.4% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
src/DDMinimizer.cpp 94.3% <94.3%> (ø)

... and 1 file with indirect coverage changes

Copy link
Collaborator

@ystade ystade left a 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.

include/DDMinimizer.hpp Outdated Show resolved Hide resolved
include/DDMinimizer.hpp Outdated Show resolved Hide resolved
include/DDMinimizer.hpp Outdated Show resolved Hide resolved
include/DDMinimizer.hpp Outdated Show resolved Hide resolved
src/DDMinimizer.cpp Outdated Show resolved Hide resolved
src/DDMinimizer.cpp Show resolved Hide resolved
src/DDMinimizer.cpp Outdated Show resolved Hide resolved
src/DDMinimizer.cpp Outdated Show resolved Hide resolved
src/DDMinimizer.cpp Outdated Show resolved Hide resolved
src/DDMinimizer.cpp Outdated Show resolved Hide resolved
@burgholzer
Copy link
Member

burgholzer commented Oct 14, 2024

@Claudiaaaaaaaaa
Don't worry too much about the failing coverage uploads here at the moment. These are due to your PR originating from a fork, which, apparently, doesn't give the GitHub token the necessary permissions for uploads based on OIDC.
I'll look into whether this can be fixed.

Edit: This should hopefully be fixed by #448.
Guess we will see once that PR is in and you can merge the main branch into the PR here.

Edit 2: apparently, it wasn't fixed 😢

(mainly to trigger CI with the new workflows)

Signed-off-by: burgholzer <[email protected]>
@burgholzer
Copy link
Member

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).
To trigger CI, I took the liberty to slightly simplify the test circuits.

Copy link
Collaborator

@ystade ystade left a 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.

* 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

Comment on lines 32 to 38
* @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

Comment on lines 45 to 46
* @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.

Comment on lines 83 to 89
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.

Comment on lines 168 to 171
std::vector<Qubit> layer(bits);
for (qc::Qubit i = 0; i < bits; i++) {
layer[i] = i;
}
Copy link
Collaborator

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>(...).

Comment on lines 215 to 226
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;
}
}

Copy link
Collaborator

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.

if (count == static_cast<int>(controlToTargets.size())) {
return qubitWeights;
}
// recoursively increase all the weights of the control qubits where the
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
// recoursively increase all the weights of the control qubits where the
// recursively increase all the weights of the control qubits where the

@ystade
Copy link
Collaborator

ystade commented Oct 28, 2024

@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.

@ystade ystade marked this pull request as ready for review October 28, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants