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

Optimise data transfer in TopologicalSorter #1159

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Apr 5, 2024

This optimises the creation of the list objects returned from TopologicalSorter.get_ready (by avoiding a temporary Vec) and allows done to accept a single index, avoiding the need for the user to allocate many small lists in several real-world uses.

This is the overload version of #1157. Happy to change it to a separate function if desired.

Close #1157


With a setup of:

from qiskit.circuit.library import EfficientSU2
from qiskit.converters import circuit_to_dag

import rustworkx

dag = circuit_to_dag(EfficientSU2(100, reps=5, flatten=True), copy_operations=False)._multi_graph

(I was using Qiskit 1.0.2 "ish", but it doesn't matter much) and a timing script:

sorter = rustworkx.TopologicalSorter(dag, check_cycle=False, check_args=False)
while ready := sorter.get_ready():
    for node in ready:
        sorter.done(node)

for this PR, and sorter.done([node]) (with a list) for main, I found main took ~510µs and this PR took ~275µs on my machine.

That's a common pattern for how we want to use this in Qiskit, though we'll only conditionally be calling done on some nodes, which is why the overhead of managing lists really hurts us.

This optimises the creation of the `list` objects returned from
`TopologicalSorter.get_ready` (by avoiding a temporary `Vec`) and allows
`done` to accept a single index, avoiding the need for the user to
allocate many small lists in several real-world uses.
@coveralls
Copy link

coveralls commented Apr 5, 2024

Pull Request Test Coverage Report for Build 8638783196

Details

  • 54 of 58 (93.1%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.02%) to 96.505%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/toposort.rs 54 58 93.1%
Files with Coverage Reduction New Missed Lines %
src/toposort.rs 1 92.24%
Totals Coverage Status
Change from base Build 8576567307: -0.02%
Covered Lines: 17311
Relevant Lines: 17938

💛 - Coveralls

Copy link
Contributor

@enavarro51 enavarro51 left a comment

Choose a reason for hiding this comment

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

Just a couple of questions and then this looks about ready to go.

src/toposort.rs Show resolved Hide resolved
src/toposort.rs Show resolved Hide resolved
src/toposort.rs Show resolved Hide resolved
Copy link
Contributor

@enavarro51 enavarro51 left a comment

Choose a reason for hiding this comment

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

LGTM.

@enavarro51 enavarro51 added the automerge Queue a approved PR for merging label Apr 10, 2024
@mergify mergify bot merged commit ac2aa88 into Qiskit:main Apr 10, 2024
30 checks passed
@jakelishman jakelishman deleted the toposort-speedup branch April 11, 2024 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Queue a approved PR for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow single node indices in TopologicalSorter.done
3 participants