FrankenNetworkX

Guide/Start here

FAQ

4 min readFrom the README

Is it really a drop-in replacement? Across the pinned 3.6.1 declared import-and-signature FeatureUniverse, all 4,129 applicable paths are strictly present (100.0%), with 0 partial and 0 missing. The 476 algorithms in backend.py are the dispatch registry, not a proof that every NetworkX path or behavior is covered; behavioral claims remain scoped to their conformance fixtures.

Why are iteration orders such a big deal? NetworkX users often write code that implicitly depends on dict insertion order or BFS visit order or connected_components set ordering. If a "faster NetworkX" returns the same set of correct answers but in a different order, downstream code breaks subtly. CGSE + the parity tests + the iteration-order audit ledger collectively make iteration order a first-class API contract.

Do I need a Rust toolchain? No: prebuilt ABI3 wheels on PyPI support Linux, macOS, and Windows for Python 3.10+. Only contributors developing Rust internals or building from source need rustup and the nightly toolchain pinned in rust-toolchain.toml.

What's the ABI3 story? The native extension uses pyo3/abi3-py310. One wheel works for Python 3.10, 3.11, 3.12, 3.13, and 3.14+. No per-Python-version build matrix is needed.

Is it thread-safe? Algorithm calls release the GIL at hundreds of call sites and operate on borrowed adjacency. Concurrent reads are safe. Concurrent writes are not. Graph mutation is &mut self in Rust, and _sync_rust_edge_attrs tolerates concurrent borrow with bounded retry but is not a substitute for application-level synchronization on shared graphs. The tests/python/test_thread_safety.py suite exercises the concurrent-read contract.

What's "Strict" vs "Hardened"? A runtime mode in fnx-runtime::CompatibilityMode. Strict maximizes byte-for-byte NetworkX compatibility on V1-scoped APIs and fails closed on malformed input. Hardened preserves the API contract while applying bounded defensive recovery; useful when ingesting adversarial graphs from untrusted sources. Both modes record every action selection as a DecisionRecord in an evidence ledger.

What's CGSE? The Canonical Graph Semantics Engine: a Rust crate (fnx-cgse) that makes tie-breaking, complexity witnesses, and policy registries first-class. Twelve reference algorithms are registered and emit length-prefixed-Blake3 ComplexityWitness receipts on their primary public Python routes inside a collection scope (with indexed public Prim reporting WeightThenInsertionOrder). See Inspecting CGSE policy + witness types from Python for the implemented routes and receipt checker.

Why not just use networkx[backend=cugraph] / igraph / graph-tool? Use them if they fit. cugraph requires CUDA; igraph and graph-tool have different APIs and don't preserve nx tie-break behavior. The niche FrankenNetworkX fills is "I have an nx codebase, I want it faster, I do not want to think about tie-breaks or rewrite anything."

Does the backend mode work with nx.config.backend_priority and explicit backend="..." kwargs? Yes. The list-form controls the default; the per-call kwarg overrides it. fnx's BackendInterface.can_run honors both paths the same way; for unsupported algorithms or unsupported argument shapes, the call falls through.

What happens to graph mutations made through the backend? The same as with any NetworkX backend. With backend_priority, NetworkX does not auto-dispatch functions that mutate their input (relabel_nodes(copy=False), contracted_nodes, set_node_attributes, the edge swaps, ...), so they run in NetworkX on your graph. With an explicit backend="franken_networkx" on a NetworkX graph, NetworkX converts the graph and the mutation lands on the converted copy, not on your graph; NetworkX's dispatcher documents this for all backends. Called on an fnx graph (or directly as fnx.<function>), they mutate that graph exactly as NetworkX would, including seeded edge swaps producing NetworkX's graph for the same seed.

How are NaN edge weights handled? Exactly as NetworkX handles them, in every mode. The Dijkstra / A* / PageRank paths use a native Rust non-finite-weight scan as a fast pre-check and route NaN/±∞-weighted inputs to NetworkX-exact code, so the result (including NetworkX's own NaN semantics) matches nx. The strict/hardened modes currently change reader behaviour only; there is no NaN coercion.

Why do some functions return an iterator and others a list? Because NetworkX does. The contract is that fnx.<func> returns the exact same Python type as nx.<func>: generators stay generators, dict_values stays dict_values, list stays list. This was specifically locked for all_shortest_paths (br-r37-c1-6atv8).

Can I run an algorithm under a non-default tie-break policy? No. Production kernels implement their ordering directly and do not accept a TieBreakPolicy parameter. The enum describes reference policies and supports Rust-side policy tests; it is not a runtime policy switch for the Rust or Python algorithm API.

Does pip install franken-networkx install NetworkX too? Yes. networkx>=3.0 is a hard dependency. fnx's wrapper layer imports nx for exception classes, the dispatch protocol, and the fallback path on unsupported argument shapes.

Is there a no-NetworkX build? Not currently. fnx re-exports NetworkX's exception classes and some objects by identity, and the remaining NetworkX-bound routes (see "Parity coverage today") need nx available. A "pure fnx" mode would require porting those routes to native code.