SpectraFit-Core
High-performance numerical curve fitting — a Rust kernel with analytical Jacobians, Pydantic-typed schemas, and a self-auditing benchmark that audits its own credibility against independent oracles (lmfit, JAX, scipy) and NIST StRD certified values.
Status: beta (
0.1.2). APIs and the benchmark contract may still change before the stable 1.0 release. See LIMITATIONS.md for disclosed gaps.
Documentation: https://anselmoo.github.io/SpectraFit-Core/ — start with Installation and Quickstart.
What is this?
SpectraFit-Core fits spectroscopic and general nonlinear models with a Rust Levenberg–Marquardt / trust-region core, exposed to Python through a PyO3 wheel and a Pydantic schema mirror. Its distinguishing feature is a trustworthy benchmark: rather than asking you to take its speed/accuracy claims on faith, it ships a dashboard that verifies its own numbers (independent parity oracle, timing-isolation guards, render-truth provenance, NIST StRD validation) and visibly discloses what it has not verified.
Installation
pip install spectrafit-core # or: uv add spectrafit-core
To build from source (Rust toolchain + maturin required):
git clone https://github.com/Anselmoo/SpectraFit-Core.git
cd SpectraFit-Core
uv sync --extra benchmark # dev tooling is a dependency-group, installed by default
uv run maturin develop
In a source checkout, uv run pytest runs the full test suite.
Quick start
Fit a single Gaussian peak to synthetic data, using only the public
spectrafit_core API (verified to run — see
Quickstart
for the full walkthrough):
import numpy as np
from spectrafit_core import MeasurementData, compose, fit, gaussian
# Synthetic "measured" data: a Gaussian peak plus a little noise.
x = np.linspace(-5, 5, 200)
y = 3.0 * np.exp(-0.5 * ((x - 0.5) / 1.2) ** 2) + np.random.default_rng(0).normal(
0, 0.05, x.size
)
# Build the model graph: one Gaussian node with initial guesses.
graph = compose([gaussian("peak1", amplitude=1.0, center=0.0, sigma=1.0)]).build()
# Run the fit.
result = fit(graph, MeasurementData(x=x.tolist(), y=y.tolist()))
print(result.parameters) # fitted amplitude/center/sigma, keyed "peak1.<param>"
print(result.r_squared) # goodness of fit
This is deterministic (seeded RNG) and recovers the true amplitude/center/sigma
(3.0, 0.5, 1.2) to within about one standard error, with r_squared ≈ 0.998:
{'peak1.sigma': ParameterResult(value=1.2024163241228947, ..., stderr=0.004211511681961483),
'peak1.center': ParameterResult(value=0.49756589193680784, ..., stderr=0.004211469158787863),
'peak1.amplitude': ParameterResult(value=2.997594452290324, ..., stderr=0.00909249987508253)}
0.9979075074894731
The block above is reformatted for readability:
Benchmark
The benchmark (python/oracles/) fits the same problems with spectrafit
(the Rust kernel under test) and five reference backends: lmfit,
jax/optimistix and three scipy.optimize.least_squares methods (lm,
trf, dogbox).
- Cases: a deterministic catalogue defined in
python/oracles/cases.py(CATEGORY_REGISTRY: easy, complex, scaling, lineshapes, reality, edge, optfn, fixed, tied). Every case can be opened on its own in the report. - Showcases: a 3-D fit with the native
gaussian_ndkernel and a joint multi-spectrum fit withGlobalFitGraph(shared centres and widths, per-spectrum amplitudes). - Data flow: benchmark run →
results.json(theBenchReportcontract) → FastAPI → the React app inweb/.poe report_htmlbundles the same report into one offline file. - Report: Standing shows what was measured, without a verdict; Evidence shows every backend on every case, side by side.
uv run poe benchmark # full run → results.json + manifest.json
uv run poe benchmark_quick # lean reps, fast local iteration
uv run poe serve # serve the latest report over FastAPI (http://localhost:8000)
uv run poe benchmark_gate # spectrafit-vs-lmfit regression gate on the latest run
# or the CLI directly
PYTHONPATH=python uv run python -m oracles.cli run --reps 10 --mc 30
PYTHONPATH=python uv run python -m oracles.cli gate
Each run writes its own folder:
.spectrafit_reports/<category>/<YYYY-MM-DD>_run_NNN/
results.json # the BenchReport contract payload (served by the FastAPI app)
manifest.json # run metadata + headline stats (geomean speedup, max |Δr²|, win-rate)
.spectrafit_reports/index.json # all runs, newest first
The latest run resolves via oracles.reports.latest_results(category).
Regression gate
benchmark_gate (and CI) always checks three axes — spectrafit must not
become slower than lmfit overall (geomean speedup < 1×), must not
break accuracy parity (max |Δr²| > 1e-3 on the LM-family cases; the
multimodal optfn/global category is excluded since two stochastic global
optimizers legitimately reach different optima), and must not regress any
backend's convergence. Up to four more axes are appended only when their
backing evidence exists (self-perf, model-selection, σ-calibration, speed
inference) — the gate is never a fixed axis count. See
Why SpectraFit-Core, "A benchmark that
verifies itself" section, for the full axis-by-axis description.
Web report
uv run poe serve # serve the latest report over FastAPI (in another shell)
cd web && npm install
npm run dev # dev server; proxies /api → http://localhost:8000 (the FastAPI app)
npm run build # production build → dist/ (fetches /api/report at runtime)
npm run test # vitest: render all views from fixtures, no browser/API (alias: npm run smoke)
npm run contract # regenerate src/openapi.gen.ts from the live /openapi.json
Self-contained HTML — one command builds the extension, runs the benchmark, and bundles a
single, deployable report.html (all JS/CSS inlined, the report inlined as window.__BENCH__)
that opens offline with no server:
uv run poe report_html # → .spectrafit_reports/benchmark/<run>/report.html (one file, tens of MB;
# size scales with the backend roster and case catalog)
The Python contract (oracles.bench_contract) is the single source of truth.
The FastAPI app publishes it as OpenAPI, and npm run contract generates the
TypeScript types from that schema, so engine and UI cannot drift apart.
Adding a model or case
The benchmark is registry-driven (see Extending SpectraFit-Core):
register one PeakModel in oracles.models, reference its key from a
CaseSpec/CaseFamily in oracles.cases. After a contract change, regenerate
the TS types from the live OpenAPI schema: uv run poe serve then
cd web && npm run contract.
Contributing
Contributions of any size are welcome — issues and pull requests here; see CONTRIBUTING.md for development setup, conventions, and the PR process. SpectraFit-Core is also developed on the MPCDF GitLab; changes from both places are kept in sync automatically.
Citing
If you use SpectraFit-Core in academic work, please cite it via
CITATION.cff (GitHub's "Cite this repository" button reads it).
Every release is archived on Zenodo; the concept DOI
10.5281/zenodo.23043544 always
resolves to the latest version.
License
MIT © Anselm Hahn. See also CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
Metadata
Release files for spectrafit-core 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spectrafit_core-0.1.2.tar.gz | 314.9 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| spectrafit_core-0.1.2-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details |
| spectrafit_core-0.1.2-cp314-cp314-manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.28+ x86-64 | Details |
| spectrafit_core-0.1.2-cp314-cp314-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.14 | CPython 3.14 | macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64 | Details |
| spectrafit_core-0.1.2-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details |
| spectrafit_core-0.1.2-cp313-cp313-manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64 | Details |
| spectrafit_core-0.1.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.13 | CPython 3.13 | macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 | Details |
Total release size: 11.0 MB
Release files / spectrafit_core-0.1.2.tar.gz
| Download URL | spectrafit_core-0.1.2.tar.gz |
|---|---|
| Size | 314.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d79c616e0392e220829269736f60b61264cb90375afbcad6df4197d9f4c1dfe6
|
|
BLAKE2b-256 checksum How to use checksums |
3e69ee9ccbfe68297ed380c2d047c590b73b3aace97db35bebd1396cc89657c7
|
| 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 Oct 5, 2026.
Transparency logRelease files / spectrafit_core-0.1.2-cp314-cp314-win_amd64.whl
| Download URL | spectrafit_core-0.1.2-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3c98b101c6000ae24f500c423b10d80eefb172c737bda4ba906f714570b3ec37
|
|
BLAKE2b-256 checksum How to use checksums |
5b685f2dbfe5f8c0f9879c464124291aca38cc1014bc62edf6a5d507704b32b2
|
| 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 Oct 5, 2026.
Transparency logRelease files / spectrafit_core-0.1.2-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | spectrafit_core-0.1.2-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
ad849bbf3202bf266f6cdab224c5d1129dbbb73f4851c8a7c3c746465c83e0cc
|
|
BLAKE2b-256 checksum How to use checksums |
0add6877240281141ff01b7dab936066d1dde75adbdefe85d723a4321efb34fb
|
| 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 Oct 5, 2026.
Transparency logRelease files / spectrafit_core-0.1.2-cp314-cp314-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | spectrafit_core-0.1.2-cp314-cp314-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 2.3 MB |
| Tags | CPython 3.14 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a6a8590a322a1264323aa5323a8a8de0c724a8bcc0c34a6f8e91dbb84b841e3e
|
|
BLAKE2b-256 checksum How to use checksums |
338d62f064cd38bee17ab49453e79e2576ec543c1eea80edfc1113b174bd5255
|
| 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 Oct 5, 2026.
Transparency logRelease files / spectrafit_core-0.1.2-cp313-cp313-win_amd64.whl
| Download URL | spectrafit_core-0.1.2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
65a746180fa7d1e048811785ce496d0a47d3bae26f89d3906c9a9df7ca448ab8
|
|
BLAKE2b-256 checksum How to use checksums |
a85dc91931e4199d66a846ecab82df21c23018e520e2ed54332f01c845df66bf
|
| 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 Oct 5, 2026.
Transparency logRelease files / spectrafit_core-0.1.2-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | spectrafit_core-0.1.2-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
6d00dc553a2f17fd126d0db2e9822a6387e593114765983dac719b28027704ac
|
|
BLAKE2b-256 checksum How to use checksums |
938a5db6e44a196d8cef1d182cb9b36104210a601756cc7cc380310cc444434b
|
| 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 Oct 5, 2026.
Transparency logRelease files / spectrafit_core-0.1.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | spectrafit_core-0.1.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 2.3 MB |
| Tags | CPython 3.13 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0138036dd57e5dd8334b65cba164a72997e4590cd743871a3b11dd6e358d1fa2
|
|
BLAKE2b-256 checksum How to use checksums |
2935912a7816aca90b4b8fb0806ae10ae21abdf1707c990a2d2b568eea6f62f7
|
| 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 Oct 5, 2026.
Transparency log