Skip to content

Add conformal prediction notebooks - #185

Merged
victoraalves merged 5 commits into
cog-imperial:mainfrom
dovallev:conformal-prediction-notebooks
Jun 24, 2026
Merged

Add conformal prediction notebooks#185
victoraalves merged 5 commits into
cog-imperial:mainfrom
dovallev:conformal-prediction-notebooks

Conversation

@dovallev

@dovallev dovallev commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds five Jupyter notebooks demonstrating conformal prediction and Conformal Mixed-Integer Constraint Learning (C-MICL), for both regression and classification:

  • docs/notebooks/conformal/regression/01_conformal_tutorial.ipynb: split conformal prediction and adaptive (normalized) intervals on a heteroscedastic dataset
  • docs/notebooks/conformal/regression/02_uncertainty_integration.ipynb: embedding conformal predictive sets into a Pyomo/OMLT optimization model, following the C-MICL framework (Ovalle et al., NeurIPS 2026)
  • docs/notebooks/conformal/regression/03_feasibility_verification.ipynb: empirically illustrates the paper's ground-truth feasibility theorem by comparing standard MICL against C-MICL on a membrane reactor design problem, verified against a physics-based ODE oracle
  • docs/notebooks/conformal/classification/01_conformal_tutorial.ipynb: conformal prediction sets for classification on MNIST, contrasting the traditional softmax-based nonconformity score with a logit-based score that avoids extra nonlinearities when embedded into an optimization formulation
  • docs/notebooks/conformal/classification/02_uncertainty_integration.ipynb: embeds the logit-based conformal classifier into a Pyomo/OMLT MILP to find minimal-perturbation adversarial examples under both standard and uncertainty-aware (C-MICL) formulations

Also:

  • Moves heteroscedastic_data.csv and adds membrane_reactor_data.csv and mnist_classifier_500.pth to the shared docs/notebooks/data/ folder
  • Adds pytest entries for all five notebooks in tests/notebooks/test_run_notebooks.py
  • Adds citation for ovalle2026conformal to README.rst after the Zhang et al. entry
  • Adds ERA001/PLR0913 to the docs/notebooks/* ruff ignore list to accommodate illustrative commented-out code and the scipy.odeint calling convention

Test plan

  • All five notebooks execute end-to-end without errors (jupyter nbconvert --execute)
  • ruff check and ruff format --check pass on docs/notebooks/conformal/
  • typos passes on changed files
  • New pytest functions pass with a torch/keras-enabled environment

Legal Acknowledgement
By contributing to this software project, I agree my contributions are
submitted under the BSD license.
I represent I am authorized to make the contributions and grant the
license.
If my employer has rights to intellectual property that includes these
contributions,
I represent that I have received permission to make contributions and
grant the required license on behalf of that employer.

Adds two notebooks under docs/notebooks/conformal/regression/:
- 01_conformal_tutorial.ipynb: introduces split conformal prediction
  and adaptive (normalized) conformal intervals on a heteroscedastic
  regression dataset
- 02_uncertainty_integration.ipynb: embeds conformal predictive sets
  into a Pyomo/OMLT optimization model with finite-sample feasibility
  guarantees, following the C-MICL framework

Also:
- Moves heteroscedastic_data.csv into the shared docs/notebooks/data/ folder
- Adds notebook tests to test_run_notebooks.py
- Adds citation for ovalle2026conformal to README.rst
@dovallev

Copy link
Copy Markdown
Contributor Author

Tagging @victoraalves and @carldlaird for review when you get a chance.

dovallev added 3 commits May 12, 2026 20:49
…ification

Adds two new classification notebooks under docs/notebooks/conformal/classification/
(01_conformal_tutorial.ipynb, 02_uncertainty_integration.ipynb) mirroring the
existing regression series, and a third regression notebook
(03_feasibility_verification.ipynb) that empirically illustrates the paper's
ground-truth feasibility theorem by comparing standard MICL against C-MICL on
a membrane reactor design problem, verified against a physics-based ODE oracle.

Also fixes a stray typo in the regression uncertainty-integration notebook,
adds the MNIST classifier weights and membrane reactor dataset used by the
new notebooks, registers pytest coverage for all new notebooks, and adds
ERA001/PLR0913 to the docs/notebooks ruff ignore list to accommodate
illustrative commented-out code and the scipy.odeint calling convention.
Fixes the two ruff violations that previously required new per-file-ignore
entries in pyproject.toml, instead of changing shared project config:

- classification/01_conformal_tutorial.ipynb: removes the two illustrative
  commented-out retrain/save lines (ERA001) and updates the surrounding
  markdown to describe how to retrain without leaving dead code in the cell.
- regression/03_feasibility_verification.ipynb: refactors
  membrane_reactor_odes to take a single packed parameter tuple instead of
  five separate scalar arguments (PLR0913), matching scipy.odeint's calling
  convention without exceeding ruff's argument-count limit.

Both notebooks re-executed end-to-end with identical results, and
pyproject.toml is now byte-for-byte unchanged from main.
@victoraalves victoraalves self-assigned this Jun 22, 2026
@victoraalves
victoraalves self-requested a review June 22, 2026 19:12

@victoraalves victoraalves left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just needs some cleanup regarding a few warnings from PyTorch/CUDA.

Addresses review feedback that the notebooks emit noisy warnings on import
and during training/solving:

- regression/01, regression/02, regression/03: TensorFlow/CUDA emits a
  plugin-registration banner (cuDNN/cuBLAS/cuFFT "already registered",
  computation placer warnings) at C++ static-initializer time, which
  predates any Python-level log-level setting. Silenced by redirecting the
  OS-level stderr file descriptor around the Keras import, plus a one-time
  throwaway fit() inside that same suppressed block to pre-trigger Keras's
  lazy CUDA-device probe (which otherwise re-emits the same banner on the
  first real fit/predict call in a later cell).
- classification/02_uncertainty_integration.ipynb: importing from
  omlt.io.onnx transitively imports omlt's Keras reader (since Keras is
  installed), triggering the same banner even though this notebook never
  uses Keras directly. Wrapped the OMLT import in the same suppression
  helper. Also scoped a DeprecationWarning filter around the single
  torch.onnx.export call: the legacy TorchScript exporter (dynamo=False) is
  kept intentionally, since the newer torch.export-based exporter does not
  yet support dynamic_axes cleanly.
- regression/03_feasibility_verification.ipynb: also silences a benign
  Pyomo W1002 warning, logged every time OMLT's Big-M formulation
  initializes surrogate variables to 0 before the solver assigns real
  values (the computed bounds never include 0, so this is expected).

All 5 notebooks re-executed end-to-end with identical results to before,
and pyproject.toml remains untouched (no shared lint config changes).
@victoraalves
victoraalves merged commit 7e698a7 into cog-imperial:main Jun 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants