Skip to content

Updates documentation to include details about using NetworkX with backends. - #7611

Merged
dschult merged 26 commits into
networkx:mainfrom
rlratzel:v3.4-doc_updates_for_backends
Oct 10, 2024
Merged

dschult merged 26 commits into
networkx:mainfrom
rlratzel:v3.4-doc_updates_for_backends

Conversation

@rlratzel

@rlratzel rlratzel commented Aug 21, 2024 •

Copy link
Copy Markdown
Contributor

As discussed in the NetworkX community dispatching meeting on August 14, 2024, this PR adds documentation on "the wide variety of topics related to using NetworkX with backends".

These updates include:

  • Updates to the detailed backends docs for the latest changes to dispatching for NX 3.4
  • Separate the content for Configs into its own section
  • Add text to the tutorial section to explain the basics for using backends
  • Add a "Backends" section, accessible from the top navbar, that lists various backends known to work with NX 3.4
  • Add text to the Install section to briefly explain backends, how they're installed separately, and where to learn more.

@Schefflera-Arboricola Schefflera-Arboricola added type: Documentation Dispatching Related to dispatching and backend support labels Aug 21, 2024
@eriknw

eriknw commented Oct 4, 2024

Copy link
Copy Markdown
Contributor

Some prose:

NetworkX backends can be used explicitly (requires changing code) or implicitly (requires setting configuration or environment variables). The best way to use a backend depends on the backend, your use case, and whether you want to automatically convert to or from backend graphs. Automatic conversions of graphs is always opt-in.

To explicitly use a backend, use backend=... keyword argument in a dispatchable function. This will convert (and cached by default) input NetworkX graphs to backend graphs and call the backend implementation. Another explicit way to use a backend is to create a backend graph directly--for example, perhaps the backend has its own functions for loading data and creating graphs--and pass that graph to a dispatchable function,
which will then call the backend implementation without converting.

Using backends implicitly requires setting configuration options. Every NetworkX configuration may also be set from an environment variable and are processed at the time networkx is imported.

nx.config.backend_priority.algos (NETWORKX_BACKEND_PRIORITY_ALGOS env var), a list of backends, controls dispatchable functions that don't return graphs such as nx.pagerank. When one of these functions is called with NetworkX graphs as input, the dispatcher iterates over the backends listed in this backend_priority config and will use the first backend that implements this function. The input NetworkX graphs are converted (and cached by default) to backend graphs. Using this configuration can allow you to use the full flexibility of NetworkX graphs and the performance of backend implementations, but possible downsides are that creating NetworkX graphs, converting to backend graphs, and caching backend graphs may all be expensive.

nx.config.backend_priority.generators (NETWORKX_BACKEND_PRIORITY_GENERATORS env var), a list of backends, controls dispatchable functions that return graphs such as nx.from_pandas_edgelist and nx.empty_graph. When one of these functions is called, the first backend listed in this backend_priority config that implements this function will be used and will return a backend graph. When this backend graph is passed to other dispatchable NetworkX functions, it will use the backend implementation if it exists or raise by default unless nx.config.fallback_to_nx is True (default is False). Using this configuration avoids creating NetworkX graphs, which subsequently avoids the need to convert to and cache backend graphs as when using nx.config.backend_priority.algos, but possible downsides are that the backend graph may not behave the same as a NetworkX graph and the backend may not implement all algorithms that you use, which may break your workflow.

nx.config.fallback_to_nx (NETWORKX_FALLBACK_TO_NX env var), a boolean (default False), controls what happens when a backend graph is passed to a dispatchable function that is not implemented by that backend. The default behavior when False is to raise. If True, then the backend graph will be converted (and cached by default) to a NetworkX graph and will run with the default NetworkX implementation. Enabling this configuration can allow workflows to complete if the backend does not implement all algorithms used by the workflow, but a possible downside is that it may require converting the input backend graph to a NetworkX graph, which may be expensive. If a backend graph is duck-type compatible as a NetworkX graph, then it may choose not to convert to a NetworkX graph since it already is one.

nx.config.cache_converted_graphs (NETWORKX_CACHE_CONVERTED_GRAPHS env var), a boolean (default True), controls whether graph conversions are cached to G.__networkx_cache__ or not. Caching can improve performance by avoiding repeated conversions, but it uses more memory.

Backends are encouraged to document how they recommend to be used and whether their graph types are duck-type compatible as NetworkX graphs. If backend graphs are NetworkX-compatible and you want your workflow to automatically "just work" with a backend--performing conversions and caching if necessary--then use all of the above configurations. Automatically converting graphs is opt-in, and configuration gives you the user control.

@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 know you are probably still working on these, but I read through them and had these comments. Feel free to ignore or ask what I meant, etc...

Comment thread doc/tutorial.md Resolved
Comment thread doc/tutorial.md Resolved
Comment thread doc/backends.md Resolved
@rlratzel
rlratzel marked this pull request as ready for review October 8, 2024 06:10
@rlratzel

rlratzel commented Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

Questions:

  • Should we include graphblas-algorithms in the list of backends on the new "Backends" page? It hasn't been updated in quite a while and the docs still use outdated terminology ("plugin").
  • Should we include any other backends on the new "Backends" page?

@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 made a PR to your branch with a proposed rewording of the "How does this work" section -- mostly breaking it up into subsections.

And I have a couple suggestions already entered in github's gui so I'll make that review here. I got hung up twice on the pronoun "it" in the same place so replace the pronoun, and I tried to shorten the sentence about turning on all the config options.

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

dschult commented Oct 9, 2024

Copy link
Copy Markdown
Member

These are good questions for the dispatching group:

Should we include graphblas-algorithms in the list of backends on the new "Backends" page? It hasn't been updated in quite a while and the docs still use outdated terminology ("plugin").
It looks like graphblas-algorithms hasn't received the focus to update it along with the dispatching system. But @eriknw is one of its core devs and he wrote the dispatching system. So I would give them the choice in this case.

Should we include any other backends on the new "Backends" page?
Have any other backends approached us about being added? Are we aware of any others? If not, it's hard to add them.

@dschult

dschult commented Oct 9, 2024

Copy link
Copy Markdown
Member

Here's a big-picture question regarding the docs:
Should Backends have the separate tab on the main NX webpage? The webpage itself is about as long as the entry in the "install" tab about backends. Could we just put the list of known backends into the install page docs? Or into a multiple-page section of the reference docs? To be clear, I am fine with this PR for this release. Nothing here is a blocker. But I'm sad that the tabs on the docs page are enough to require a "more" click to see them all on my laptop display. :)

@rlratzel

rlratzel commented Oct 9, 2024

Copy link
Copy Markdown
Contributor Author

Could we just put the list of known backends into the install page docs? Or into a multiple-page section of the reference docs?

Yeah I see what you mean about the list being short enough to not warrant its own page. One of the big motivations for the dedicated Backends page was discoverability though, and I'd be concerned users wouldn't notice the backends available or when new ones are added if it was inlined in the Install page or another part of the Reference.

I wonder if the Backends page will be more obviously necessary as a dedicated page when:

  • we get more backends participating (like perhaps graphblas when it get updated, nx-pandas, perhaps a rustworkx backend, others?)
  • we use it to summarize more information about the contributions each backend makes so the user can see at-a-glance what they'd like to install. Perhaps a collapsible section for each backend that shows what algos they provide, and perhaps another that shows the speedup of each algo if we can coordinate this with the benchmarking initiative. Maybe also install requirements, license, etc. would be good to include.
  • we add text to the page to invite contributors to submit their backend, at which point there would be instructions on how to get it to run with the NX test suite, how to add it to the benchmark system to get the above mentioned performance metrics included, etc.

I can also see this growing to the point where it's not a list, but maybe a gallery-style grid of tiles where each tile has some of the above mentioned metadata included to make at-a-glance discoverability easier.

Of course, none of this is in place now so we could get away with just inlining the list in the Install page. Perhaps this is also a good discussion topic for the dispatching meeting?

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

I think it makes sense to create a new Backend page to put out backends more out in the world.

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

This looks good to me! Thanks everyone, esp @rlratzel !

@dschult
dschult merged commit 0371b0c into networkx:main Oct 10, 2024
@jarrodmillman jarrodmillman added this to the 3.4 milestone Oct 10, 2024
Comment thread doc/backends.md
Comment on lines +34 to +44
```{list-table}
:header-rows: 1
* - Name
- Description
* - [nx-parallel](https://github.com/networkx/nx-parallel)
- Parallelized implementations of various NetworkX functions using joblib
* - [nx-cugraph](https://rapids.ai/nx-cugraph)
- GPU acceleration using RAPIDS cuGraph and NVIDIA GPUs
* - [nx-arangodb](https://nx-arangodb.readthedocs.io/en/latest/)
- Seamlessly adds ArangoDB as a persistence layer to NetworkX graphs
```

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.

maybe we can do something like this(https://docs.pytest.org/en/stable/reference/plugin_list.html#) here, like pytest does it. The update script is also there on this same webpage. Like get all the PyPI projects whose names begin with "nx-". but we don't have lots of plugins(backends) right now, so idk if it'd be worth the effort. But just putting it here for future reference.

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: Documentation

Development

Successfully merging this pull request may close these issues.

6 participants