Skip to content

Log "can/should run" and caching in dispatch machinery - #7568

Merged
MridulS merged 8 commits into
networkx:mainfrom
eriknw:log_can_run
Aug 25, 2024
Merged

MridulS merged 8 commits into
networkx:mainfrom
eriknw:log_can_run

Conversation

@eriknw

@eriknw eriknw commented Jul 18, 2024

Copy link
Copy Markdown
Contributor

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

eriknw commented Jul 18, 2024

Copy link
Copy Markdown
Contributor Author

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

@Schefflera-Arboricola Schefflera-Arboricola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @eriknw :)

Comment thread networkx/utils/backends.py Outdated
Comment on lines +959 to +961
_logger.debug(
"Backend '%s' does not implement `%s'", backend_name, self.name
)

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
@Schefflera-Arboricola Schefflera-Arboricola added the Dispatching Related to dispatching and backend support label Jul 19, 2024

@Schefflera-Arboricola Schefflera-Arboricola left a comment

Copy link
Copy Markdown
Member

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 !

@MridulS MridulS left a comment

Copy link
Copy Markdown
Member

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 <[email protected]>

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

Co-authored-by: Aditi Juneja <[email protected]>

* Don't log if info also in error message

* Log when falling back to networkx too

---------

Co-authored-by: Aditi Juneja <[email protected]>
Co-authored-by: Mridul Seth <[email protected]>
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