Metadata-Version: 2.5
Name: vibe-check-ml
Version: 0.1.0
Summary: Reliability checks for machine-learning surrogates in scientific software.
Project-URL: Homepage, https://github.com/imalsky/vibe-check
Project-URL: Repository, https://github.com/imalsky/vibe-check
Project-URL: Issues, https://github.com/imalsky/vibe-check/issues
Project-URL: Changelog, https://github.com/imalsky/vibe-check/blob/main/CHANGELOG.md
Author-email: Isaac Malsky <isaacmalsky@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Isaac Malsky
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: emulator,machine-learning,neural-operator,reliability,reproducibility,scientific-computing,surrogate,validation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.1; extra == 'dev'
Requires-Dist: pytest>=7.4; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Provides-Extra: viz
Requires-Dist: matplotlib>=3.7; extra == 'viz'
Description-Content-Type: text/markdown

# vibe-check

Reliability checks for machine-learning surrogates in scientific software.

A surrogate (an emulator, neural operator, or learned solver component) is
usually judged by its average test error. That number can hide problems: the
model may be extrapolating outside its training data, the preprocessing may
have leaked test data, or the outputs may break a physical constraint.
vibe-check takes a `predict` function (or saved predictions) and your data
splits, runs twelve checks, and writes a report that someone who did not
train the model can read.

This work is supported by the US Research Software Sustainability Institute
(URSSI) via grant G-2022-19347 from the Sloan Foundation.

## Install

The package is not on PyPI yet. Clone the repository and install it in place:

```
git clone https://github.com/imalsky/vibe-check.git
cd vibe-check
pip install -e ".[viz]"
```

The core needs only numpy. The `viz` extra adds matplotlib for report figures.
The distribution is named `vibe-check-ml`; the module you import is `vibecheck`.

## Example

`examples/quickstart.py` is the smallest complete run: a linear least-squares
surrogate for 1-D diffusion. It maps an initial field on a 64-point periodic
grid to the field the heat equation produces at a later time, with observation
noise on the targets. The solution operator of the heat equation is a matrix,
so least squares is a fair surrogate for it. The script needs numpy and
matplotlib.

The check itself is one call. `predict` is the fitted surrogate, and the
metadata names the input scaler the model used, a throughput budget, and the
fact that the 64 outputs are a 1-D field:

```python
report = vc.check(
    predict,
    X_train=u0_train, y_train=ut_train,
    X_test=u0_test, y_test=ut_test,
    metadata={
        "normalization": {"mean": u0_train.mean(0), "std": u0_train.std(0)},
        "speed": {"min_throughput": 1e4},
        "error_field": {"is_field": True},  # the 64 output values are a 1-D field
        "make_figures": True,
    },
)
print(report)
report.to_markdown("report.md")
report.to_html("report.html")
report.to_json("report.json")
```

The script prints one line per check (SKIP means the check did not get the
inputs it needs, and the line names them) and an overall status that says
how many checks ran. It writes `report.md`, `report.html`, and
`report.json`, and draws the figure below. On the left, one test field
diffuses from `u(x, 0)` to `u(x, T)` and the surrogate lies over it. On the
right, predicted against true across the whole test set.

![One test field before and after diffusion with the surrogate over it, and predicted against true test values](docs/figures/quickstart.png)

## What it checks

| check | what it detects |
|---|---|
| `leakage.normalization` | input or target scaler statistics fit on test or full data instead of train only |
| `leakage.split_overlap` | duplicate or near-duplicate rows across train, validation, and test |
| `distribution.coverage` | test inputs outside the training domain, with a coverage map |
| `distribution.drift` | drift between the train, validation, and test marginals |
| `error.pointwise` | RMSE and skill per output channel, predicted vs true, residuals |
| `error.field` | true, predicted, and percent-error maps for spatial fields, and error by wavenumber band |
| `error.by_input` | where in input space the error concentrates: the worst quantile bin against the rest |
| `calibration.coverage` | stated uncertainty vs observed coverage of 1, 2, and 3 sigma intervals, and the tails beyond 3 sigma |
| `constraints.physical` | conservation, positivity, monotonicity, symmetry, bounds |
| `model.determinism` | outputs that change between calls or with the batch size: dropout or batch-norm left in training mode |
| `export.roundtrip` | whether an exported model reproduces the in-memory one |
| `speed.inference` | batch throughput and single-input latency against a stated budget |

## Worked examples

Four small trained surrogates with committed reports, one per common shape
of scientific ML model:

- `examples/robertson`: Robertson stiff chemical kinetics, a state-to-state
  MLP ([report](examples/robertson/report.md)).
- `examples/lorenz`: the Lorenz system, an MLP that predicts the next several
  states ([report](examples/lorenz/report.md)).
- `examples/fno_burgers`: a Fourier neural operator on 1-D Burgers, a
  spatial-field model ([report](examples/fno_burgers/report.md)).
- `examples/darcy_2d`: a 2-D Fourier neural operator on Darcy flow, a
  2-D field model with a positivity constraint
  ([report](examples/darcy_2d/report.md)).

`examples/README.md` says how to run them. The Darcy report's worst test
sample, as `error.field` draws it: the true pressure field, the predicted
field on the same colour scale, and the percent error.

<p>
<img src="docs/figures/darcy_true.png" width="32%" alt="True pressure field of the worst Darcy test sample">
<img src="docs/figures/darcy_predicted.png" width="32%" alt="Predicted pressure field of the same sample, on the same colour scale">
<img src="docs/figures/darcy_error.png" width="32%" alt="Percent error of the prediction for the same sample">
</p>

## Documentation

- [`docs/TUTORIAL.md`](docs/TUTORIAL.md): from a trained model to a report,
  how to turn on more checks, and how to gate CI.
- [`docs/RECIPES.md`](docs/RECIPES.md): wrapping PyTorch, JAX, scikit-learn,
  and ONNX models as `predict`, field-shaped arrays, and running from saved
  predictions.
- [`docs/VALIDATION_CONTRACT.md`](docs/VALIDATION_CONTRACT.md): the interface
  every check follows and the `metadata` keys each one reads.
- [`docs/CASE_STUDY_normalization_leakage.md`](docs/CASE_STUDY_normalization_leakage.md):
  how a scaler fit on the full dataset inflates test accuracy, with a runnable
  demo.
- [`docs/RELEASING.md`](docs/RELEASING.md): the release checklist.

## Related tools

[deepchecks](https://github.com/deepchecks/deepchecks) and
[Evidently](https://github.com/evidentlyai/evidently) test tabular data and
models in pandas. [uncertainty-toolbox](https://github.com/uncertainty-toolbox/uncertainty-toolbox)
scores predictive uncertainty and [MAPIE](https://github.com/scikit-learn-contrib/MAPIE)
builds conformal intervals. [PDEBench](https://github.com/pdebench/PDEBench)
and [The Well](https://github.com/PolymathicAI/the_well) benchmark PDE
surrogates on their own datasets, and
[diagnostics_for_physics](https://github.com/lennonshikhman/diagnostics_for_physics)
audits the physical structure of learned PDE time-steppers. None of them
takes a bare `predict` function with numpy splits and reports leakage,
coverage, calibration, constraints, export, and speed together; that is
the gap vibe-check fills.

## Status

Version 0.1.0 is prepared but not yet tagged or published. The public API may
change before 1.0. See `CHANGELOG.md`.

## License

MIT. See `LICENSE`.
