Skip to content

Conversation

@eriknw
Copy link
Contributor

@eriknw eriknw commented Jul 18, 2024

This adds informative logging messages for can_run and should_run to better understand behaviors of dispatching.

@eriknw eriknw changed the title Log "can run" and "should run" in dispatch machinery Log "can/should run" and caching in dispatch machinery Jul 18, 2024
@eriknw
Copy link
Contributor Author

eriknw commented Jul 18, 2024

Also added logging for using the cache. This continues logging that was first added in #7300. CC @rlratzel

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 @eriknw :)

Comment on lines 959 to 961
_logger.debug(
"Backend '%s' does not implement `%s'", backend_name, self.name
)

Choose a reason for hiding this comment

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

Do we want to log it and also raise an exception here? isn't the error msg sufficient?

>>> nx.degree_centrality(G, backend="parallel")
Backend 'parallel' does not implement `degree_centrality'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/networkx/networkx/utils/decorators.py", line 789, in func
    return argmap._lazy_compile(__wrapper)(*args, **kwargs)
  File "<class 'networkx.utils.decorators.argmap'> compilation 29", line 3, in argmap_degree_centrality_26
  File "/workspaces/networkx/networkx/utils/backends.py", line 911, in __call__
    return self._convert_and_call(
  File "/workspaces/networkx/networkx/utils/backends.py", line 1371, in _convert_and_call
    raise RuntimeError(msg)
RuntimeError: 'degree_centrality' not implemented by parallel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that duplication is kind of unfortunate. Nice attention to detail.

I just pushed a change that doesn't write that log message when that exception will be raised. The log message may have info that doesn't show up in the warnings--specifically, the string returned by can_run--so maybe a little duplication is okay if the log message may be more helpful.

@Schefflera-Arboricola Schefflera-Arboricola added the Dispatching Related to dispatching and backend support label Jul 19, 2024
eriknw and others added 4 commits July 19, 2024 05:47
Co-authored-by: Aditi Juneja <91629733+Schefflera-Arboricola@users.noreply.github.com>
Co-authored-by: Aditi Juneja <91629733+Schefflera-Arboricola@users.noreply.github.com>
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.

Thank you @eriknw and @rlratzel !

Copy link
Member

@MridulS MridulS left a comment

Choose a reason for hiding this comment

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

Not a blocker for this PR but we really need to find good ways to test the backends.py file.

@MridulS MridulS merged commit 623b2c8 into networkx:main Aug 25, 2024
@MridulS MridulS added this to the 3.4 milestone Aug 25, 2024
rossbar pushed a commit to Peiffap/networkx that referenced this pull request Sep 6, 2024
* Log "can run" and "should run" in dispatch machinery

* Also add logging for using cache

* Make code more concise by combining branches for `should_run`

Co-authored-by: Aditi Juneja <91629733+Schefflera-Arboricola@users.noreply.github.com>

* Make code more concise by combining branches for `can_run`

Co-authored-by: Aditi Juneja <91629733+Schefflera-Arboricola@users.noreply.github.com>

* Don't log if info also in error message

* Log when falling back to networkx too

---------

Co-authored-by: Aditi Juneja <91629733+Schefflera-Arboricola@users.noreply.github.com>
Co-authored-by: Mridul Seth <seth.mridul@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dispatching Related to dispatching and backend support type: Enhancements

Development

Successfully merging this pull request may close these issues.

4 participants