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

Add chain_decomposition function. #444

Merged
merged 14 commits into from
Oct 15, 2021
Merged

Conversation

georgios-ts
Copy link
Collaborator

This commit adds a new function that finds a
chain decomposition of an undirected PyGraph .
It's defined in https://doi.org/10.1016/j.ipl.2013.01.016
and can be used to compute all bridges and cut
vertices of the input graph.

One current limitation is that it's a recursive implementation
since it's based on the petgraph::depth_first_search.

This commit adds a new function that finds
a chain decomposition of an undirected .
It's defined in https://doi.org/10.1016/j.ipl.2013.01.016
and can be used to compute all bridges and cut
vertices of the input graph.

One current limitation is that it's a recursive implementation
since it's based on the .
@coveralls
Copy link

coveralls commented Sep 10, 2021

Pull Request Test Coverage Report for Build 1346792751

  • 140 of 140 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 98.417%

Totals Coverage Status
Change from base Build 1346791951: 0.02%
Covered Lines: 10504
Relevant Lines: 10673

💛 - Coveralls

georgios-ts added a commit to georgios-ts/retworkx that referenced this pull request Sep 27, 2021
Widely used graph libraries like Boost Graph Library and graph-tool
provide the ability to insert callback functions at specified event
points for many common graph search algorithms. petgraph has a similar
concept in `petgraph::visit::depth_first_search` function. This commit
implements an iterative version of `depth_first_search`, that will be
used in a follow-up in the pending PRs Qiskit#444, Qiskit#445. At the same time it
exposes this new functionality in Python by letting users subclassing
`retworkx.visit.DFSVisitor` and provide their own implementation for
the appropriate callback functions.

The benefit is less memory consumption since we avoid storing the results
but rather let the user take the desired action at specified points. For
example, if a user wants to process the nodes in dfs-order, we don't need
to create a new list with all the graph nodes in dfs-order but rather the user
can process a node on the fly. We can (probably) leverage this approach
in other algorithms as an alternative for our inability to provide "real" python
iterators.
@georgios-ts georgios-ts mentioned this pull request Sep 27, 2021
@mtreinish mtreinish added this to the 0.11.0 milestone Oct 2, 2021
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Overall this LGTM. I'm not familiar with this algorithm I've got to read the paper before I can have any comments on the correctness there. But going through the code it looks good. I just had one inline comment on how we can potentially improve the final output collection

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Ok, I've read the paper (it's quite the simple algorithm) the code looks good on that point. I left a few inline comments mostly about docs and one inline question. Otherwise I think this is good to go.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, sorry for the delay in the review and thanks for pushing this up and the quick updates

@mtreinish mtreinish merged commit 7c54e84 into Qiskit:main Oct 15, 2021
mtreinish pushed a commit that referenced this pull request Jan 10, 2022
* Add dfs-search

Widely used graph libraries like Boost Graph Library and graph-tool
provide the ability to insert callback functions at specified event
points for many common graph search algorithms. petgraph has a similar
concept in `petgraph::visit::depth_first_search` function. This commit
implements an iterative version of `depth_first_search`, that will be
used in a follow-up in the pending PRs #444, #445. At the same time it
exposes this new functionality in Python by letting users subclassing
`retworkx.visit.DFSVisitor` and provide their own implementation for
the appropriate callback functions.

The benefit is less memory consumption since we avoid storing the results
but rather let the user take the desired action at specified points. For
example, if a user wants to process the nodes in dfs-order, we don't need
to create a new list with all the graph nodes in dfs-order but rather the user
can process a node on the fly. We can (probably) leverage this approach
in other algorithms as an alternative for our inability to provide "real" python
iterators.

* break or prune the search tree with custom exceptions

* tests

* move `depth_first_search` to retworkx-core + create a new traversal module together with `dfs_edges` function

* add option to pass a vector of starting nodes + in dfs events report the weight of an edge

* lint

* fix docs

* this is the last fix

* define custom exceptions `StopSearch`, `PruneSearch` in python and import them in rust so we can simplify a bit the namespaces

* minor doc fixes

* ignore flake warning

* run black

* deduplicate macro and mention petgraph DfsEvent struct
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.

3 participants