Skip to content

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Feb 27, 2021

Summary

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

Details and comments

This depends on #5926

@mtreinish mtreinish added on hold Can not fix yet performance labels Feb 27, 2021
@mtreinish mtreinish requested review from chriseclectic and a team as code owners February 27, 2021 20:07
@mtreinish mtreinish added this to the 0.17 milestone Feb 27, 2021
Copy link
Member

@levbishop levbishop left a 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:

  1. 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
  2. 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)

@mtreinish
Copy link
Member Author

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:

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

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

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__.
@mtreinish mtreinish force-pushed the disable-unitary-check branch from 9a2711b to 809cfd5 Compare March 5, 2021 16:53
@mtreinish mtreinish requested a review from levbishop March 5, 2021 16:54
@mtreinish mtreinish removed the on hold Can not fix yet label Mar 5, 2021
Copy link
Member

@levbishop levbishop left a 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

@mtreinish
Copy link
Member Author

Running the same script as I did in: #5926 (comment) the results for me locally were:

version time (in sec)
master 22.62060546875
#5928 (this PR) 15.05669116973877

@mergify mergify bot merged commit bf2bd53 into Qiskit:master Mar 5, 2021
@kdk kdk added the Changelog: None Do not include in changelog label Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants