Skip to main content

nefi

Neural-Field Inversion: physics-faithful, label-free inverse problems.
A coordinate neural field is fitted through your instrument's physics, from a single measurement, with no training data.

CI Docs build Documentation License: MIT Python 3.10+ PyTorch 2.1+ arXiv NeTMY arXiv NeFTY

Documentation · Get started · Gallery · Interactive 3-D · Papers

Four inverse problems solved by nefi: NV noise spectra to spin sources, a 16-view sinogram to an attenuation map, an NV stray-field image to a sheet current, acoustic traces to a sound-speed map

Why nefi

  • The physics stays exact. Every candidate field passes through a differentiable model of your instrument, whether FFT optics, PDE solvers with exact adjoints, wave propagation or scattering, so the answer is always consistent with the physics rather than a soft penalty away from it.
  • No training data. The unknown is optimized for the measurement at hand with a coarse-to-fine, frequency-annealed schedule. There is nothing to collect, nothing to amortize and nothing to go stale.
  • It adapts itself. Noise level, budget, learning rate, regularization strength and even the representation can be chosen automatically, and gauge freedoms that the data cannot resolve are detected and fixed.
  • The representation is the prior. Neural fields, grids, level sets, layered media and coordinate warps are interchangeable, and the library measures which one matches your operator.
  • It tells you how far to trust the result. Noise-floor verdicts, ill-posedness diagnostics, a benchmark protocol with confidence intervals and an inverse-crime guard, and refinements that are refused when the data do not support them.
The nefi recipe: coordinates, annealed Fourier encoding and a field with value heads (the prior), a differentiable operator (the physics), losses against the measurement and a multiscale solver (the fit), diagnostics (the trust)

Quickstart

pip install nefi                             # torch, numpy, scipy, pyyaml, tqdm ("nefi[viz]": + matplotlib)
nefi run toy1d                               # generate → invert → evaluate → runs/toy1d-<hash>/
nefi bench toy1d --methods neural,grid --n 4 --seeds 0,1
nefi diagnose toy1d                          # sensitivity, iter-0 gradient, filter rows, spectrum
import nefi
from nefi.instances.toy1d import make_problem

problem, gt, meas = make_problem(n=128, seed=0)      # 1-D deblurring, seconds on a CPU
result = nefi.invert(problem)                        # neural field + annealed two-stage curriculum
print(nefi.metrics.psnr(result.fields["x"], gt["x"]))

Bring your own problem — any measurement process you can write in PyTorch, no subclassing:

import torch
import nefi

k = torch.tensor([1.0, 4.0, 6.0, 4.0, 1.0])
k = (k[:, None] * k[None]) / 256

def forward(x):                                   # your physics: a blurred, saturating camera
    blurred = torch.nn.functional.conv2d(x[None, None], k[None, None], padding=2)[0, 0]
    return torch.tanh(1.5 * blurred)

x_true = torch.zeros(64, 64); x_true[20:44, 16:40] = 1.0
y = forward(x_true) + 0.01 * torch.randn(64, 64)  # your data

problem = nefi.from_forward(forward, y, shape=(64, 64),
                            prior="nonnegative + piecewise_constant")   # what you know
result = nefi.invert(problem)
print(nefi.quick_report(result, problem, gt=x_true))   # did the fit reach the noise floor?

from_forward chooses the representation, initialization, noise level, loss weights, learning rate and curriculum; every decision is logged and overridable (guide).

Twelve 1-D and 2-D systems, each as ground truth, measurement and reconstruction with PSNR, solve time and steps

Twelve of the 17 registered systems as ground truth · measurement · reconstruction — one gallery run on a CPU. Browse the gallery →

What's inside

Representations neural fields with annealed Fourier features, grids, hash grids, low-rank, level sets, Gaussian splats, Deep Decoder; geometric fields (layered media, anomalies, star shapes, warps) with adaptive annealing, capacity growth and held-out selection — geometry
Operators & physics FFT convolution, NV dipolar spectra, magnetostatics, Radon, Poisson, elliptic PDEs with implicit-function adjoints, implicit-Euler heat with a discrete adjoint, waves with PML and checkpointing, Born and Lippmann–Schwinger scattering, angular-spectrum optics, Gray–Scott — physics
Losses & priors MSE, log-MSE, Poisson NLL, Huber, TV, ℓ1, Laplacian, physics penalties; value heads as hard priors; a prior DSL ("nonnegative + sparse") — zoo
Curriculum & solver multiscale stages, annealing resets, LR schedules, discrepancy stopping, NaN guard with rollback, EMA, restarts, time budgets, checkpoints
Diagnostics sensitivity maps, iter-0 gradient and center bias, filter-kernel rows Gθei, singular values, energy barriers, the data-fit paradox — diagnostics
Benchmarking paired samples × seeds, 95 % confidence intervals, runtime and memory, ablations, sweeps, inverse-crime guard, sharded cluster campaigns — benchmarking
Auto-tuning gauges, budgets and learning rates against the noise floor, Morozov regularization, an acquisition report — auto-tuning
Edge refinement multi-phase level sets, phase fields, TV sharpening, with a data-fit acceptance test and a control run — refinement
Visualization comparison figures, measurement viewers, training dynamics, 3-D slices and isosurfaces, a dependency-free interactive 3-D viewer — visualization
Performance batched multi-measurement solving (vmap), whole-step torch.compile, CUDA graphs, mixed precision, a fast heat stencil — performance
CLI nefi list · run · bench · bench-merge · diagnose · autotune · ablate · sweep — reference

Instances

Seventeen registered problems, each runnable end to end with nefi run <name> --smoke and documented on its own page.

group instance problem physics
papers nv_relaxometry spin sources + Larmor field from NV noise spectra (NeTMY) dipolar tensor kernel × Lorentzian
thermal_tomography 3-D diffusivity from pulsed-thermography frames (NeFTY) implicit-Euler heat, discrete adjoint
classic imaging toy1d 1-D deblurring (tutorial, CI) FFT blur
deconvolution image deblurring, Gaussian or Poisson noise FFT convolution
sparse_view_ct sparse-view and limited-angle CT differentiable Radon transform
elliptic poisson_source sources from sparse potentials spectral Poisson solver
eit conductivity from boundary voltages elliptic PDE, implicit-function adjoint
darcy_flow log-permeability from well pressures elliptic PDE, implicit-function adjoint
current_density sheet current from its NV stray field planar magnetostatics
wave · optics · reaction wave_fwi sound speed from acoustic traces wave equation, leapfrog + PML
diffraction_tomography scattering contrast from scattered fields Born / Rytov
holography phase from multi-distance intensities angular-spectrum propagation
reaction_diffusion Gray–Scott feed rate from snapshots reaction–diffusion time stepping
volumetric ct3d 3-D sparse-view CT slice-stacked Radon transform
deconvolution3d fluorescence z-stack deconvolution 3-D FFT convolution
dot3d diffuse optical tomography diffusion equation, Robin boundaries
photoacoustic3d photoacoustic tomography, planar array 3-D wave equation

Interactive 3-D

Interactive viewer: ground truth, smooth and edge-refined isosurfaces of a 3-D CT reconstruction, with IoU and Dice

Ground truth · smooth · edge-refined, one camera, IoU and Dice computed in the browser — a self-contained HTML file written by nefi.viz.save_volume_viewer. Rotate it live →

Reproducing the papers

configs/nv_relaxometry_paper.yaml and configs/thermal_tomography_paper.yaml hold the papers' settings table by table. The server runbook lists the exact commands for the headline tables, their GPU cost and the caveats to check first, and the paper → code map traces every equation to the code.

nefi bench configs/nv_relaxometry_paper.yaml --methods netmy,f1,grid,grid_f1 \
     --classes all --by-class --n 64 --seeds 0,1,2 --device cuda        # NeTMY Tab. 1
nefi run configs/thermal_tomography_paper.yaml --device cuda             # one NeFTY specimen

Development

git clone https://github.com/ContinuumCoder/NEFI.git && cd NEFI
pip install -e ".[dev]"      # + pytest, ruff, mypy, scikit-image, matplotlib, typer, rich
make test                    # fast CPU suite; make lint, make smoke

The latest development version installs with pip install git+https://github.com/ContinuumCoder/NEFI.git; see CONTRIBUTING.md.

Documentation

Get started · Tutorials · Guides · Gallery · Physics · Instances · Research · API · CLI · Contributing · Changelog

Every page is also readable as markdown under docs/.

Citation

If you use nefi, please cite the papers it implements:

@article{zhao2026netmy,
  title   = {Neural Fields for {NV}-Center Inverse Sensing},
  author  = {Zhao, Zhixuan and Zhong, Tao and Hu, Yixun and de Leon, Nathalie P. and
             Allen-Blanchette, Christine},
  journal = {arXiv preprint arXiv:2605.13988},
  year    = {2026}
}

@article{zhong2026nefty,
  title   = {Neural Field Thermal Tomography: A Differentiable Physics Framework for
             Non-Destructive Evaluation},
  author  = {Zhong, Tao and Hu, Yixun and Zheng, Dongzhe and Sood, Aditya and
             Allen-Blanchette, Christine},
  journal = {arXiv preprint arXiv:2603.11045},
  year    = {2026}
}

License

MIT © 2026 CAB Lab, Princeton University — see LICENSE.

Acknowledgements

nefi is developed and maintained by the CAB Lab at Princeton University. It generalizes the lab's NeTMY and NeFTY papers into one library, and we thank the authors of both papers.

Metadata

Release files for nefi 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nefi 0.1.0
File Size Uploaded
nefi-0.1.0.tar.gz 932.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nefi 0.1.0
File Interpreter ABI Platform
nefi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.8 MB

Release files / nefi-0.1.0.tar.gz

Download URL nefi-0.1.0.tar.gz
Size 932.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c5ec0976671d170861e00a2fe8aa229b040b9bb42053a67a4a3e393a5ca2c82d
BLAKE2b-256 checksum
How to use checksums
7b52478ae53dd8114e70e7c1dbba459e9cfb872a1d77f5303e24d67a7be24a33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / nefi-0.1.0-py3-none-any.whl

Download URL nefi-0.1.0-py3-none-any.whl
Size 916.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a20b8f41185aaf15db8b0333b31d07c7a7f40f1585fd28348dcbf52b61adb9b
BLAKE2b-256 checksum
How to use checksums
ecfb9eeac5ba03b534464334104eb97b7322bd81e07d183e9260c77b1c8adc53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page