fix(cli): make graphify path deterministic across runs (#2074)#2087
Closed
HerenderKumar wants to merge 1 commit into
Closed
fix(cli): make graphify path deterministic across runs (#2074)#2087HerenderKumar wants to merge 1 commit into
HerenderKumar wants to merge 1 commit into
Conversation
…#2074) `graphify path A B` could return a different equal-length route on identical, repeated calls against an unchanged graph.json. `path` loads the graph via node_link_graph with no `multigraph` key, so it becomes a MultiDiGraph, and `nx.shortest_path` returns whichever equal-length path the adjacency iteration order reaches first — an order Python's per-process hash randomization shuffles. Same graph, a different route each run. Select the canonical shortest path instead: the lexicographically smallest by node-id sequence among all_shortest_paths. Deterministic regardless of hash seed (matches the reporter's stable-sort-by-node-id suggestion). With the route now stable, the relation label rendered from the chosen edge is stable too. Test spawns `graphify path` across 12 hash seeds and asserts one identical route.
Collaborator
|
Thanks @HerenderKumar — #2074 was fixed in v0.9.23: |
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.
Fixes #2074.
graphify path A Breturned a different equal-length route on identical, repeated calls against an unchangedgraph.json.Root cause
pathloads the graph vianode_link_graph, andgraph.jsoncarries nomultigraphkey, so it comes back as aMultiDiGraph. The route is then computed withnx.shortest_path, which returns whichever one of the equal-length shortest paths the adjacency-iteration order reaches first — and Python's per-process hash randomization shuffles that order. Same graph, a different route each run.Reproduced on a diamond graph (
a→b→d,a→c→d):graphify path a dflips between routes purely byPYTHONHASHSEED, no edits in between.Fix
Select the canonical shortest path instead: the lexicographically smallest by node-id sequence among
all_shortest_paths. Deterministic regardless of hash seed (matches the reporter's stable-sort-by-node-id suggestion). With the route stable, the relation rendered for each hop is stable too.Test
test_path_is_deterministic_across_hash_seedsspawnsgraphify pathacross 12 hash seeds and asserts one identical route. Red-green verified: it fails on the old code (routes vary) and passes after the fix.Out of scope
The reported phantom
--calls-->(a relation that doesn't match the two labeled nodes) is a label-collision artifact —pathprints node labels but traverses node IDs, and distinct IDs can share a label — i.e. issue #1829. This PR fixes the non-determinism; the label disambiguation belongs with #1829.