-
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
Adapt commutation checker to abstract circuits #11948
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 8176499038Details
💛 - Coveralls |
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.
Overall this lgtm, I left a couple small comments inline. Could you also add some tests to validate the checker works with annotated operations correctly?
# this might be runtime-intensive in general so we should attempt to branch out before running this | ||
# it may be more runtime-efficient to check for entries in the commutation library before | ||
try: | ||
Operator(op) |
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.
Not that I expect this will come up in practice very often, but if this is expensive to compute in some cases wouldn't it be better to only do this once? Right now you'll run this twice, once to check for a skip and later again as part of _commute_matmul
.
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.
Yes, I agree. However, I would need to refactor the commutation checker quite a bit and I wanted to do this PR quickly. :-) Is it okay to leave it as is? I also suspect that this part of the function should not be executed often in practice.
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 think it's fine to leave it as is, but maybe put a TODO comment or something in there to indicate longer term it'd be better to de-duplicate the Operator()
call.
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 shifted the Operator()
resolution to _commute_matmul
- while this would lead to unnecessary checks for operations that do not have a suitable Operator
resolution, I would expect these checks to be comparatively lightweight.
I added a couple of tests for annotated operations. I was surprised to find that |
Oh, yeah that is a surprise, maybe this is a good reason we should migrate to |
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.
Code-wise this LGTM now, I just had an inline suggestion in the release note to provide a bit more context about the feature for users. A code example showing what you can do with it now never hurts either.
releasenotes/notes/abstract-commutation-analysis-3518129e91a33599.yaml
Outdated
Show resolved
Hide resolved
…599.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Makes sense, thanks! |
* Update commutation_checker.py * reno * new tests * Update commutation_checker.py * remove Operator resolution in commutation pre-check * Update releasenotes/notes/abstract-commutation-analysis-3518129e91a33599.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org> --------- Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Summary
addresses #11911 and PR #11929
Details and comments
Quantum circuit compilation can be improved by running optimization passes based on commutative analysis before solving the routing problem. Formerly, commutative analysis was only applied to "physical circuits", i.e. entirely specified by
Instructions
that are readily defined by the unitary matrices of the instructions. Applying commutative analysis before routing requires handling abstract instructions (Operators
) that may or may not be defined by a matrix directly. However, the matrix specification of an instruction is required to determine its commutativity.This PR extends the current commutation analysis that only works on physical circuits defined over
Instructions
to handle abstract instructions, i.e. checking whether an instruction has a matrix representation and exiting early if otherwise before proceeding to determine the commutation relation.