Skip to content

Conversation

mtreinish
Copy link
Member

Summary

This commit updates the nosie adaptive layout transpiler pass to use
retworkx for its internal graph operations. Prior to this commit it was
constructing 2 networkx graphs internally. These have been replaced with
equivalent structures in retworkx. At the same time some of the
algorithms used were generating extraneous information that was never
used this is removed.

Details and comments

This commit updates the nosie adaptive layout transpiler pass to use
retworkx for its internal graph operations. Prior to this commit it was
constructing 2 networkx graphs internally. These have been replaced with
equivalent structures in retworkx. At the same time some of the
algorithms used were generating extraneous information that was never
used this is removed.
@mtreinish mtreinish requested a review from a team as a code owner September 23, 2020 17:26
1ucian0
1ucian0 previously approved these changes Sep 23, 2020
@kdk kdk added the on hold Can not fix yet label Sep 23, 2020
@kdk
Copy link
Member

kdk commented Sep 23, 2020

'on hold' for a possible performance regression @mtreinish was looking into.

@mtreinish mtreinish removed the on hold Can not fix yet label Sep 24, 2020
@mtreinish
Copy link
Member Author

I've been testing this locally I still think there might be a weird edge case and something else going on. But after applying 044ff1d I used this script to benchmark the performance:

import time

from qiskit.circuit.library import QuantumVolume
from qiskit.converters import circuit_to_dag
from qiskit.test.mock.backends import FakeManhattan
from qiskit.transpiler.passes import NoiseAdaptiveLayout

seed = 42
circuit = QuantumVolume(65, 65, seed=42)
circuit.measure_all()
fresh_dag = circuit_to_dag(circuit)
backend_props = FakeManhattan().properties()
start = time.time()
NoiseAdaptiveLayout(backend_props).run(fresh_dag)
stop = time.time()
print("Total: %s" % str(stop - start))

On my laptop with this PR it took ~.0092 seconds with this PR. Without this PR it took ~0.028 seconds. So I think 044ff1d fixed the issue (don't ask me why though, it's still confusing to me that dict access would be faster)

@kdk
Copy link
Member

kdk commented Sep 25, 2020

Here are the timings I found locally for @mtreinish 's script:

detached@b25b49df77 $ for _ in $(seq 10); do python test_5117_retworkx_noise_adaptive_swap.py ; done
Total: 0.021281957626342773
Total: 0.019123077392578125
Total: 0.018626928329467773
Total: 0.018460988998413086
Total: 0.030744075775146484
Total: 0.017805099487304688
Total: 0.019776105880737305
Total: 0.0181729793548584
Total: 0.01812005043029785
Total: 0.019826173782348633
master $ for _ in $(seq 10); do python test_5117_retworkx_noise_adaptive_swap.py ; done
Total: 0.13488388061523438
Total: 0.13796710968017578
Total: 0.13009214401245117
Total: 0.12714099884033203
Total: 0.13192486763000488
Total: 0.13408303260803223
Total: 0.1278080940246582
Total: 0.13918709754943848
Total: 0.12842297554016113
Total: 0.1287848949432373

@kdk kdk added the automerge label Sep 25, 2020
@mergify mergify bot merged commit 3ed4d18 into Qiskit:master Sep 25, 2020
@mtreinish mtreinish deleted the use-retworkx-noiseadaptive-layout branch September 25, 2020 15:07
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Sep 29, 2020
This commit fixes a performance regression introduced in Qiskit#5117 when
there were a large number of gates in the circuit being run through the
pass. The overhead of calling adj() a significant number of times was
adding a runtime penalty. Its not clear what is causing this with
retworkx but my assumption is it is related to going back and forth
between rust and python. This commit mitigates most of this overhead by
locally caching the list of neighbors each time we call
_select_best_remaining_qubit().
mergify bot pushed a commit that referenced this pull request Oct 6, 2020
* Avoid excessive neighbor discovery in NoiseAdaptiveLayout

This commit fixes a performance regression introduced in #5117 when
there were a large number of gates in the circuit being run through the
pass. The overhead of calling adj() a significant number of times was
adding a runtime penalty. Its not clear what is causing this with
retworkx but my assumption is it is related to going back and forth
between rust and python. This commit mitigates most of this overhead by
locally caching the list of neighbors each time we call
_select_best_remaining_qubit().

* Avoid shared instance state

* Appease pylint pedantry

Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Nov 18, 2020
In Qiskit#5117 the noise adaptive layout pass was updated to use retworkx
internally for performance. In that PR there were a couple of TODO
comments added about using neighbors methods when they were released.
The retworkx 0.6.0 release was pushed last week so we can update the
usage and remove the TODO comments. The neighbors methods should have
lower overhead since it only returns a list of node indices instead of a
dictionary of (node index, edge weight). This will also get
significantly faster (for large neighbors lists) with
Qiskit/rustworkx#198.
mergify bot added a commit that referenced this pull request Dec 9, 2020
In #5117 the noise adaptive layout pass was updated to use retworkx
internally for performance. In that PR there were a couple of TODO
comments added about using neighbors methods when they were released.
The retworkx 0.6.0 release was pushed last week so we can update the
usage and remove the TODO comments. The neighbors methods should have
lower overhead since it only returns a list of node indices instead of a
dictionary of (node index, edge weight). This will also get
significantly faster (for large neighbors lists) with
Qiskit/rustworkx#198.

Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants