Guide/In production
Advanced Topics
2 min readFrom the README
On this page 5
Backend dispatch from an nx.Graph you can't easily convert
If you're working in a third-party library that hands you nx.Graph instances, the easiest path is:
import networkx as nx
# Pretend this came from a library that only speaks nx.
third_party_graph = nx.karate_club_graph()
# Either: globally — shown, not executed here, because setting it GLOBALLY is
# process-wide and would change dispatch for every later example in this file.
#
# nx.config.backend_priority = ["franken_networkx"]
# Or: with a context manager (NetworkX >= 3.4), which scopes the change.
with nx.config(backend_priority=["franken_networkx"]):
pr = nx.pagerank(third_party_graph)
The backend dispatcher converts the nx graph at the dispatch boundary; the original graph is unchanged.
Converting an fnx graph to an nx graph
Three options, in increasing fidelity:
import franken_networkx as fnx
import networkx as nx
G = fnx.path_graph(5)
# Quickest: identity-of-shape via edgelist.
nx_view = nx.Graph(list(G.edges()))
# Full attribute round-trip via node-link JSON.
data = fnx.node_link_data(G)
nx_full = nx.node_link_graph(data)
# Topology-preserving via adjacency walk (used internally by the backend
# convert_to_nx path; respects insertion order).
from franken_networkx.readwrite import _from_nx_graph # private helper for parity
For most users, the second option is what you want: it preserves graph-level, node-level, and edge-level attributes.
Witness ledger artifacts
The conformance harness writes one *.report.json per fixture into artifacts/conformance/latest/ (120 in the current snapshot, dated 2026-09-09). Each report carries {suite, fixture_id, fixture_name, fixture_source_hash, mode, seed, passed, reason_code, mismatches[], mismatch_taxonomy, strict_violation_count, hardened_allowlisted_count, threat_class, duration_ms, replay_command, witness}. Summary artifacts (dashboard, flake quarantine) carry a RaptorQ sidecar (*.raptorq.json) and a decode-proof receipt (*.recovered.json); the per-fixture reports do not. The structured log is structured_logs.jsonl, one line per event.
RuntimePolicy at the Rust layer
RuntimePolicy lives in fnx-runtime and bundles the compatibility mode, an allowlist of safe operations, a Bayesian admission posterior, a loss-matrix for decision-theoretic action selection, and an append-only EvidenceLedger. It is not a global; it is constructed per call so behavior is reproducible from the decision log alone:
use fnx_runtime::{RuntimePolicy, CompatibilityMode, DecisionAction, EvidenceTerm};
let mut policy = RuntimePolicy::hardened();
assert_eq!(policy.mode(), CompatibilityMode::Hardened);
assert!(policy.allows("bounded_diagnostic_enrichment"));
// Algorithms / parsers can record decisions into the policy's evidence ledger:
policy.record(
"read_graphml", // operation
DecisionAction::FullValidate, // action selected
0.7, // incompatibility probability
"parser warning observed", // rationale
vec![ // evidence terms (signal/value/llr)
EvidenceTerm {
signal: "warning_count".into(),
observed_value: "1".into(),
log_likelihood_ratio: 0.3,
},
],
);
for record in policy.decision_log().records() {
println!("{:?}", record);
}
From Python, the mode is set with fnx.config.compatibility_mode, the fnx.compatibility_mode(...) context manager, or a reader's mode= keyword (see "Strict vs Hardened Modes"); the readers are where the modes currently behave differently. Algorithm kernels do not yet branch on the mode.
Thread safety
Algorithm calls release the GIL during their inner loops, with the following consequences:
- Concurrent reads of the same graph from multiple Python threads are safe (each one borrows the underlying Rust adjacency by reference).
- Concurrent writes are not safe.
Graphmutation is&mut selfin Rust; Python-side, the mutation paths take a write borrow internally, and_sync_rust_edge_attrstolerates concurrent borrow with bounded retry, but neither is a substitute for application-level synchronization on a shared graph. - The
tests/python/test_thread_safety.pysuite exercises the concurrent-read contract specifically; concurrent Dijkstra calls from a thread pool over a shared graph is the canonical pattern.
Native parallel kernels share one fallibly initialized worker pool. Set
RAYON_NUM_THREADS before the first parallel call; the default follows CPU
availability. On Linux, finite address-space limits are checked before spawning:
admission reserves 256 MiB for caller/TLS work plus 128 MiB and the configured
stack per requested worker. The full request is admitted or the existing serial
kernels are used, with one stderr diagnostic; a failed admission or spawn is
cached for the process lifetime. An installed Rust caller pool takes precedence.
This conservative admission policy is not a general out-of-memory guarantee:
graphs and algorithms still need memory. Other platforms retain fallible spawn
handling without the Linux address-space preflight.