Skip to content

Ensure we always raise for unknown backend in backend= - #7494

Merged
Schefflera-Arboricola merged 19 commits into
networkx:mainfrom
eriknw:always_raise_unknown_backend
Jul 25, 2024
Merged

Schefflera-Arboricola merged 19 commits into
networkx:mainfrom
eriknw:always_raise_unknown_backend

Conversation

@eriknw

@eriknw eriknw commented Jun 11, 2024

Copy link
Copy Markdown
Contributor

Previously, using backend="foo" would silently work if there were no backends installed. We should catch e.g. typos sooner.

Note that I originally had this bugfix in #7485, but I think it's cleaner to have a separate PR with a test.

eriknw added 5 commits June 4, 2024 14:20
This is like doing `backend=...` when calling a dispatchable function.
Previously, using `backend="foo"` would silently work if there
were no backends installed. We should catch e.g. typos sooner.
@eriknw eriknw added type: Bug fix Dispatching Related to dispatching and backend support labels Jun 11, 2024
@eriknw

eriknw commented Jun 11, 2024

Copy link
Copy Markdown
Contributor Author

I updated conftest.py so that the nx-loopback backend is only present when testing a backend, so normal testing should now go through the fast path. This change required nx-loopback to be renamed to nx_loopback, which is also done in #7297, so this PR will now look a little larger than it actually is.

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

This looks good, I just have one request related to consistency.

Also, related to this PR, is a question that I want to make sure I know the answer to: what's the behavior (current and desired) when a user adds an unknown backend to the backend_priority list?

- name: Test Dispatching
run: |
NETWORKX_TEST_BACKEND=nx-loopback pytest --doctest-modules --durations=10 --pyargs networkx
NETWORKX_TEST_BACKEND=nx_loopback pytest --doctest-modules --durations=10 --pyargs networkx

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.

Our convention when specifying backends to networkx is to drop the nx- prefix used by the package name, so in this case it would be loopback (or at least that's how I've been explaining it to other users). This is also how the nx-cugraph backend is specified (as just cugraph) in the NETWORKX_BACKEND_PRIORITY env var and the backend= kwarg. Can we be consistent and change this to loopback?

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.

I've asked @dschult this before too. Let's keep it nx_loopback for now and at least until more of the dispatching PRs are merged, since this would make my life easier. I have WIP branches in flight that combine many of the PRs, so I would like to avoid unnecessary churn.

If we ever make loopback a "proper" backend that demonstrates how to be a backend--and one that tests networkx--then we should revisit the name.

Comment thread networkx/utils/configs.py Resolved
Comment thread networkx/utils/configs.py Resolved
eriknw and others added 2 commits July 3, 2024 14:02
Co-authored-by: Rick Ratzel <[email protected]>
Co-authored-by: Rick Ratzel <[email protected]>

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

I've left a few comments/reviews below. Pls LMK what you think.

Thank you :)

Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/tests/test_backends.py Resolved
Comment thread networkx/utils/tests/test_backends.py Resolved
Comment thread networkx/utils/configs.py Outdated
This is a global configuration. Use with caution when using from multiple threads.
"""

backend: str | None

@Schefflera-Arboricola Schefflera-Arboricola Jul 21, 2024 •

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.

This backend config is not needed for this PR, right?
I think this is a part of the PR that you made which adds backend="networkx".
Or am I missing something and this is needed here?

if we had used backend_priority = ["nx_loopback"], then I think it would have been sufficient for this PR.

Also, I think backends and backend can cause confusions, and a user can confuse backends with backend_priority. So, I think it might be nice to revisit my this comment #7485 (comment) in PR#7485 which proposed to combine the behaviour of backend and backend_priority. And I know you addressed it by saying that this would restrict how the both(backend and backend_priority) get developed in the future(but, I'm not completely sure how backend can grow further...). So, I am just trying to convey the point that we should name and define the functionalities of these parameters a little better.

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.

Good catch! I'll remove this.

This branch was originally based off of #7485, so this must have accidentally slipped through. I agree with not having nx.config.backend in this PR, because it needs more discussion. Perhaps we can discuss options at an nx dispatching meeting soon.

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.

Okay, I removed nx.config.backend from this PR 👍

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

LGTM, and seems like useful and expected functionality.

@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 , @rlratzel and @mjschwenne :)

@Schefflera-Arboricola
Schefflera-Arboricola merged commit be6c35e into networkx:main Jul 25, 2024
@dschult dschult added this to the 3.4 milestone Aug 28, 2024
rossbar pushed a commit to Peiffap/networkx that referenced this pull request Sep 6, 2024
* Add `nx.config.backend` option

This is like doing `backend=...` when calling a dispatchable function.

* Add note to discuss the difference between `backend` and `backend_priority`

* Ensure we always raise for unknown backend in `backend=`

Previously, using `backend="foo"` would silently work if there
were no backends installed. We should catch e.g. typos sooner.

* Clean up (moved to separate PR)

* Fix test, and rename `nx-loopback` to `nx_loopback`

* s/nx-loopback/nx_loopback/

* oops fix bad merge

* s/soft/best effort/

Co-authored-by: Rick Ratzel <[email protected]>

* s/hard/strict/

Co-authored-by: Rick Ratzel <[email protected]>

* "...backend is not installed"

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

* "...backend is not installed" (testing)

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

* Get rid of `nx.config.backend` (doesn't belong in this PR)

* More "backend is not installed" updates

---------

Co-authored-by: Rick Ratzel <[email protected]>
Co-authored-by: Aditi Juneja <[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: Bug fix

Development

Successfully merging this pull request may close these issues.

5 participants