Skip to content

Avoid repeated cache conversion failures for backends - #7768

Merged
dschult merged 8 commits into
networkx:mainfrom
eriknw:failed_to_convert
Apr 14, 2025
Merged

dschult merged 8 commits into
networkx:mainfrom
eriknw:failed_to_convert

Conversation

@eriknw

@eriknw eriknw commented Dec 11, 2024

Copy link
Copy Markdown
Contributor

When playing around with a workflow that uses NetworkX, I saw repeated failures when trying to convert to a backend. This doesn't seem ideal.

This PR saves a value to the cache (if present) to indicate that a conversion failed, which then allows us to avoid attempting this exact conversion in the future.

CC @rlratzel

@eriknw eriknw added type: Enhancements Dispatching Related to dispatching and backend support labels Dec 11, 2024
@eriknw eriknw added this to the 3.5 milestone Mar 7, 2025
@dschult dschult changed the title Avoid repeated cache conversion failures Avoid repeated cache conversion failures for backends Apr 1, 2025

@dschult dschult 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.

I've taken a pass at this PR. Seems like a good goal. I have some questions below.

Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved

@dschult dschult 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.

I approve this PR. I've got a suggestion about a comment -- but its not a blocker. This is ready to go!

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm approving as this strikes me as more explicit, though I can't claim to have a complete mental model of the caching system. Thanks @eriknw and @dschult !

I will hold off on the green button in case @eriknw wants to take another final pass, otherwise anyone should feel free to merge!

@eriknw

eriknw commented Apr 10, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @dschult and @rossbar for the reviews! I went ahead and implemented the "possible future work" that Dan and I were discussing the comments above. The change is actually relatively minor, although it did change an indentation level so it looks larger than it is.

I tested this locally, and things look great. I'll try to follow up and add a test using the nx_loopback backend, which will require monkey-patching conversion functions to intentionally fail to convert, which is kinda funky, but tests are nice. Feel free to merge if y'all are comfortable, and I'll plan to add a test before 3.5 release.

@dschult dschult 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.

I wanted to take a look at this new change -- it is getting into the parts of the logic that I find tricky. I understand the new parts and they look correct... and the logic in the older parts looks the same. So I'm going to merge this. And I will eventually work to come back and understand this all better. :)

Thanks @eriknw! (and @rossbar for review)

@dschult
dschult merged commit 5e7843b into networkx:main Apr 14, 2025
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.

3 participants