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

Implementation of closeness_centrality #593

Merged
merged 11 commits into from
Mar 10, 2023

Conversation

derbuihan
Copy link
Contributor

This PR implements closeness centrality for graphs and digraphs.
It supports boolean option wf_improved with the same names and meanings as their networkx counterparts.

#441

@CLAassistant
Copy link

CLAassistant commented Apr 23, 2022

CLA assistant check
All committers have signed the CLA.

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, thanks for pushing this PR. I have a few inline comments including a suggestion on how to fix the MSRV job failure.

The only other thing is while you're updating this if you could also add a release note using reno so we can document this new feature as part of 0.12.0. The procedure for doing this is documented here: https://github.com/Qiskit/retworkx/blob/main/CONTRIBUTING.md#release-notes

retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/tests/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
src/centrality.rs Outdated Show resolved Hide resolved
src/centrality.rs Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Apr 27, 2022

Pull Request Test Coverage Report for Build 2281936091

  • 57 of 57 (100.0%) changed or added relevant lines in 3 files are covered.
  • 159 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.9%) to 97.192%

Files with Coverage Reduction New Missed Lines %
src/connectivity/mod.rs 11 96.36%
src/iterators.rs 148 83.87%
Totals Coverage Status
Change from base Build 2173032073: -0.9%
Covered Lines: 11216
Relevant Lines: 11540

💛 - Coveralls

@derbuihan
Copy link
Contributor Author

@mtreinish
Thanks for your kind review, I really appreciate it. I applied all your suggestions.

retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/src/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/tests/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/tests/centrality.rs Outdated Show resolved Hide resolved
retworkx-core/tests/centrality.rs Outdated Show resolved Hide resolved
retworkx/__init__.py Outdated Show resolved Hide resolved
src/centrality.rs Outdated Show resolved Hide resolved
src/centrality.rs Outdated Show resolved Hide resolved
tests/digraph/test_centrality.py Outdated Show resolved Hide resolved
tests/digraph/test_centrality.py Outdated Show resolved Hide resolved
tests/digraph/test_centrality.py Outdated Show resolved Hide resolved
tests/digraph/test_centrality.py Outdated Show resolved Hide resolved
tests/graph/test_centrality.py Outdated Show resolved Hide resolved
tests/graph/test_centrality.py Outdated Show resolved Hide resolved
Comment on lines 114 to 116
betweenness = retworkx.graph_closeness_centrality(self.graph)
expected = {0: 0.5, 1: 0.75, 2: 0.75, 4: 0.5}
self.assertEqual(expected, betweenness)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
betweenness = retworkx.graph_closeness_centrality(self.graph)
expected = {0: 0.5, 1: 0.75, 2: 0.75, 4: 0.5}
self.assertEqual(expected, betweenness)
closeness = retworkx.graph_closeness_centrality(self.graph)
expected = {0: 0.5, 1: 0.75, 2: 0.75, 4: 0.5}
self.assertEqual(expected, closeness)

tests/graph/test_centrality.py Outdated Show resolved Hide resolved
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 looks good to me. The code seems fine to me. I only have one concern about the docstrings specifically how they seem to be copied directly from networkx. If we're going to borrow the docstrings from there that's fine but we need to add a comment to the source to document the original authors of the text (everywhere we use it).

where :math:`d(v, u)` is the shortest-path distance between :math:`v` and
:math:`u`, and :math:`n` is the number of nodes that can reach :math:`u`.

Wasserman and Faust propose an improved formula for graphs with more than
Copy link
Member

Choose a reason for hiding this comment

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

Do you have a link to the paper for this? If so it'd be good to include a link to it. (also in the docstrings)

Comment on lines 19 to 22
Wasserman and Faust propose an improved formula for graphs with more than
one connected component. The result is "a ratio of the fraction of actors
in the group who are reachable, to the average distance" from the reachable
actors.
Copy link
Member

Choose a reason for hiding this comment

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

This paragraph looks identical to what's in the NetworkX documentation for this option: https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.centrality.closeness_centrality.html

It might be better to put this in your own words instead of copying exactly what NetworkX has in the documentation or provide a link to the original text as a comment to cite the original source of this text (same with the docstrings).

This merge commit fixes a number of merge conflicts caused by the
project rename from retworkx to rustworkx and other changes since this
was first opened.
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.

This LGTM now, thanks for pushing this. I went ahead and just rebased this on the current state of the main branch and updated all the docstrings to put them in our own words and add a citation to the Wasserman & Faust paper.

@mtreinish mtreinish added the automerge Queue a approved PR for merging label Mar 10, 2023
@coveralls
Copy link

Pull Request Test Coverage Report for Build 4387478694

  • 57 of 57 (100.0%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 97.149%

Files with Coverage Reduction New Missed Lines %
src/shortest_path/all_pairs_dijkstra.rs 1 98.54%
Totals Coverage Status
Change from base Build 4380086067: 0.01%
Covered Lines: 14109
Relevant Lines: 14523

💛 - Coveralls

@mergify mergify bot merged commit 9dd7a8a into Qiskit:main Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Queue a approved PR for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants