Architecture
NextStat follows a "clean architecture" style: inference depends on stable abstractions, not on specific execution backends. The high-level logic (MLE, profile likelihood, hypothesis tests) is decoupled from the compute layer (SIMD, CUDA, Metal).
Layer Diagram
┌─────────────────────────────────────────────────────────────────┐
│ HIGH-LEVEL LOGIC │
│ ns-inference (MLE, Profile Likelihood, Hypothesis Tests, ...) │
│ - depends on core types and model interfaces │
└─────────────────────────┬──────────────────────────────────────┘
│ depends on abstractions
┌─────────────────────────┴──────────────────────────────────────┐
│ ns-core (interfaces) │
│ - error types, FitResult, traits │
└─────────────────────────┬──────────────────────────────────────┘
│ implemented by
┌─────────────────────────┴──────────────────────────────────────┐
│ LOW-LEVEL IMPLEMENTATIONS │
│ ns-translate ns-compute ns-ad ns-root │
│ (pyhf/ntuple) (SIMD/GPU) (AD) (ROOT I/O) │
└────────────────────────────────────────────────────────────────┘Crate Map
| Crate | Purpose |
|---|---|
| ns-core | Core types, traits, error handling |
| ns-compute | SIMD kernels, Apple Accelerate, CUDA/Metal batch NLL+grad |
| ns-ad | Automatic differentiation (dual numbers / tape) |
| ns-root | Native ROOT file reader (TH1, TTree, expressions, filler) |
| ns-translate | Format translators (pyhf JSON, HistFactory XML, ntuple builder) |
| ns-inference | MLE, NUTS, CLs, GLM, time series, PK/NLME |
| ns-viz | Visualization artifacts (Brazil bands, profile scans) |
| ns-cli | Command-line binary |
| ns-prob | Probability distributions |
Compute Backends
The ns-compute crate abstracts over multiple backends. The inference layer selects the best available backend at runtime:
- CPU (default) — SIMD auto-vectorization + Rayon thread pool
- Apple Accelerate — vDSP/vForce for vectorized math on macOS
- CUDA — NVIDIA GPU kernels for batch NLL + gradient (f64)
- Metal — Apple Silicon GPU shaders (f32)
Python Bindings
The ns-py crate (in bindings/ns-py/) exposes the Rust API to Python via PyO3. Built with maturin. The Python package name is nextstat.
