-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Stop building decomposition dag at instance creation #1445
Conversation
luciano sped things up in #1455 by making sure that |
ugh, well that makes rebasing this fun :) I'll do that right now |
This commit adjust how we define decompositions for gates. Previously we ran a function which built a dag of the decompositions during __init__ for the gate class. This meant we'd build a new dag every time we created a new gate, which for large circuits would start to add up. However, the decompositions are static for most gates and we only need to run it once. To accomplish that this commit makes the decompositions a class defined parameter and removes it from __init__. This way we only ever build the decomposition dags once unless explicitly needed. Gates that are not touched: crz, cu1, cu3, rx, ry, rz, rzz, u1, u2, u3, are left alone because the decomposition depends on run time variables in the instance and this optimization provides no benefit. Fixes Qiskit#1441
a0827ea
to
c577f42
Compare
0334855
to
b351a07
Compare
Sorry for the overlapping, it was part of moving the unroller as a pass :( |
Since #1441 is closed, I'm closing this PR. |
I would still like to do what Matthew did in this PR. It provides further speedups to what was already achieved. However, this PR is probably already quite out of sync with master, so might make sense to open a new PR. I'll open an issue. |
When we have a conditional applied during decomposition we modify the decomposition dag to contain the conditional. However, since in many cases now we have a single global instance of the decomposition dag for a gate doing this is a bad idea. This will lead to the conditional persiting for all future decompositions of the gate whether there is one or not. To avoid this issue this commit adds a deepcopy() call to make a duplicate of the decomposition dag for when we have a conditional so we do not modify the original global decomposition dag.
Hmm, it looks like we're still modifying |
I'm closing this PR because it has conflicts with the current master. Feel free to open a new PR for closing #1729 ! |
@1ucian0 It's unlikely to be feasible while we're still modifying the dag in place. If we move to shared instance for any dag (including the decomposition dags like this commit) this gets really messy since those in place modifications effect the global/shared instance. We have to stop doing that as a first step before this is really something we can consider, especially weighed against the modest performance benefits I was seeing locally (there might be some edge cases I'm missing though) |
Summary
This commit adjust how we define decompositions for gates. Previously we
ran a function which built a dag of the decompositions during
__init__
for the gate class. This meant we'd build a new dag every time we
created a new gate, which for large circuits would start to add up.
However, the decompositions are static for most gates and we only need
to run it once. To accomplish that this commit makes the decompositions
a class defined parameter and removes it from
__init__
. This way we onlyever build the decomposition dags once unless explicitly needed.
Gates that are not touched: crz, cu1, cu3, rx, ry, rz, rzz, u1, u2, u3,
are left alone because the decomposition depends on run time variables
in the instance and this optimization provides no benefit.
Details and comments
Fixes #1729