summaryrefslogtreecommitdiff
path: root/networkx/classes/backends.py
Commit message (Collapse)AuthorAgeFilesLines
* Handle weights as `distance=` in testing dispatch (#6671)Erik Welch2023-05-131-0/+3
| | | | | | | | * Handle weights as `distance=` in testing dispatch * fix `test_intersection` This change was suggested here: https://github.com/python-graphblas/graphblas-algorithms/pull/62#issuecomment-1531810715
* Allow multiple graphs for `@nx._dispatch` (#6628)Jim Kitchen2023-04-251-38/+74
| | | | | | | | | | | | | * Allow multiple graphs for nx._dispatch A new `graphs` keyword is added. For the case of two graphs named `G` and `H` as the first to arguments in `foo`, the new spelling is @nx._dispatch(graphs="G,H") def foo(G, H, other_arg, **kwargs): ... * Use better default "G" for graphs kwarg * fix
* Test dispatching via nx-loopback backend (#6536)Jim Kitchen2023-03-281-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add tests for nx._dispatch decorator The dispatch functionality is used to delegate graph computations to a different backend. Because those backends are not part of NetworkX, testing the dispatching feature was not originally added, relying instead on the other backends (e.g. graphblas-algorithms) to verify the dispatch functionality is working. This change creates a "loopback" backend where NetworkX dispatches to itself for the sole purpose of exercising the dispatching machinery. In one incarnation, various tests are augmented to use the LoopbackGraph family and force loopback dispatching to occur as normal usage would. A second incarnation forces *all* tests to run in dispatch mode but use of a different _dispatch decorator. This mode is triggered for all of pytest, so it must be tested by the CI system specifically. * Update CI to hopefully run dispatching auto tests * Formatting * More formatting fixes * Better comments explaining dispatching tests
* tweak `test_override_dispatch` to allow G keyword (#6499)Erik Welch2023-03-131-1/+7
| | | | | | | | | | | This is a simple follow-up to #6471, and, as in that PR, this fix is short term. We would like to find a more elegant, robust solution (probably after nx 3.1). I sometimes forget there are two versions of `_dispatch`, and this PR fixes the one that gets used when `NETWORKX_GRAPH_CONVERT` environment variable is set. NetworkX does not yet test `test_override_dispatch`, so it's not easy to add a test, but it gets used by external backends such as `graphblas_algorithms`. Ideally, we should test this in NetworkX, which will require calling subprocess in a test with an environment variable set.
* Allow first argument to be passed as kwarg in dispatcher (#6471)Dan Schult2023-03-111-1/+7
| | | | | * tweak _dispatch to allow func(G=G) pattern in signature Co-authored-by: Erik Welch <erik.n.welch@gmail.com>
* DOC: Minor formatting fixups to get rid of doc build warnings. (#6363)Ross Barnowski2023-01-131-21/+18
| | | Minor formatting fixups to get rid of doc build warnings.
* fix warnings for make doctest (#6323)Dan Schult2023-01-041-1/+3
|
* plugin based backend infrastructure to use multiple computation backends (#6000)Mridul Seth2022-11-081-0/+223
* Wrappers classes to dispatch to a backend * Rework the backend dispatching - Use __networkx_plugin__=name to find graph-like objects instead of subclassing - Add PluginInfo to smooth over differences in importlib.metadata across python versions - Add dispatch behavior override via environment variable to aid in testing plugins * Dispatch more algorithms and improve auto-test capabilities * Allow dispatcher decorator without a name - Name is taken from the decorated function - Raise error if backend doesn't implement a decorated function which is called - Check for duplicate names for dispatching algorithms * Make sphinx pick up backend docs * make black happy * Rename decorator to _dispatch as it's experimental * A few more dispatched functions * Make convert to and from methods for auto-testing - Rename `convert` to `convert_from_nx` - Add `convert_to_nx` function These will allow backends to return native objects when dispatching, but provide a mechanism to convert the result to the type expected by NetworkX tests for the auto-test plugin mechanism. * More dispatching * Include name with `convert_**_nx` methods * Remove known plugin names This check is not needed, as any plugin can register itself in the entry points section. The dispatching and auto-testing explicitly specify the plugin to use, so there is no need to hardcode the options. These were originally included for security, but any malicious actor would simply use one of the valid names, so having a hardcoded list does not actually provide any meaningful security. * Add `dispatchname` to dispatchable functions Co-authored-by: Jim Kitchen <jim22k@gmail.com> Co-authored-by: Erik Welch <erik.n.welch@gmail.com>