Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a6ac962
Support pandas 3 and Python 3.13 to 3.15.
janosg Nov 23, 2026
01b7e5b
Test each optimizer library in its own environment and CI job.
janosg Nov 23, 2026
a81b0a0
Merge branch 'main' into pandas3-python-versions
janosg Nov 23, 2026
8c41ebf
Fix tao_pounders for petsc4py 3.26 and the bootstrap tutorial for pan…
janosg Nov 23, 2026
ebd0eee
Leave the Python version out of the names of single-version CI jobs.
janosg Nov 23, 2026
03524aa
Make library markers the only way to declare optimizer dependencies a…
janosg Nov 23, 2026
556dd68
Relax the precision of the nevergrad test without bounds.
janosg Nov 23, 2026
51746c5
Run the algo selection hook on Python 3.14 and install uv for it.
janosg Nov 24, 2026
385dd54
Return the best evaluated point of nevergrad optimizers and make stop…
janosg Nov 24, 2026
7607ef3
Explain why NoisyBandit is expected to fail in the nevergrad tests.
janosg Nov 24, 2026
f00f331
Save coverage reports of test jobs even if a test fails.
janosg Nov 24, 2026
79c6f56
Add tools for wrapper options and wrapper tests
janosg Nov 18, 2026
6cb4d12
Modernize the fides wrapper and add a fides tutorial
janosg Nov 18, 2026
bd55dbe
Modernize the nag_dfols and nag_pybobyqa wrappers
janosg Nov 18, 2026
4611c3c
Document the wrapper standards and add the wrap-optimizer skill
janosg Nov 18, 2026
6a1d5d2
Use a deprecated_options decorator and pass option groups as instances
janosg Nov 18, 2026
b0d59cc
Combine switches and their option groups and report more result fields
janosg Nov 18, 2026
f62d355
Test that stopping_maxfun in algo_options reaches the NAG solvers
janosg Nov 18, 2026
83f909e
Run the wrapper tests for every pull request in a dedicated job
janosg Nov 19, 2026
349ef68
Search open issues when updating an existing wrapper in the wrap-opti…
janosg Nov 24, 2026
e08b9fd
Adapt option groups to the lazily built validators of #747
janosg Nov 24, 2026
6bf73a3
Use the library markers of #749 for the wrapper tests
janosg Nov 24, 2026
343c573
Start the seek_global_optimum test where the local search gets stuck.
janosg Nov 24, 2026
e90ac57
Merge branch 'main' into worktree-modernize-nag-fides-wrappers
janosg Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions .claude/skills/wrap-optimizer/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
---
name: wrap-optimizer
description: Add an optimizer wrapper to optimagic or bring an existing wrapper up to the wrapper standards.
disable-model-invocation: true
---

Wrap an optimizer for optimagic, or bring an existing wrapper up to standard. Both
branches run the same steps; a paragraph marked **New** or **Existing** applies to
one branch only.

The rules are in two docs pages. Each step names the sections to read before you do
it:

- `docs/source/how_to/how_to_add_optimizers.md`, part "Standards for wrappers"
- `docs/source/how_to/how_to_document_optimizers.md`

Reference implementations: `src/optimagic/optimizers/fides.py` with
`tests/optimagic/optimizers/test_fides_wrappers.py` (flat options, objects from the
library, a changed default) and `nag_optimizers.py` with `test_nag_wrappers.py` (option
groups, converted deprecations).

The spine of the work is the **option table**: one row per option of the library.
Every step after the audit is checked against its rows.

## 1. Audit the library

Work against the newest release. **New:** add the dependency as described in
"Integrate the wrapper into optimagic". **Existing:** raise the minimal version in
`pyproject.toml` to the newest release, run `pixi install`, and read the changelog
between the old and the new minimal version.

Read the papers and the documentation, then establish every fact from the installed
source: documentation goes stale. For each option, follow it from the entry point to
the lines that use it and note its default, the range and type it accepts, and its
effect. Note also whether the library treats an absent option differently from one
passed as `None`, whether a default depends on the problem, and whether a flag makes
other options ineffective while it is off. Where the source leaves a doubt, run the
library directly on a small problem and look.

List what the library returns and which fields of `InternalOptimizeResult` it can
fill, directly or with a counter in the wrapper.

**Existing:** also list every defect of the current wrapper: options that are never
passed, passed under a wrong key, typed so that they cannot be used, results read
from the wrong field. Check whether `replace_and_warn_about_deprecated_algo_options`
in `src/optimagic/deprecations.py` renames an option of this wrapper before it
arrives. Search the open issues for the wrapper, its algorithms and the library (for
example `gh issue list --state open --search "<library>"`, then once per algorithm
name), and add every problem they report to the list of defects.

Done when every argument of the library's entry point, every key of its option
dictionaries and every attribute of its configuration objects has a row, for each
row you can name the function in the library's source where the option takes effect,
and every field of `InternalOptimizeResult` is marked as filled or as impossible to
fill with the reason.

## 2. Draft the option table

Read "The option table", "Which options to expose", "Keep the library's grouping",
"Names of options" and "Defaults".

Fill every column of every row, and list the options that are not exposed with their
reasons. A flag together with the options it switches on becomes one row group for an
option of the form `bool | <group>`.

A default that deviates from the library needs **evidence**, and so does adopting a
library default that the current wrapper deviates from. See
[Evidence for defaults](#evidence-for-defaults). The harmonized stopping and
convergence options are the exception: they take the optimagic values, and the
evidence to collect is which criterion ends the runs.

Done when every row has a name, a group, a default, the name it replaces and a planned
test, and every default that differs from the library's has a benchmark result or
"harmonized" next to it.

## 3. Checkpoint: the option table

Present to the user, in plain language with examples from this library:

- the option table and the list of options that are not exposed,
- the fields of the result the wrapper will fill and those it cannot,
- the defaults that deviate or change, with the evidence,
- **Existing:** the defects found, the open issues and which of them this work
closes, and the deprecations the table implies,
- whether a tutorial is due (section "Tutorials"),
- every open question as a recommendation with its alternative.

Stop here. Continue once the user has approved the table, with their corrections
applied to it.

## 4. Implement

Read "Keep the library's grouping", "The result" and "Changing an existing wrapper".

Put the tables that tests and wrapper share into the wrapper module as public
constants: library name to optimagic name, options that are not exposed with reasons,
defaults that deviate with reasons. Build the call to the library from the first
table.

**Existing:** declare every renamed, moved or converted option as a `DeprecatedOption`
and every changed default with `resolve_changed_default`. Announce removals and new
defaults for the minor release after the one that ships the change (see `CHANGES.md`
and the latest git tag for the current version).

Done when every row of the approved table is in the code under its approved name and
default, every defect from the audit is fixed, the result has every field the audit
marked as filled, and
`pixi run tests tests/optimagic/optimization/test_many_algorithms.py -k <algorithm>`
passes.

## 5. Test

Read "Tests".

Probe before you assert: run the tiny problem with two values of the option and write
the assertion for the effect you observed. An option that shows no effect in the probe
is a finding. Go back to the library's source and find out when the option matters.
Put that into its docstring, or, if the option cannot have an effect inside
optimagic, move it to the options that are not exposed and tell the user.

Let forwarding tests run the real solver with a tiny budget behind the spy. They then
also show that the library accepts the value. Let the contract test read the
library's defaults in every context they depend on (noisy or not, few or many
parameters): it then verifies each "depends on the problem" claim of the table.

Done when

- every row has the test planned for it, and every deprecated name and changed default
has a deprecation test,
- `pixi run tests tests/optimagic/optimizers/test_<library>_wrappers.py` passes in
under a minute,
- deleting one entry from the name table makes a contract test fail (try it, then
restore the entry),
- `pixi run -e tests-<library> tests --library <library>` passes; it fails if a test
of the library is skipped.

## 6. Document

Read `how_to_document_optimizers.md`.

Done when every option and every attribute of an option group has a docstring with the
three parts of the template, the class docstring lists the unsupported features with
reasons, `pixi run -e docs build-docs` passes, and you have read the rendered entry of
the algorithm from top to bottom.

## 7. Tutorial

Only if a tutorial is due. Read "Tutorials".

Find each example by experiment first: a section stays only if running it shows the
effect it claims. Generate the numbers in the notebook instead of writing them into
the text.

Done when the notebook runs from top to bottom without warnings in under a minute and
is linked from `docs/source/tutorials/index.md` and from the class docstring.

## 8. Finish

- Register the marker and the library as described in "Integrate the wrapper into
optimagic". Add the entry to `CHANGES.md`.
- Run `pixi run tests` if you changed code outside the wrapper module, otherwise
`pixi run tests-fast`; then `pixi run -e type-checking ty` and
`prek run --all-files`.
- Draft an issue for every unsupported feature that a reasonable extension of
optimagic could support.
- Draft the pull request description: what changed for users, the issues it closes,
the final option table,
the evidence for defaults, and the AI-use note the contributor guide asks for
(`docs/source/development/how_to_contribute.md`, "Using AI tools").

Done when all checks pass and the user has the drafts of the pull request and the
issues to review before anything is published.

## Evidence for defaults

Compare the candidate values on `om.get_benchmark_problems("more_wild")`, with bounds
added if the option only matters with bounds. Keep everything else at the planned
defaults. Report for each candidate:

- the share of problems on which it comes within 1e-4 of the best value any candidate
found, relative to the improvement over the start value,
- the median number of function evaluations it needs to get there,
- the computation time per iteration, if the option changes the work inside the
optimizer,
- for convergence options: which criterion ends the runs and on how many problems a
run stops short of the best value.

The library default stands unless the numbers show that another value is better. Put
the numbers into the checkpoint and later into the pull request description.
45 changes: 45 additions & 0 deletions .github/workflows/wrapper-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# Tests of the wrapped optimizer libraries against their newest release, to detect
# upstream changes. They run once a month and can be started by hand. For every pull
# request, the main workflow runs the same tests with the library versions in the lock
# file.
permissions:
contents: read
name: wrapper-tests
on:
schedule:
- cron: 0 5 1 * *
workflow_dispatch: null
jobs:
run-wrapper-tests:
name: Run ${{ matrix.library }} tests with the newest release
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Libraries that have wrapper tests, with their packages. Add a library when
# you add its wrapper tests.
include:
- library: fides
packages: fides
- library: nag
packages: dfo-ls py-bobyqa
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: prefix-dev/setup-pixi@9936258fee697aff89b3fed6ca1f80a382ef694e # v0.11.3
with:
pixi-version: v0.71.2
cache: true
cache-write: false
frozen: true
environments: tests-${{ matrix.library }}
- name: Update the wrapped library to its newest release
shell: bash -el {0}
run: pixi update -e tests-${{ matrix.library }} ${{ matrix.packages }}
- name: Run pytest
shell: bash -el {0}
run: >-
pixi run -e tests-${{ matrix.library }} tests
--library ${{ matrix.library }}
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ Consult the relevant sections of the documentation for your task:
- Contribution workflow: [contributor guide](docs/source/development/how_to_contribute.md).
- Code changes: [style guide](docs/source/development/styleguide.md).
- Typing and public interfaces: [EP-02](docs/source/development/ep-02-typing.md).
- Optimizer wrappers (adding or changing one):
[how to add optimizers](docs/source/how_to/how_to_add_optimizers.md). The
user-invoked `wrap-optimizer` skill runs the full workflow.
- GitHub activity: read the contributor guide's AI-use section and\
follow its guidance before publishing.
32 changes: 32 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ This release adds experimental support for **SciPy-style callbacks**, replaces p
validators of algorithm options are built when an algorithm is instantiated for the
first time and the classes behind `om.algos` are no longer dataclasses. The minimum
supported version of pydantic is now 2.10 ({ghuser}`janosg`).
- {gh}`746` Modernizes the `fides` wrapper, which now requires `fides>=0.8.2`. Options
are renamed to stay closer to fides (`hessian_update`, `subspace_solver`,
`stepback_strategy`, `max_stepback_fraction`, `stopping_maxtime`) and to follow a new
convention for trust-region options (`trustregion_shrinking_threshold`,
`trustregion_expansion_threshold`, `trustregion_shrinking_factor`,
`trustregion_expansion_factor`). The old names are deprecated and will be removed in
0.7.0. `stepback_strategy="refine"` is new. For problems with bounds, the default of
`stepback_strategy` will change from `"truncate"` to `"reflect"` in 0.7.0. A new
tutorial shows how to use the advanced options of fides ({ghuser}`janosg`).
- {gh}`746` Modernizes `nag_dfols` and `nag_pybobyqa`, which now require
`DFO-LS>=1.6.5` and `Py-BOBYQA>=1.5.0`. Options that belong together are bundled in
option groups that mirror the solvers (`init_options`, `trustregion_options`,
`slow_progress_options`, `interpolation_options`, `regression_options`,
`growing_options`). Restarts are switched on with `restarts=True` or configured with
an instance of the restart options, noisy functions are declared with `noisy=True`
or with an instance of `NagNoiseOptions`, and all options of the solvers that
optimagic can serve are available. The old option names are deprecated and will be
removed in 0.7.0 ({ghuser}`janosg`).
- {gh}`746` Fixes several bugs in `nag_dfols` and `nag_pybobyqa`: `n_evals_per_point`
(formerly `noise_n_evals_per_point`) could not be used, `n_fun_evals` counted points
instead of evaluations or was missing, `stopping_maxfun` was ignored by
`nag_pybobyqa`, `n_iterations` was one too low and some options were never passed
to the solvers. Options the solvers reject now raise an `InvalidAlgoOptionError`.
`fides` now reports `status`, `n_fun_evals` and `n_jac_evals` ({ghuser}`janosg`).
- {gh}`746` Adds tools for the options of algorithm wrappers: the
`mark.deprecated_options` decorator keeps old option names working with a
`FutureWarning`, and related options can be bundled in validated option groups,
which are passed as instances of their class. Adds detailed wrapper tests, which
run in the CI jobs of the libraries for every pull request and once a month against
the newest releases of the wrapped libraries. The guides on adding and
documenting optimizers describe the new standards for wrappers, and a
`wrap-optimizer` skill guides coding agents through them ({ghuser}`janosg`).
- {gh}`739` Fixes `tao_pounders` ignoring `convergence_gtol_abs`,
`convergence_gtol_rel` and `convergence_gtol_scaled`. Reaching `stopping_maxiter` is
now reported as unsuccessful with the message "maxits reached" instead of as
Expand Down
Loading
Loading