Trusty Neurocoder

Verified scientific surrogates via neuro-symbolic compilation and LLM agents.

Documentation: cmungall.github.io/nsam4hpc

What This Does

Takes a scientific simulation kernel (e.g., a Fortran soil decomposition subroutine), preserves the known physics as fixed program structure, makes uncertain parts learnable via neural networks, trains against data, and decompiles the learned weights back to interpretable math. Physical invariants (mass conservation, positivity) hold by construction.

Scientific source code (Fortran, C++, Python)
    ↓  LLM agent extracts kernel
Cajal program (typed functional language)
    ↓  compiler
PyTorch computation graph (differentiable)
    ↓  train against data
Learned neural weights
    ↓  symbolic regression
Interpretable mathematical expression + verified invariants

Results

Eight working demonstrations across DOE science domains:

ModelDomainLearnedResult
Exponential decayFoundationrate kk=0.3000 exact
Coupled poolsEarth sciencetransfer αα=0.4000 exact
Unknown functionEarth sciencemoisture responseHill equation recovered
CENTURY-LiteEarth sciencetemp + moistureboth forms recovered
Decay chainNuclearbranching ratios0.70, 0.85 exact
Battery fadeEnergy storageSEI growth lawparabolic law recovered
Chemical kineticsCombustionArrhenius rateA=2.01, E=4.99
EcoSIM decompEarth scienceT + water stressextracted from Fortran

Comparison: Cajal vs PINN vs Black-Box

On identical data (reversible reaction A⇌B):

Black-boxPINNCajal
Trajectory MSE6.2×10⁻³7.7×10⁻³9.3×10⁻⁷
Conservation error5.4×10⁻³6.5×10⁻³1.6×10⁻⁷
Extrapolation3.1×10⁻²5.0×10⁻²1.3×10⁻²
Sample efficiency (2 traj)8.6×10⁻²1.2×10⁻³
InterpretableNoNok=1.97·exp(-4.86/T)

Quick Start

git clone https://github.com/cmungall/trusty-neurocoder.git
cd trusty-neurocoder
uv pip install -e ".[dev,notebooks,docs]"

# Run examples
just examples

# Run notebooks
just notebooks

# Serve docs
just docs

Notebooks

Interactive Jupyter notebooks with embedded output and plots:

Cajal Type System

Built on Cajal (Velez-Ginorio, Amin, Kording, Zdancewic), a typed linear programming language whose programs compile exactly to recurrent neural networks. We extend the type system with TyReal(n) for real-valued state vectors and fix four soundness bugs in the vendored implementation.

References

  • Velez-Ginorio et al. "Compiling to Recurrent Neurons" (arXiv:2511.14953, 2025)
  • Velez-Ginorio et al. "Compiling to Linear Neurons" (POPL 2026)
  • Amin & Rompf. "Collapsing Towers of Interpreters" (POPL 2018)

License

BSD-3-Clause