Docs/Guarantees and recipes
Migrating from NumPy: A Checklist
A practical checklist for Python users moving an existing NumPy-based codebase to fnp_python.
| Step | What to do | Why |
|---|---|---|
| 1 | import fnp_python as np (replace import numpy as np) |
fnp_python re-exports the full numpy.__all__, so the import rename usually suffices. |
| 2 | Run your existing test suite. | The surface is 1:1, and NumPy's own suite passes with fnp_python swapped in except for the divergences the drop-in run lists (47 of about 47,200 tests on 2026-10-08, each owned by a bead); check your results against that list. |
| 3 | Inspect failures for is-comparisons against numpy types (e.g. type(x) is numpy.ndarray). |
The arrays returned from re-exported numpy functions ARE numpy ndarrays; those returned from Rust-engine fast paths might be the same. If is-comparisons break, switch to isinstance(x, np.ndarray). |
| 4 | Pin a specific seed everywhere that uses np.random.default_rng() when reproducibility matters. |
SeedMaterial::None now matches NumPy by sourcing OS entropy; explicit seeds give stable streams. |
| 5 | Replace single-RNG parallel patterns with SeedSequence.spawn(n). |
If you've been calling np.random.default_rng() once per worker without seed spawning, you've been relying on OS entropy for stream independence; switch to explicit spawn so the behavior is reproducible AND parallel-safe. |
| 6 | Audit your .npy / .npz consumers if you handle untrusted files. |
In strict mode (the default) fnp_python.load hands file-like objects and every .npz to numpy.load, so untrusted input meets NumPy's parser. Hardened mode (FNP_RUNTIME_MODE=hardened or fnp_python.set_runtime_mode("hardened")) checks every load source against the fnp-io bounds first (MAX_HEADER_BYTES = 65,536, rank <= 32, MAX_ARCHIVE_MEMBERS = 4,096, MAX_ARCHIVE_UNCOMPRESSED_BYTES = 2 GiB, ...) and raises ValueError on a violation. If your pipeline loads files beyond these bounds, it cannot run in hardened mode. |
| 7 | np.empty() behaves as in NumPy. |
fnp_python.empty calls numpy.empty (contents uninitialized); only the Rust UFuncArray::empty zero-fills. |
| 8 | If you use the C-extension API (np.PyArray_* from your own C extension), that surface is not exposed by fnp_python. |
You'd need to keep using upstream numpy for those calls, or to invoke fnp_python via Python rather than via the C API. |
| 9 | Cap any errstate or seterr usage to RAII scopes when possible. |
The Rust-side errstate() is RAII-scoped per thread. Global seterr works but is process-wide and harder to reason about. |
| 10 | Run a parity-test pass: pin a representative input, call the operation under both numpy and fnp_python, assert equality / closeness. |
This gives you a regression net for the migration even if you don't adopt the upstream conformance harness. |
Most codebases need only steps 1, 2, and 4. Steps 5–10 matter if you depend on specific semantics that the migration could perturb.