Skip to content

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

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
akshitasure12 opened this issue Mar 22, 2025 · 4 comments · May be fixed by #104
Open
Labels
type: Bug fix Something isn't working

Comments

@akshitasure12
Copy link
Contributor

akshitasure12 commented Mar 22, 2025

Hi @Schefflera-Arboricola,
I added a new algorithm and wanted to try it out. While experimenting, I added two print statements to the get_all_functions() function in test_get_chunks.py to check the function's behavior. However, I encountered the following :

platform darwin -- Python 3.12.4, pytest-7.4.4, pluggy-1.0.0
rootdir: /Users/a91986/Desktop/nx-parallel
plugins: anyio-4.2.0
collected 1 item                                                                                                                                                                                           

nx_parallel/tests/test_get_chunks.py all_pairs_all_shortest_paths
{'args': [], 'kwargs': 'args'}
all_pairs_bellman_ford_path
{'args': [], 'kwargs': 'args'}
all_pairs_bellman_ford_path_length
{'args': [], 'kwargs': 'args'}
all_pairs_dijkstra
{'args': [], 'kwargs': 'args'}
all_pairs_dijkstra_path
{'args': [], 'kwargs': 'args'}
all_pairs_dijkstra_path_length
{'args': [], 'kwargs': 'args'}
all_pairs_node_connectivity
{'args': [], 'kwargs': 'args'}
all_pairs_shortest_path
{'args': [], 'kwargs': 'args'}
all_pairs_shortest_path_length
{'args': [], 'kwargs': 'args'}
approximate_all_pairs_node_connectivity
{'args': [], 'kwargs': 'args'}
betweenness_centrality
{'args': [], 'kwargs': 'args'}
chunks
{'args': ['iterable', 'n_chunks'], 'kwargs': None}
closeness_vitality
{'args': [], 'kwargs': 'args'}
create_iterables
{'args': ['G', 'iterator', 'n_cores', 'list_of_iterator'], 'kwargs': None}
edge_betweenness_centrality
{'args': [], 'kwargs': 'args'}
get_n_jobs
{'args': ['n_jobs'], 'kwargs': None}
is_reachable
{'args': [], 'kwargs': 'args'}
johnson
{'args': [], 'kwargs': 'args'}
local_efficiency
{'args': [], 'kwargs': 'args'}
node_redundancy
{'args': [], 'kwargs': 'args'}
number_of_isolates
{'args': [], 'kwargs': 'args'}
square_clustering
{'args': [], 'kwargs': 'args'}
tournament_is_strongly_connected
{'args': [], 'kwargs': 'args'}
.

Steps to Reproduce :

  1. Modified get_all_functions() by adding two print statements like this:
def get_all_functions(package_name="nx_parallel"):
    """Returns a dict keyed by function names to its arguments.

    This function constructs a dictionary keyed by the function
    names in the package `package_name` to dictionaries containing
    the function's keyword arguments and positional arguments.
    """
    package = importlib.import_module(package_name)
    functions = {}

    for name, obj in inspect.getmembers(package, inspect.isfunction):
        if not name.startswith("_"):
            print(name)
            args, kwargs = inspect.getfullargspec(obj)[:2]
            functions[name] = {"args": args, "kwargs": kwargs}
            print(functions[name])
    return functions
  1. Ran the following command:
pytest -s nx_parallel/tests/test_get_chunks.py
  1. Encountered the above error.

Expected Behavior:

I expected the function to print the name of the function and its arguments without any error.
Please let me know if I’m missing something or if there’s anything else I should check!

@Schefflera-Arboricola
Copy link
Member

Thank you very much @akshitasure12 for reporting this! The get_all_functions is indeed not working as intended.

I'm not sure why it's not picking up args and kwargs for functions specifically in the algorithms sub-module (it's working fine with the functions in utils)... maybe because we recently added an assign_algorithms decorator to the BackendInterface class in PR#80? or because we wrapped all the algorithms in the _configure_if_nx_active decorator? Before these got added, I definitely remember test_get_chunks used to work (bcoz it used to fail sometimes 😅).

Would you like to investigate further?

Thank you :)

@Schefflera-Arboricola Schefflera-Arboricola added the type: Bug fix Something isn't working label Mar 22, 2025
@Schefflera-Arboricola Schefflera-Arboricola changed the title Error while using get_all_functions() after adding print statements BUG: get_all_functions() is not returning args and kwargs of the functions in algorithms Mar 23, 2025
@Schefflera-Arboricola
Copy link
Member

Could you please update the issue description by copy-pasting the output from the terminal instead of the screenshot as it might not be readable to everyone(for e.g. someone might be using some kind of a reading software(text-to-audio) that might not pick up the text in the image)? And instead of just writing the two print statements in the "Added two print statements to get_all_functions() like this:" section, could you copy-paste the entire function, so that it's easier for everyone to understand where exactly in the function did you put those print statements and have more context on what functions and name mean?

Thanks!

@akshitasure12
Copy link
Contributor Author

Sure, @Schefflera-Arboricola! I'd love to look into this further. I'll also add the suggested changes to the issue description. Thank you!

@akshitasure12
Copy link
Contributor Author

Hi @Schefflera-Arboricola!
I've been working through different solutions for the past few days, and I think I've finally identified where the problem might be. I tried bypassing both the decorators and experimented with them, but get_all_functions still didn’t return the expected args and kwargs.

While investigating whether the issue could be related to inspect.getfullargspec() or other inspect methods, I came across an interesting discussion in joblib: Use inspect.signature() instead of inspect.getfullargspec().

I believe this could lead us to the expected results.
Looking forward to hearing your thoughts on this!

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
2 participants