Skip to content

feat: add optimistix optimizer - #2678

Open
pfackeldey wants to merge 15 commits into
scikit-hep:mainfrom
pfackeldey:add_optimistix_optimizer
Open

feat: add optimistix optimizer#2678
pfackeldey wants to merge 15 commits into
scikit-hep:mainfrom
pfackeldey:add_optimistix_optimizer

Conversation

@pfackeldey

@pfackeldey pfackeldey commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds optimistix as a new optimizer backend. Optimistix implements JAX-native solvers and supports differentiation through minimization via the implicit function theorem, moving pyhf a step closer to being fully differentiable out of the box.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR

* Add new `optimistix_optimizer` class wrapping `optx.minimise` 
  with DFP solver by default (maxiter=1000); fixed parameters are 
  represented as `None` pytree leaves so the minimizer skips
  gradient updates for them; returns a `scipy.optimize.OptimizeResult`
  including `optx_state`
* Add `optimistix` optional dependency in `pyproject.toml` constrained
  to `python_version >= '3.11'`; wire into `backends`, `all`, and `test`
  pixi environments
* Extend `tests/conftest.py` `backend` fixture to conditionally include
  a `jax_optimistix` parametrize entry when `optimistix` is importable, so 
  all existing parametrized tests exercise the new optimizer automatically
* Add targeted tests:`ValueError` on `solver=None`, `ValueError` when
  used with non-JAX backend, basic fit, fit with a fixed parameter, 
  and `return_result_obj` round-trip checking `optx_state` is present

Co-Authored-By: Giordon Stark <kratsg@gmail.com>

Summary by CodeRabbit

  • New Features
    • Added an Optimistix-based optimizer backend (Python 3.11+), including fixed-parameter handling and richer result metadata.
    • Added empty and arange array-creation utilities to tensor backends.
  • Bug Fixes
    • Improved optional backend import errors when Optimistix is unavailable.
  • Documentation
    • Expanded Sphinx cross-references to include Optimistix docs.
  • Tests
    • Added/updated coverage and a new test marker related to the JAX+Optimistix combination.
  • Chores
    • Updated optional dependency groups and tool configuration; improved local artifact ignore rules.

@pfackeldey pfackeldey changed the title Add optimistix optimizer feat: add optimistix optimizer Mar 27, 2026
Comment thread src/pyhf/optimize/opt_optimistix.py Outdated
Comment thread src/pyhf/optimize/opt_optimistix.py
@lukasheinrich

Copy link
Copy Markdown
Contributor

this looks ok to me.. just had minor comments..

@pfackeldey

Copy link
Copy Markdown
Contributor Author

Ok, now it seems like I have to skip the optimistix tests for py<3.11 test suites. Do you have a suggestion where to apply such skips? I also see there's a constraint.txt in tests/ but I'm not sure if this is somehow related?

Comment thread pyproject.toml Outdated
Comment thread src/pyhf/optimize/opt_optimistix.py
Comment thread tests/conftest.py Outdated
@github-project-automation github-project-automation Bot moved this to In progress in pyhf v0.8.0 Apr 2, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Review in progress in pyhf v0.8.0 Apr 2, 2026
@codecov

codecov Bot commented Apr 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.18519% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.03%. Comparing base (826a041) to head (5f7ae6f).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/pyhf/tensor/numpy_backend.py 22.22% 7 Missing ⚠️
src/pyhf/tensor/jax_backend.py 66.66% 3 Missing ⚠️
src/pyhf/optimize/opt_optimistix.py 96.22% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2678      +/-   ##
==========================================
- Coverage   98.28%   98.03%   -0.25%     
==========================================
  Files          65       66       +1     
  Lines        4305     4386      +81     
  Branches      465      469       +4     
==========================================
+ Hits         4231     4300      +69     
- Misses         46       57      +11     
- Partials       28       29       +1     
Flag Coverage Δ
contrib 97.92% <85.18%> (-0.24%) ⬇️
doctest 98.03% <85.18%> (-0.25%) ⬇️
unittests-3.10 94.91% <12.34%> (-1.56%) ⬇️
unittests-3.11 96.26% <85.18%> (-0.21%) ⬇️
unittests-3.12 96.26% <85.18%> (-0.21%) ⬇️
unittests-3.13 96.26% <85.18%> (-0.21%) ⬇️
unittests-3.9 94.98% <12.34%> (-1.56%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kratsg

kratsg commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

once tests are fixed and running, can go in.

@kratsg
kratsg force-pushed the add_optimistix_optimizer branch from 01dc9c0 to c4c5ade Compare April 11, 2026 05:56
pfackeldey and others added 8 commits April 10, 2026 23:22
- Add test_optimistix_no_solver, test_optimistix_wrong_backend,
  test_optimistix_minimize, test_optimistix_minimize_fixed_params,
  test_optimistix_return_result_obj to test_optim.py
- Add optimistix entry to test_missing_optimizer parametrize in test_init.py

Co-Authored-By: Giordon Stark <kratsg@gmail.com>
Co-Authored-By: Giordon Stark <kratsg@gmail.com>
@kratsg
kratsg force-pushed the add_optimistix_optimizer branch from 6bd2d92 to 51871d6 Compare April 11, 2026 06:22
optimistix requires Python >= 3.11, so it may never be imported and thus
absent from sys.modules on older Python versions. Use .get() for the hide
step and conditional restore for put-back to avoid KeyError.

Co-Authored-By: Giordon Stark <kratsg@gmail.com>
@kratsg

kratsg commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

@pfackeldey it looks like we're seeing significantly longer run times for some of the tests with optimistix. If you look at the public_api tests, the hypotest we run with jax_optimistix takes significantly longer -- any ideas why?

@pfackeldey

pfackeldey commented Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

@kratsg thanks for pushing this PR forward!! I didn't have the capacity last week to do so.

I need to check, maybe a recompilation+retracing issue? I'll investigate...

@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
@scikit-hep scikit-hep deleted a comment from coderabbitai Bot Apr 13, 2026
pfackeldey and others added 2 commits June 19, 2026 11:09
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@matthewfeickert

Copy link
Copy Markdown
Member

The failures are due to the new matplotlib release (v3.11.0). We'll fix this and then rebase this.

@pfackeldey

Copy link
Copy Markdown
Contributor Author

Once it's rebased the PR is ready from my side @matthewfeickert @kratsg :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review in progress

Development

Successfully merging this pull request may close these issues.

5 participants