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 bfs-search #469

Merged
merged 12 commits into from
Nov 17, 2021
Merged

Add bfs-search #469

merged 12 commits into from
Nov 17, 2021

Conversation

georgios-ts
Copy link
Collaborator

This commit implements a breadth_first_search that provides
the ability to insert callback functions at specified event points.
Python users should subclass retworkx.visit.BFSVisitor and overwrite
the appropriate callback functions.

Similar to #456

This commit implements a `breadth_first_search` that provides
the ability to insert callback functions at specified event points.
Python users should subclass `retworkx.visit.BFSVisitor` and overwrite
the appropriate callback functions.

Similar to Qiskit#456
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 looking forward to getting this and the dfs in retworkx. I just have a few questions and suggestions inline.

Also, sorry this has taken me so long to look at, I've been heads down on some qiskit-terra functionality and haven't had much time for retworkx reviews.

retworkx-core/src/traversal/bfs_visit.rs Outdated Show resolved Hide resolved
retworkx-core/src/traversal/bfs_visit.rs Show resolved Hide resolved
retworkx/__init__.py Show resolved Hide resolved
retworkx/__init__.py Outdated Show resolved Hide resolved
retworkx/__init__.py Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/traversal/bfs_visit.rs Show resolved Hide resolved
georgios-ts and others added 5 commits November 15, 2021 18:02
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@coveralls
Copy link

coveralls commented Nov 15, 2021

Pull Request Test Coverage Report for Build 1472802387

  • 139 of 141 (98.58%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.004%) to 98.413%

Changes Missing Coverage Covered Lines Changed/Added Lines %
retworkx-core/src/traversal/bfs_visit.rs 73 75 97.33%
Totals Coverage Status
Change from base Build 1436778676: -0.004%
Covered Lines: 10477
Relevant Lines: 10646

💛 - Coveralls

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.

Thanks for the fast updates, I think this is basically ready now. Before approving I just have one inline question/comment before I'm ready to approve.

Also I was looking at coverage and I noticed a bunch of continue lines don't have coverage, for example: https://coveralls.io/builds/44296139/source?filename=retworkx-core%2Fsrc%2Ftraversal%2Fbfs_visit.rs#L247 is that an issue with the coverage collection or are we missing a path in the tests so that's not getting triggered.

retworkx-core/src/traversal/bfs_visit.rs Show resolved Hide resolved
@georgios-ts
Copy link
Collaborator Author

Also I was looking at coverage and I noticed a bunch of continue lines don't have coverage, for example: https://coveralls.io/builds/44296139/source?filename=retworkx-core%2Fsrc%2Ftraversal%2Fbfs_visit.rs#L247 is that an issue with the coverage collection or are we missing a path in the tests so that's not getting triggered.

Yeah, we miss some test paths, let me add some extra tests to cover these lines.

@georgios-ts
Copy link
Collaborator Author

@mtreinish
Actually thinking about this a bit more, to cover these lines we would need to raise PruneSearch in events where this would not really have any meaningful outcome (i.e the rest of the search will not be affected). So, I'm wondering if it's best to keep the continue statement and just add some dummy tests that will not really assert anything but will satisfy the coverage report or if we should replace continue with a panic as in Finish event.

@mtreinish
Copy link
Member

I think having a test case that just runs like normal when PruneSearch is raised in those edge cases make sense to me. We just make it explicit the test is expected to work fine and we're just testing pathological edge cases. I don't think we need to panic there too.

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 thanks for updating this. The dispatch function is just missing the example from it's docstring after that's added I think this is ready to merge.

Comment on lines +1774 to +1775
In the following example we keep track of the tree edges:

Copy link
Member

Choose a reason for hiding this comment

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

The example here is missing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, good catch! Added in e6123aa.

@mtreinish mtreinish merged commit a9c775e into Qiskit:main Nov 17, 2021
e-eight pushed a commit to e-eight/retworkx that referenced this pull request Dec 5, 2021
* Add bfs-search
This commit implements a `breadth_first_search` that provides
the ability to insert callback functions at specified event points.
Python users should subclass `retworkx.visit.BFSVisitor` and overwrite
the appropriate callback functions.

Similar to Qiskit#456

* update docs from code review

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* docs

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* docs + a comment in the code

* pseudo-code is not a doc test

* fix typo in docs

* do not raise if StopSearch exception

* more tests

* black

* add missing example from docs

* black again

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@mtreinish mtreinish mentioned this pull request Jan 4, 2022
@IvanIsCoding IvanIsCoding mentioned this pull request Jan 11, 2022
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