NextStatNextStat

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

CratePurpose
ns-coreCore types, traits, error handling
ns-computeSIMD kernels, Apple Accelerate, CUDA/Metal batch NLL+grad
ns-adAutomatic differentiation (dual numbers / tape)
ns-rootNative ROOT file reader (TH1, TTree, expressions, filler)
ns-translateFormat translators (pyhf JSON, HistFactory XML, ntuple builder)
ns-inferenceMLE, NUTS, CLs, GLM, time series, PK/NLME
ns-vizVisualization artifacts (Brazil bands, profile scans)
ns-cliCommand-line binary
ns-probProbability 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.