Skip to content

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.

- 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!

Choose a reason for hiding this comment

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

@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!

Copy link
Member

@Schefflera-Arboricola Schefflera-Arboricola left a comment

Choose a reason for hiding this comment

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

Thanks @akshitasure12 -- Apologies for the delayed response! Please LMK if you still have the bandwidth to address the following comments. Thanks!

Comment on lines 26 to 30
kwargs = [
param.name
for param in signature.parameters.values()
if param.default is not inspect.Parameter.empty
]

Choose a reason for hiding this comment

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

this is collecting all the default values of all the kwargs-- not the kwargs. Is that what you intended? The get_functions_with_get_chunks function calls this function-- and it assumes that get_all_functions is providing all the functions keyed to their kwargs. Could you please consider updating the docstrings of these functions to make it more clear to review?

We should also consider adding these helper functions to test/utils or utils maybe and then testing these as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was unintentional! I’ll get these changes done asap!

assert math.isclose(c1[i], c2[i], abs_tol=1e-16)
for key in c1.keys():
assert math.isclose(
c1.get(key, 0), c2.get(key, 0), abs_tol=1e-16

Choose a reason for hiding this comment

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

I don't think we should use .get here because the keys should be the same in both c1 and c2 and if they are not-- then an error should be raised instead of using 0. LMKWYT.

assert math.isclose(c1[i], c2[i], abs_tol=1e-16)
for key in c1.keys():
assert math.isclose(
c1.get(key, 0), c2.get(key, 0), abs_tol=1e-16

Choose a reason for hiding this comment

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

same here.

@akshitasure12
Copy link
Contributor Author

Thanks @akshitasure12 -- Apologies for the delayed response! Please LMK if you still have the bandwidth to address the following comments. Thanks!

Sure! I’ll be free in about a week and will get back to it.

Comment on lines 84 to 87
if not math.isclose(c1[key], c2[key], abs_tol=1e-16):
raise ValueError(
f"Values for key '{key}' differ: {c1[key]} != {c2[key]}"
)

Choose a reason for hiding this comment

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

no need for explicitly raising error like this here, assert already handles this

def get_all_functions(package_name="nx_parallel"):
"""Returns a dict keyed by function names to its arguments.
def get_all_functions_kwargs(package_name="nx_parallel"):
"""Returns a dict keyed by function names to its positional-or-keyword arguments.

Choose a reason for hiding this comment

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

why have you explicitly mentioned "positional-or-keyword"? -- it returns all the arguments. also in the following code could you please update the variable names i.e. update kwarg_?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the functions only have positional or keyword arguments, so there is no need to mention that explicitly. I'll make the changes. Thanks!

Copy link
Member

@Schefflera-Arboricola Schefflera-Arboricola left a comment

Choose a reason for hiding this comment

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

Thanks @akshitasure12!
CI failures unrelated.

Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

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

This looks like a good simplification and refactor.
And, of course, it now avoids the problems with getfullargspec.

I approve this PR

@dschult dschult merged commit 22e4c3c into networkx:main May 17, 2025
2 of 11 checks passed
@Schefflera-Arboricola Schefflera-Arboricola added this to the 0.4 milestone May 18, 2025
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

3 participants