-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add option to 1q euler decomposer for disabling unitary check #5928
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
Conversation
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.
The idea of having a way to bypass consistency checks internally makes sense to me, but I prefer a different API for this kind of thing:
- Instead of a user-visible flag, can we have an internal
_decompose()
method that skips the checks, and have the user-visible__call__
do the checks and then go to_decompose
for the (dangerous) implementation - For the internal API can we have the implementation work only with ndarray, and push the
to_operator
,to_matrix
,np.asarray
stuff for the user-facing friendly API (this should give a small additional perf boost)
516c5ec
to
9a2711b
Compare
Yeah, that's a good idea and a pattern more consistent with the rest of qiskit too. I've pivoted to use the private method instead of the kwarg in: 9a2711b |
Previously when running the OneQubitEulerDecomposer the first step it would perform is a check that the input matrix is a 1 qubit unitary. However, in situations when we're explicitly generating a unitary matrix and know the input we're passing is unitary there is no need to run this check and it adds unecessary overhead to the process. This commit adds a new kwarg, check_unitary, to the __call__ method on the OneQubitEulerDecomposer which when set to False will skip the unitary check to avoid this overhead. The flag is then set when the decomposer is called from the Optimize1qGatesDecomposition, UnitarySynthesis passes, and TwoQubitBasisDecomposer to avoid the overhead when we know the input is unitary.
This commit pivots to using an inner private method that doesn't have the validation instead of having a kwarg to disable the unitary check. This means the end user doesn't have the option to disable the validation which could potential cause issues but for internal qiskit usage when we know the input is valid we just call the inner method instead of __call__.
9a2711b
to
809cfd5
Compare
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.
LGTM. If its not too much trouble, be nice to post perf numbers before/after to get a sense of how much this kind of thing matters - If this makes a big difference I'll fold the analog for TwoQubitBasisDecomposer
into my PR #5827 changes
Running the same script as I did in: #5926 (comment) the results for me locally were:
|
Summary
Previously when running the
OneQubitEulerDecomposer
the first stepit would perform is a check that the input matrix is a 1 qubit unitary.
However, in situations when we're explicitly generating a unitary matrix
and know the input we're passing is unitary there is no need to run this
check and it adds unnecessary overhead to the process. This commit adds a
new kwarg, check_unitary, to the
__call__
method on theOneQubitEulerDecomposer
which when set to False will skip the unitarycheck to avoid this overhead. The flag is then set
when the decomposer is called from the
Optimize1qGatesDecomposition
,UnitarySynthesis
passes, andTwoQubitBasisDecomposer
to avoid theoverhead when we know the input is unitary.
Details and comments
This depends on #5926