Skip to content

76 native 20 fixes - #176

Open
eriknw wants to merge 1 commit into
python-graphblas:75-should-run-basefrom
eriknw:76-native-20-fixes
Open

eriknw wants to merge 1 commit into
python-graphblas:75-should-run-basefrom
eriknw:76-native-20-fixes

Conversation

@eriknw

@eriknw eriknw commented Dec 4, 2026

Copy link
Copy Markdown
Member

Serve the calls on #102 to #121 that this backend declined although NetworkX answers them, so that a backend graph gets them too, each with NetworkX's answer or error. Where NetworkX has a bug, the answer here is the one the docs below give, and the call NetworkX dispatches itself still gets NetworkX's, through the should_run this is stacked on. The difference and symmetric difference of a Graph and a DiGraph (#107) stay as they are, since #147 revises that rule.

  • bethe_hessian_matrix (03 dispatch #102) reads a backend graph's values where they are weight's, and otherwise weighs every edge 1, as NetworkX reads the graph. A weighted NetworkX graph is still declined: NetworkX reads weight here but declares no edge attribute, so its conversion carries no weights, and backend="graphblas" on such a graph raises NotImplementedError. Whether a NetworkX graph has weights is read once per version of the graph, through remembered.
  • reciprocity and overall_reciprocity (03 dispatch #102) answer an undirected graph as NetworkX does: 0.0 overall (NetworkXError for a graph without edges), and for nodes NetworkX's AttributeError, raised at the first node the graph has, as NetworkX's lazy search meets it; {} when it has none. The error names the class of the caller's graph, such as a subclass of nx.Graph, which from_networkx now records on a conversion and on a backend graph built from a NetworkX graph. The decorator is now NetworkX's, which refuses only an undirected multigraph.
  • hits (05 link analysis #104) serves method="svd", NetworkX 3.7's own computation (SciPy's svds with its start vector, max_iter and tol) on this backend's matrix, and raises NetworkX's ValueError: method not supported for any other method. The second method is "svd", not the "scipy" and "numpy" the audit named. Where the largest singular value is repeated (any undirected bipartite graph), SciPy's vector, and NetworkX's own answer, changes from one call to the next. NetworkX 3.6 has no method: NetworkX's dispatch passes a keyword it does not declare to the backend, so there this backend takes it as its own, as it took "power_iteration" before, while NetworkX alone raises TypeError. The notes NetworkX shows for hits say so.
  • average_shortest_path_length (13 distance measures #112) serves method="floyd-warshall" and "floyd-warshall-numpy", whose mean is the other methods' mean, and raises ValueError: method not supported before anything else, as NetworkX does. On a negative cycle it raises NetworkXUnbounded, as NetworkX 3.7's Floyd-Warshall does, for a backend graph and for backend="graphblas". NetworkX 3.6's Floyd-Warshall gives a number there, so where the installed NetworkX's does not raise, should_run leaves a NetworkX graph with a negative weight for those methods to NetworkX; whether a graph has one is read once per version of the graph, through remembered. The installed NetworkX is asked once per method, on a two-node negative cycle, and the answer is kept for the process, so it comes from NetworkX's own code, called without dispatching it and without writing NetworkX's config, which other threads share: a write there races with another thread's own with nx.config.backend_priority(...). In 3.6.1, 3.7 and dev, floyd_warshall raises only through floyd_warshall_predecessor_and_distance, which it calls dispatched, so a priority for algos or for that name would give the call to this backend, which raises on the cycle. That function's own code calls nothing dispatched, and it is what runs for "floyd-warshall". For the numpy method floyd_warshall_numpy's own code runs; the to_numpy_array it calls is dispatched, and this backend does not implement it. NetworkX's test mode hands that call to the backend under test anyway, where it raises pytest's xfail, so there the numpy method gets the other method's answer. Any error but NetworkXUnbounded counts as no, which leaves such a graph to NetworkX. Asked afresh 20000 times under no priority, algos, a priority for each of those names and the test mode, beside a thread looping on its own with over the priorities, beside one setting a priority back and forth, and from two threads at once, it gave no wrong answer and no error in any thread, and left the config as it was, in 3.6.1, 3.7 and dev. With a priority for this name, NetworkX 3.6 then gives its number. With the algos priority, NetworkX's own mean calls floyd_warshall, which this backend serves and which raises on a negative cycle in every version: that is floyd_warshall's own difference from NetworkX 3.6, which this does not change.
  • diameter, radius, periphery, center and eccentricity (13 distance measures #112) give the null graph the installed NetworkX's answer, which changes between versions: NetworkXPointlessConcept from 3.7, ValueError or {} in 3.6, ValueError with usebounds, and the maximum of a given e. The installed NetworkX is asked directly, on a null graph of the same kind; nothing is converted or walked. A precomputed sp on a null graph now gets that answer too.
  • k_core, k_shell, k_crust and k_corona (19 core #120) take a k that is not a real number to NetworkX's own test of each node's core number, in node order: a string or a complex number raises NetworkX's TypeError where NetworkX's comparison raises, a Decimal compares as a number, and the null graph compares nothing. The subgraph is built as for any other k. k_corona takes a k of None as the largest core number, as NetworkX does; it raised TypeError before.
  • bfs_edges and bfs_successors (11 bfs #110) walk with sort_neighbors as NetworkX's generic_bfs_edges does: sort_neighbors is asked for each node's neighbors as the node is found, the walk reads what it returns lazily and stops once every node is seen. It is handed each node's neighbors in node order, where NetworkX hands them in the order they were added, so a sort_neighbors that keeps its input's order walks differently; one that sorts the nodes gives NetworkX's tree. should_run leaves a NetworkX graph to the next backend or NetworkX, which hands the neighbors in the order they were added, and whose walk of its own graph is faster than this one in Python.
  • schultz_index and gutman_index (20 wiener efficiency #121) give a graph with a node named "weight" the index its degree gives. NetworkX builds its degrees as dict(G.degree, weight=weight), which gives that node the weight argument as its degree, so NetworkX raises TypeError on a connected graph and gives inf on another. should_run leaves such a NetworkX graph to the next backend or NetworkX; a backend graph and backend="graphblas" get the index.
  • Docs. The notes NetworkX shows for these names say each of the above.
  • Tests. A new file calls each case three ways: on a backend graph, with backend="graphblas" on a NetworkX graph, and with NetworkX choosing the backend, and compares each with NetworkX's answer or error (floats to 1e-12, the HITS vectors to 1e-6), or, for the three rules, with the documented answer, checking whether NetworkX converted the graph for the third. The cases are a weighted graph with a self-loop, r and nodelist, and the same values under another attribute; undirected graphs with nodes given as None, a node, lists with and without members, a missing node, an unhashable member before and after a member, and a string; HITS by "svd" on graphs that are not bipartite (weighted, directed, tol, nstart, unnormalized up to SciPy's sign, nodes out of row order, hubs and authorities of a digraph) and its errors, compared on NetworkX 3.6 with NetworkX 3.7's computation, which the tests hold and check against NetworkX's own where it has it, and on NetworkX 3.6 NetworkX's TypeError beside the backend's answer; Floyd-Warshall on weighted, directed and negative-weight graphs, two negative cycles (one whose negative weight lies between -1 and 0) and an unknown method, with NetworkX's number on the automatic path on NetworkX 3.6, the negative weight read once per version of the graph, and the installed NetworkX asked afresh under the algos priority, under a priority for each name its Floyd-Warshall calls and in its test mode, with nothing converted and nothing written to NetworkX's config, and a changed signature or a missing orig_func taken for no; reciprocity's error on a subclass; the five names on null graphs of both kinds with each argument; eight kinds of k on three graphs, and k_corona with None on four; three sorts on four graphs with depth_limit and reverse, the calls to sort_neighbors and what it yields being read, and a missing, an unhashable and a stranger node; and the Wiener relatives with a node named "weight" on connected and disconnected graphs, weighted and not. The tests of the old declines are gone. 50 mutants, of each rule and of each answer above, fail these tests in dev, 3.7 and 3.6.1, but these: the check of the installed NetworkX's Floyd-Warshall, made to answer that it raises (or that it does not), changes nothing on the NetworkX that does (or does not), and fails them on the other; and a negative weight seen only at -1 or below changes nothing where that check says it raises, and fails them on NetworkX 3.6. Among those that fail them: the check run through floyd_warshall's own code, or through either function dispatched, or by emptying the priorities in NetworkX's config; the numpy method asked in the test mode; and another error let out, or taken for yes.
  • NetworkX's tests through the backend, the whole suite in dev, 3.7 and 3.6.1: the same tests pass, skip and xfail before and after (none of 10343, 9930 and 6895 differs). The counts of calls served and declined change in the tests of these names (test_hits_invalid_method and the svd case, test_specified_methods and test_bad_method for the mean, test_diameter_radius_empty_graph and test_eccentricity, test_bfs_edges_sorting), and otherwise only in the tests whose counts also change between two runs of one tree (the traveling salesman ascent, test_kcomponents, test_lukes, the double-edge swap and small-world tests).

Stacked on #174.

These calls were declined, so a backend graph could not get them:

- bethe_hessian_matrix reads a backend graph's values where they are
  weight's. A weighted NetworkX graph is still declined, since NetworkX
  converts no edge data for this name; whether it has weights is now
  read once per version of the graph.
- reciprocity and overall_reciprocity answer an undirected graph as
  NetworkX does: 0.0 overall, and its AttributeError for nodes, naming
  the class of the caller's graph, which from_networkx now records.
- hits serves method="svd" with SciPy's svds on this backend's matrix,
  as NetworkX 3.7 computes it, and raises its ValueError for an unknown
  method. On NetworkX 3.6, which has no method, it is this backend's
  own keyword.
- average_shortest_path_length serves both Floyd-Warshall methods and
  raises NetworkX's ValueError for an unknown method. On a negative
  cycle it raises NetworkXUnbounded, as NetworkX 3.7 does; where the
  installed NetworkX's Floyd-Warshall gives a number instead, should_run
  leaves a NetworkX graph with a negative weight to it.
- diameter, radius, periphery, center and eccentricity give the null
  graph the installed NetworkX's own answer, which differs between its
  versions.
- k_core, k_shell, k_crust and k_corona compare a k that is not a real
  number with each core number as NetworkX does, and k_corona takes a
  k of None as the largest core number.
- bfs_edges and bfs_successors walk with sort_neighbors as NetworkX
  does, handing it each node's neighbors in node order. should_run
  leaves a NetworkX graph to NetworkX, which hands them in the order
  they were added, and whose walk of its own graph is faster.
- schultz_index and gutman_index give a graph with a node named
  "weight" the index its degree gives, where NetworkX takes that node's
  degree from its weight argument. should_run leaves such a graph to
  NetworkX where it would convert it.
@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.41521% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.28%. Comparing base (7933efc) to head (30663db).

Additional details and impacted files
@@                  Coverage Diff                   @@
##           75-should-run-base     #176      +/-   ##
======================================================
+ Coverage               93.07%   93.28%   +0.21%     
======================================================
  Files                     184      185       +1     
  Lines                   11568    12054     +486     
  Branches                 1290     1355      +65     
======================================================
+ Hits                    10767    11245     +478     
- Misses                    549      556       +7     
- Partials                  252      253       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant