Repository navigation
Conversation
should_run asks a wrapper's own rule, set with nxapi._utils.should_run, as can_run does. NetworkX asks it only on the automatic path, so a rule there moves a call to NetworkX without declining a backend graph or a call that names this backend. A rule reads a fact from the NetworkX graph through remembered, which keeps it in the graph's __networkx_cache__ until NetworkX empties it. It keeps nothing while cache_converted_graphs is off or in NetworkX's test mode, where an edit in place needs no clearing, or for a view, whose cache NetworkX keeps when the graph under it changes. The rebuild verdict in can_run now goes through it: a view converted before its graph gained a second edge attribute was answered from the stale conversion without that attribute, and is now left to NetworkX. has_reusable_conversion says whether NetworkX will give a call a cached conversion, from the key NetworkX's own conversion code makes for that call. It says no for a view, whose cached conversion may be stale; in NetworkX's test mode, which converts afresh; and if the private names it reads have changed.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 20-wiener-efficiency #174 +/- ##
========================================================
+ Coverage 92.88% 93.07% +0.19%
========================================================
Files 182 184 +2
Lines 11227 11568 +341
Branches 1274 1290 +16
========================================================
+ Hits 10428 10767 +339
- Misses 546 549 +3
+ Partials 253 252 -1 🚀 New features to boost your workflow:
|
eriknw
force-pushed
the
75-should-run-base
branch
from
December 3, 2026 23:43
ce2429d to
7933efc
Compare
This was referenced Dec 4, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
Dispatcher.should_run, which asks a wrapper's own rule (set withnxapi._utils.should_run) ascan_rundoes, and two helpers for rules that read what NetworkX caches on a graph. No name gets a rule here; each comes with the change that needs it. NetworkX asksshould_runonly where it would convert a NetworkX graph for a call that names no backend, aftercan_runsaid yes, so a rule there moves only that call to NetworkX: a backend graph, and a call withbackend="graphblas", are served whatever it says. The code is the code #151 and #153 each add, byte for byte, so both drop their copies when restacked on this; a merge of this with each of #151, #153 and #165 is clean.remembered(graph, key, compute). A rule that reads a fact from the NetworkX graph before every call reads it once per version of the graph. The fact is kept in the graph's__networkx_cache__, which NetworkX empties when the graph changes through its methods, and which the caller clears after an edit in place, as NetworkX asks for its own conversions. Nothing is kept whilenx.config.cache_converted_graphsis off, when an edit in place needs no clearing; in NetworkX's test mode, which converts afresh for each call and so lets a test edit data in place between calls; or for a view, since NetworkX does not empty a view's cache when the graph under it changes.can_run, for the names whose result keeps the input's data (k_truss, the k-core names,ego_graph,reverseand the operators), now goes throughremembered. It used to be kept on views too. A subgraph view converted before its graph gained a second edge attribute was then answered from the stale conversion:k_trussgave the edge(0, 1)as{'weight': 1.0}where NetworkX gives{'weight': 1.0, 'colour': 'red'}. It is now declined, and NetworkX answers.has_reusable_conversion(name, bound, graph_name). Whether NetworkX will give this call a cached conversion of the graph. The cache key is the one NetworkX's own conversion code makes for the call, run on a stand-in that records the key instead of converting, and the search is NetworkX's own, on a copy of the cache, since the search may write to it. It is False while caching is off; for a view (anything holding its graph as_graph), since NetworkX keeps a view's cache, conversions included, when the graph under it changes, so a rule that serves because a conversion is cached would serve the view from a stale one; in NetworkX's test mode, which converts afresh for a call that names no backend; and if a private name it reads from NetworkX has gone or changed shape: every such read is inside one guard, so a later NetworkX gives the answer that claims nothing rather than an error in the user's call. A rule that claims a call because a conversion is cached, or that reads a fact from one, should ask this: a conversion cached for other attributes, or one NetworkX will not use for this call, says nothing about it. Nothing calls it yet.should_runis asked on the automatic path alone (a spy on it and onconvert_from_nx: none for a backend graph, a conversion and noshould_runforbackend="graphblas"); a declining rule moves only the automatic call; a hook gets the arguments by name with NetworkX's defaults, and none acts on arguments that do not bind. A rule reads its graph once per version, again after a mutation or a cleared cache, and on every call with caching off; after an edit in place to one weight, the answer is NetworkX's both with caching off and with caching on and the cache cleared. Views are read afresh, and so is every fact in NetworkX's test mode; a view's cached conversion (of a subgraph, of a digraph reversed, and of a digraph as undirected) is not reusable, before or after its graph changes, where its graph's is. With each private name the helpers read removed or replaced by one of another shape (the registry, the cache search, the key, the failure marker, the test-mode flag, the conversion code),has_reusable_conversionsays False andrememberedcomputes afresh.has_reusable_conversionis checked against NetworkX's own cache search for every dispatched name, after five primers (none, a weighted, an unweighted and another attribute's conversion, and the call itself) and withweightas declared, None and another attribute. It agrees with NetworkX on all 1115 calls in dev and 3.7 and all 1095 in 3.6.1, of which NetworkX reused a conversion in 665 and 657. 24 mutants each fail these tests in dev, 3.7 and 3.6.1, among themshould_rundropping the rule's reason or acting on arguments that do not bind, facts kept with caching off, in test mode, on views or outside the cache, a test mode that cannot be read taken as off, a guard that catches only some errors, and a cache read keyed byweightalone, by an exact key, or claimed with caching off, in test mode, for a view, or for any view but a subgraph.test_kcomponents,test_lukesand the double-edge swap and small-world tests, which draw on unseeded or shared random state), and by one call on a MultiDiGraph in 3.6.1, which both trees decline before any rule this changes.Stacked on #121.