-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Translate parameterized gates only in gradient calculations #9067
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Tagging @a-matsuo for review 🙂 |
Pull Request Test Coverage Report for Build 3750990070
💛 - Coveralls |
It looks good for me except which directory we should put the code as @t-imamichi mentioned. |
combine not necessary as no arguments were combined, use data for simplicity
FYI in d567074 I also removed trailing classical registers that weren't used in the LCU gradients (+ QFI) if the |
Thank you @Cryoris LGTM! |
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 only looked at the transpiler pass, but I left a few comments inline. The biggest thing for me is we should add Target
support from the start to this pass, especially because the BasisTranslator
which is used internally already supports working with the Target
.
Once a parameterized instruction is found that is not in the ``supported_gates`` list, | ||
the instruction is decomposed one level and the parameterized sub-blocks are recursively | ||
decomposed. The recursion is stopped once all parameterized gates are in ``supported_gates``, | ||
or if a gate has no definition and a translation to the basis is attempted (this might happen | ||
e.g. for the ``UGate`` if it's not in the specified gate list). |
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.
How is this different than the unroll* passes which effectively do this already? Looking at the code it's because this only unrolls parameterized gates, but if we adding another pass to do this we should probably call out why you'd want to use this instead of any of those.
The other related question is whether we want to add this functionality to an existing pass.
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.
Good point, it's unrolling plus translating if the unrolling didn't reach the target base. If it were only unrolling then we could add a criterion
function or something to the Unroller
which we could set to detect parameterized gates. Then we could afterwards do a translation pass on the gates which are not yet in the right basis. So this pass here would be something like
def is_parameterized(gate):
# returns True if ``gate`` is parameterized, else False
this_pass = PassManager([
Unroller(basis_gates, criterion=is_parameterized),
BasisTranslator(...)
])
That would of course mean that we have to construct this pass manually, but since this is used often in gradient calculations I thought it might be generally useful -- but we can also do the above!
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
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.
Thanks for adding the target support, just two small inline comments about it
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 just left one question inline, but I had a question inline and I'm not sure how you want to proceed with regards to that. I'm fine either keeping the qubit restriction on the target lookup or dropping it depend on the expectations around the pass. So I'm karking this as approved, but if you want to change that line go ahead and feel free to merge this without waiting on a re-approval from me.
that's because this pass is run before qubit mapping
…erra into translate-parameterized
) * translate parameterized gates only * TranslateParameterized to proper pass * update reno w/ new trafo pass * Only add cregs if required * rm unused import * directly construct DAG Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * target support * qubit-wise support of unrolling * globally check for supported gates in target that's because this pass is run before qubit mapping * lint! * updates after merge from main Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) * translate parameterized gates only * TranslateParameterized to proper pass * update reno w/ new trafo pass * Only add cregs if required * rm unused import * directly construct DAG Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * target support * qubit-wise support of unrolling * globally check for supported gates in target that's because this pass is run before qubit mapping * lint! * updates after merge from main Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) * translate parameterized gates only * TranslateParameterized to proper pass * update reno w/ new trafo pass * Only add cregs if required * rm unused import * directly construct DAG Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * target support * qubit-wise support of unrolling * globally check for supported gates in target that's because this pass is run before qubit mapping * lint! * updates after merge from main Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…iskit#9067) * translate parameterized gates only * TranslateParameterized to proper pass * update reno w/ new trafo pass * Only add cregs if required * rm unused import * directly construct DAG Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * target support * qubit-wise support of unrolling * globally check for supported gates in target that's because this pass is run before qubit mapping * lint! * updates after merge from main Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
Closes #9054.
Details and comments
All gradient now preserve unparameterized operations instead of attempting to unroll them.
This