Skip to content
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

Change collect_1q_runs return for performance #5685

Merged
merged 1 commit into from
Jan 22, 2021

Conversation

mtreinish
Copy link
Member

Summary

Currently the return type from collect_1q_runs is being converted from
the 'list(list(DAGNode))' which is returned by retworkx.collect_runs()
to be 'set(tuple(DAGNode))' so that it is consistent with the return
type from collect_runs(). However, this ends up adding significant
overhead to the collect_1q_runs method and ends up being the bottleneck.
We spend more time running the set expression to convert from the list
than we do in rx.collect_runs() (mainly the filter function). Since
collect_1q_runs hasn't been included in a release yet we can change the
return type without breaking users and avoid this extra overhead. This
commit does that and removes the set comprehension and just returns the
nested list directly from retworkx.collect_runs().

Details and comments

Currently the return type from collect_1q_runs is being converted from
the 'list(list(DAGNode))' which is returned by retworkx.collect_runs()
to be 'set(tuple(DAGNode))' so that it is consistent with the return
type from collect_runs(). However, this ends up adding significant
overhead to the collect_1q_runs method and ends up being the bottleneck.
We spend more time running the set expression to convert from the list
than we do in rx.collect_runs() (mainly the filter function). Since
collect_1q_runs hasn't been included in a release yet we can change the
return type without breaking users and avoid this extra overhead. This
commit does that and removes the set comprehension and just returns the
nested list directly from retworkx.collect_runs().
@mtreinish mtreinish requested a review from a team as a code owner January 22, 2021 20:34
@mtreinish
Copy link
Member Author

Looking at the profile of collect_1q_runs when running Optimize1qGatesDecomposition over a 65x4096 random circuit goes from:

Screenshot_2021-01-22_15-36-03

without this PR.

To:

Screenshot_2021-01-22_15-40-20

With this PR applied.

@mtreinish mtreinish added this to the 0.17 milestone Jan 22, 2021
Copy link
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Would it make sense to update the return type on the stable branch?

@kdk kdk added the automerge label Jan 22, 2021
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Jan 22, 2021
The collect_1q_runs method was rewritten in python as part of the
backport of a larger bugfix in the Optimize1qGatesDecomposition
transpiler pass in Qiskit#5655. However, it is not part of the public api in
0.16.x and was only backported to fix the bug in
Optimize1qGatesDecomposition. Since the version included on the master
branch will be subtlely different in return type (after Qiskit#5685) Since we
don't want to advertise the method until it's included in the public api
this commit prepends '_' making the method name _collect_1q_runs to
indicate it is internal only as part of the 0.16.2 release.
@mtreinish
Copy link
Member Author

This looks good. Would it make sense to update the return type on the stable branch?

We can but as part of: #5686 I marked the backported python version of the function as private. So we won't be breaking any potential backwards compatibility contract if someone starts using it in 0.16.2.

@mergify mergify bot merged commit 6e25422 into Qiskit:master Jan 22, 2021
@mtreinish mtreinish deleted the collect-1q-return-type branch January 22, 2021 21:59
mtreinish added a commit that referenced this pull request Jan 26, 2021
* Prepare 0.16.2 release

This commit prepares for the 0.16.2 release by bumping the version
strings to reflect the new version. This is just a bugfix release
that several fixes for bugs introduced in 0.16.1.

* Mark DAGCircuit collect_1q_runs private

The collect_1q_runs method was rewritten in python as part of the
backport of a larger bugfix in the Optimize1qGatesDecomposition
transpiler pass in #5655. However, it is not part of the public api in
0.16.x and was only backported to fix the bug in
Optimize1qGatesDecomposition. Since the version included on the master
branch will be subtlely different in return type (after #5685) Since we
don't want to advertise the method until it's included in the public api
this commit prepends '_' making the method name _collect_1q_runs to
indicate it is internal only as part of the 0.16.2 release.

* Cleanup release notes
@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.

2 participants