FrankenNetworkX

Guide/In production

Common Pitfalls

5 min readFrom the README

On this page 7
"Why is nx.shortest_path not faster after I installed franken-networkx?""My algorithm result has the same set of items but in a different order between runs""My benchmark shows fnx is *slower* than networkx""I called G.add_edge(0, 1) and then G[0][1]['weight'] = 5 but nx.shortest_path(G, 0, 1, weight='weight', backend='franken_networkx') returned the wrong path""MultiGraph edge keys of 0, 0.0, and False are colliding""I'm getting NetworkXNotImplemented on a function I thought was supported""verify_docs.py says generated docs validation failed"

Pitfalls real users have hit, in roughly descending order of frequency.

"Why is nx.shortest_path not faster after I installed franken-networkx?"

You probably forgot to enable the backend:

import networkx as nx
nx.config.backend_priority = ["franken_networkx"]   # ← required

Installing the wheel doesn't automatically rewire nx.*; the user is in charge of enabling the backend. This is intentional (otherwise installing the wheel would silently change behavior of every NetworkX program on the machine).

"My algorithm result has the same set of items but in a different order between runs"

fnx shouldn't be the cause; CGSE pins iteration order. If you see drift, the cause is almost always a Python-side issue:

  • You're iterating a dict constructed from a set (sets have hash-randomized iteration order in CPython unless PYTHONHASHSEED is fixed).
  • You're collecting connected_components into a set of frozensets and printing them; the print order depends on frozenset.__hash__, not on fnx.

Use list(...) end-to-end and the order will be deterministic.

"My benchmark shows fnx is slower than networkx"

For very small graphs (< 100 nodes / single-shot analysis), the PyO3 marshaling cost can exceed the algorithm cost. Three suggestions:

  • Use a release build. maturin develop --release --features pyo3/abi3-py310. Debug builds are 5–20× slower.
  • Amortize the marshaling. A single fnx.pagerank(G) call pays the marshaling once; calling it 1000 times in a loop pays it 1000 times. Reuse the result.
  • Use the standalone API, not backend dispatch, when you know the algorithm is supported. Direct fnx.pagerank(G) skips the dispatcher overhead.

Known Performance Trade-offs and Inverted Operations

Analytics kernels are where fnx wins (the per-family table above ranges from about 1.3× to 194×; whole jobs 1.1–2.2×). The class core and the backend boundary are where it loses. Figures below are same-process sanity probes from 2026-09-23 on a loaded shared host (load 30–70), unless a harness is named — the direction and the growth pattern are reliable, the decimals are not:

Operation Workload / shape fnx vs NetworkX Root cause Status
remove_node(u), any node but the last Graph/DiGraph, n = 1.6k → 25.6k, ~4n edges 0.52× → 1.75× / 0.78× → 1.31× (O(degree) per removal) flat ~2.5–3.5 µs per call: Graph still loses at 1.6k and 6.4k nodes, wins at 25.6k Open — br-r37-c1-epic-storage-architecture-yr2oc.1 (multigraph classes)
remove_node(u), any node but the last MultiGraph, n = 1.6k → 25.6k, ~4n edges 0.60× → 0.76× (O(degree) per removal); 0.27–0.30× when built one add_edge at a time a constant per call; a graph built edge by edge also pays its edges' Python attribute mirrors Open — same bead; mirrors: br-r37-c1-wzoa7, br-r37-c1-rc0923-epic-perf-where-we-lose-sfq4w.1
remove_node(u), any node but the last MultiDiGraph, n = 1.6k → 25.6k, ~4n edges 0.32× → 0.45× (O(degree) per removal) the String-keyed store frees ~7 blocks per incident edge Open — same bead (slot-keyed store)
remove_node on a graph with edge attributes, with a single-node read between removals Graph/DiGraph, n = 1.6k → 25.6k, one attribute per edge 0.2–0.5× each removal updates the Python attribute mirrors of the incident edges Open
copy.copy(G) n = 10 → 10k 1.34× → 0.0031× (O(n)); attr dicts not shared as in nx fnx copies the graph, nx aliases it Open — br-r37-c1-epic-storage-architecture-yr2oc.3
attributed graph memory 800k edges, 1–2 edge attrs 3.4–4.3× nx's RSS (unattributed: 0.63×) two attribute stores (Python dicts + native) Open — br-r37-c1-rc0923-epic-perf-where-we-lose-sfq4w.1
backend mode, cold conversion nx graph, 80k edges, cheap kernel (BFS, components, sssp, dijkstra) converting costs 0.12–0.34× of networkx's own run (0.66 µs per edge topology-only, 1.5 at 400k edges; attributes copied only as networkx's hints ask), so should_run lets networkx run a cheap kernel's first calls (~1.0×) and converts once the graph's calls have paid for it; 20 repeated calls 1.04–6.9×, warm cache 1.7–47× conversion still builds one Python tuple per edge (0.3 µs/edge target not met) Open — …sfq4w.2
G.has_edge(u, v), present edge Graph/DiGraph, n = 20k, int nodes added out of order; DiGraph with str nodes 0.975× / 0.975× three hash probes (u, v, the edge) where nx does two dict lookups Open — …sfq4w.3
G[u][v] MultiGraph / MultiDiGraph, direct edge-keydict probe 0.42–0.50× (Graph 1.09–1.24× and DiGraph 1.07–1.09× win; 2026-09-25, admissible, see the per-surface table) the multigraph row and cell are stacked Python view layers; Graph/DiGraph rows are the native C-slot AtlasView Open — br-r37-c1-ey6ob
MultiGraph/MultiDiGraph.get_edge_data(u, v) unkeyed, 1–16 parallel edges 0.57–0.62× per call, flat in parallel edges; consumption 0.73–0.89× a registry lookup per call where nx does two dict lookups; the keydict itself is a real dict (2026-09-24) Open (per-call cost)

"I called G.add_edge(0, 1) and then G[0][1]['weight'] = 5 but nx.shortest_path(G, 0, 1, weight='weight', backend='franken_networkx') returned the wrong path"

This is a known sync subtlety. _sync_rust_edge_attrs(G) runs transparently before weighted-algorithm dispatch, but if you're doing direct G[u][v][k] = v mutation outside of any algorithm call and then querying G.adj[u][v][k], you may see stale Python-side state. The fix landed in beads br-r37-c1-sjf4t and br-r37-c1-0x9pd; if you see this on the latest version, please file an issue.

"MultiGraph edge keys of 0, 0.0, and False are colliding"

This is intentional. fnx matches Python's hash(0) == hash(0.0) == hash(False) dict-key semantics. If you want distinct edges, use distinct keys (e.g. 0, 1, 2).

"I'm getting NetworkXNotImplemented on a function I thought was supported"

A few functions accept the graph type but not the argument shape you provided. Examples:

  • min_cost_flow rejects undirected input (matches nx).
  • gomory_hu_tree rejects MultiGraph input.
  • node_connectivity(G, flow_func=my_callable) rejects the custom callable; drop the flow_func kwarg or call the nx version directly.

Check docs/upstream_divergence_ledger.md for the canonical list.

"verify_docs.py says generated docs validation failed"

The public surface changed and docs/coverage.md no longer matches it; the printed diff shows which classification moved. Regenerate with python scripts/generate_coverage_matrix.py and commit the result with the change that caused it. Read the diff first: a row moving to partial or an export moving to NX_DELEGATED is a real change in what fnx provides, not noise.