Leverage retworkx generators for all cmap constructors#5469
Merged
mergify[bot] merged 3 commits intoDec 4, 2020
Merged
Conversation
In Qiskit#5183 we switched the internal graph datastructures used for the CouplingMap to be based on retworkx instead of networkx. That PR was written against the 0.6.0 retworkx release and for the from_grid() and from_full() constructors python had to be used since retworkx was missing functions to generate graphs of those types. However, in the recent 0.7.x retworkx release 2 new generators directed_grid_graph() [1] and directed_mesh_graph() [2] were added. This commit switches the implementation of from_grid() and from_full() to use these generators, which significantly speeds up (and reduces the memory overhead) of the constructor methods. The only constructor which still relies on a Python loop is the from_full() method when bidirection=False. This is because retworkx doesn't offer a constructor that will build a graph like that. If in a future release a generator is added we can remove that for loop too. [1] https://retworkx.readthedocs.io/en/stable/stubs/retworkx.generators.directed_grid_graph.html [2] https://retworkx.readthedocs.io/en/stable/stubs/retworkx.generators.directed_mesh_graph.html
Member
Author
|
I ran some quick benchmarks on this: (both graphs are iog-log) It's also worth noting that I ran these on my laptop with only 16GB of ram which wasn't enough for the Python full case, and at around 10k nodes it consumed all the available ram and started swapping pretty heavily which is probably why run time spiked there. This wasn't an issue on the retworkx constructor. for i in np.logspace(1, 6, 20, dtype=int):
dim = int(math.sqrt(i))
start = time.time()
temp = CouplingMap.from_grid(dim, dim)
stop = time.time()
del temp
for i in np.logspace(1, 4.2, 20, dtype=int):
start = time.time()
temp = CouplingMap.from_full(i)
stop = time.time()
del tempis what I used to generate the data |
1ucian0
approved these changes
Dec 4, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
In #5183 we switched the internal graph datastructures used for the
CouplingMap to be based on retworkx instead of networkx. That PR was
written against the 0.6.0 retworkx release and for the from_grid()
and from_full() constructors python had to be used since retworkx
was missing functions to generate graphs of those types. However, in the
recent 0.7.x retworkx release 2 new generators directed_grid_graph() [1]
and directed_mesh_graph() [2] were added. This commit switches the
implementation of from_grid() and from_full() to use these generators,
which significantly speeds up (and reduces the memory overhead) of the
constructor methods.
The only constructor which still relies on a Python loop is the
from_full() method when bidirection=False. This is because retworkx
doesn't offer a constructor that will build a graph like that. If in
a future release a generator is added we can remove that for loop too.
Details and comments
[1] https://retworkx.readthedocs.io/en/stable/stubs/retworkx.generators.directed_grid_graph.html
[2] https://retworkx.readthedocs.io/en/stable/stubs/retworkx.generators.directed_mesh_graph.html