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

Switch is_directed_acyclic_graph to use toposort internally #217

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

mtreinish
Copy link
Member

Previously the retworkx.is_directed_acyclic_graph() function was
internally using the petgraph::algo::is_cyclic_directed function to look
for a potential cycle in the graph. However, as noted in the docs[1]
this function is recursive and as reported in Qiskit/qiskit#5502
with very large graphs this is causing segfaults. To avoid this
potential issue this commit changes the internal implementation to use
petgraph::algo::toposort which isn't recursive and should be more
reliable.

Fixes: Qiskit/qiskit#5502

[1] https://docs.rs/petgraph/0.5.1/petgraph/algo/fn.is_cyclic_directed.html

@coveralls
Copy link

coveralls commented Dec 10, 2020

Pull Request Test Coverage Report for Build 415935664

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 94.851%

Totals Coverage Status
Change from base Build 415918432: 0.002%
Covered Lines: 3095
Relevant Lines: 3263

💛 - Coveralls

@mtreinish
Copy link
Member Author

I ran some benchmarks on this locally, and using petgraph::algo::toposort ends up being roughly 30% slower for the cases they both worked, but does not segfault for large graphs. While using the petgraph::algo::is_cyclic_directed is segfaulting at >=100000 nodes in a graph. So it's a necessary performance hit and one most people probably won't see because because for a 1000 node graph it still only takes 21μs.

Previously the retworkx.is_directed_acyclic_graph() function was
internally using the petgraph::algo::is_cyclic_directed function to look
for a potential cycle in the graph. However, as noted in the docs[1]
this function is recursive and as reported in Qiskit/qiskit#5502
with very large graphs this is causing segfaults. To avoid this
potential issue this commit changes the internal implementation to use
petgraph::algo::toposort which isn't recursive and should be more
reliable.

Fixes: Qiskit/qiskit#5502

[1] https://docs.rs/petgraph/0.5.1/petgraph/algo/fn.is_cyclic_directed.html
@mtreinish mtreinish merged commit d735c76 into Qiskit:master Dec 11, 2020
@mtreinish mtreinish deleted the fix-segfault branch December 11, 2020 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transpilation segmentation fault with large circuit
3 participants