Skip to content

Refactor get_all_functions to use inspect.signature instead of inspect.getfullargspe #104

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akshitasure12
Copy link
Contributor

This PR addresses issue #94

Changes made :

  1. Replaced inspect.getfullargspec() with inspect.signature() for reporting the signature of the original function and not that of wrapped.

  2. Updated the assertion logic in the test_get_chunks for chk_dict_vals to iterate over graph edges instead of nodes since chk_dict_vals consists of functions that deals with edges between the nodes and not the nodes themselves.

Comment on lines 25 to 39
signature = inspect.signature(obj)
args = [
param.name
for param in signature.parameters.values()
if param.kind
in (
inspect.Parameter.POSITIONAL_ONLY,
inspect.Parameter.POSITIONAL_OR_KEYWORD,
)
]
kwargs = [
param.name
for param in signature.parameters.values()
if param.kind == inspect.Parameter.KEYWORD_ONLY
]

Choose a reason for hiding this comment

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

I checked the tests are passing(using pytest nx_parallel). The CI test failure is unrelated!

Maybe we can simplify this code by only returning kwargs instead of both args and kwargs as get_chunks is always a kwarg. Does that sound like a good idea to you?

Comment on lines 93 to 96
for edge in G.edges:
assert math.isclose(
c1.get(edge, 0), c2.get(edge, 0), abs_tol=1e-16
)
Copy link
Member

@Schefflera-Arboricola Schefflera-Arboricola Apr 5, 2025

Choose a reason for hiding this comment

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

Good catch! But this will now work with edge_betweenness_centrality and not betweenness_centrality because for the later the keys are nodes not edges. But, this seems like it is working because when you apply get on edges it always returns 0 for both c1 and c2. But, that shouldn't happen. So maybe we should use c1.keys instead of G.nodes(or G.edges). LMKWYT.

@@ -121,11 +121,12 @@ The default chunking in nx-parallel is done by slicing the list of nodes (or edg
- The algorithm that you are considering to add to nx-parallel should be in the main networkx repository and it should have the `_dispatchable` decorator. If not, you can consider adding a sequential implementation in networkx first.
- check-list for adding a new function:
- [ ] Add the parallel implementation(make sure API doesn't break), the file structure should be the same as that in networkx.
- [ ] add the function to the `BackendInterface` class in [interface.py](./nx_parallel/interface.py) (take care of the `name` parameter in `_dispatchable` (ref. [docs](https://networkx.org/documentation/latest/reference/backends.html)))
- [ ] Include the `get_chunks` additional parameter. Currently, all algorithms in nx-parallel offer the user to pass their own custom chunks. Unless it is impossible to chunk, please do include this additional parameter.

Choose a reason for hiding this comment

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

Could you consider rebasing this branch -- so that these changes don't appear in the diff? Thanks!

@akshitasure12
Copy link
Contributor Author

I agree with you @Schefflera-Arboricola! I've made the changes you suggested.
Let me know if anything else needs to be addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Bug fix Something isn't working
Development

Successfully merging this pull request may close these issues.

BUG: get_all_functions() is not returning args and kwargs of the functions in algorithms
2 participants