Skip to content

Fix bound handling of nlopt_newuoa and nlopt_praxis and an error in nlopt_direct. - #740

Open
janosg wants to merge 16 commits into
mainfrom
fix-nlopt-bugs
Open

janosg wants to merge 16 commits into
mainfrom
fix-nlopt-bugs

Conversation

@janosg

@janosg janosg commented Nov 15, 2026

Copy link
Copy Markdown
Member

Stacked on #690.

  • nlopt_newuoa used the bounded variant LN_NEWUOA_BOUND only if both lower and upper bounds were given, so one-sided bounds were ignored.
  • nlopt_praxis was marked supports_bounds=False, but bounds were forwarded and NLopt enforces them via a variable transformation, also for one-sided bounds. It is now marked as supporting bounds, including infinite ones.
  • nlopt_direct with random_search=True, locally_biased=False raised an UnboundLocalError. It now raises a ValueError.

🤖 Generated with Claude Code

janosg and others added 14 commits July 5, 2026 17:13
… annotations.

With `from __future__ import annotations`, dataclass field types are
annotation strings rather than type objects, so the TYPE_CONVERTERS lookup
in Algorithm.__post_init__ never matched and option coercion/validation was
silently skipped for all optimizer modules using the import.

Adds a string-keyed TYPE_CONVERTERS_BY_NAME lookup so coercion works
identically with and without the import, plus regression tests: a dummy
algorithm defined under postponed annotations mirroring the existing type
conversion tests, and a registry-wide test that passes floats for all
int-typed options of every algorithm.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Brings in #696, which replaces the hand-written option converter table with
pydantic validation. PR #691, whose fix for the same problem was the first
commit on this branch, was closed in favor of #696, so its changes are dropped
here rather than merged:

- src/optimagic/type_conversion.py: deleted (superseded by validated_dataclass
  in optimagic/typing.py), including the TYPE_CONVERTERS_BY_NAME lookup #691
  added.
- Algorithm.__post_init__: removed, main validates via mark.minimizer instead.
- tests/.../test_algorithm_future_annotations.py: deleted. Its coverage of the
  postponed-annotations path is provided by main's
  test_algo_option_validation_stringified.py, and its registry-wide int
  coercion test by test_all_algorithms_can_be_instantiated_with_defaults.

Docs conflicts resolved by keeping this branch's docstrings on top of main's
widened annotations:

- Fides.hessian_update_strategy is now HessianUpdateStrategy, not a bare
  Literal, so its docstring no longer claims that HessianApproximation
  instances are unavailable; it explains that Broyden must be passed as an
  instance because phi has no default.
- PygmoMbh.inner_algorithm uses the PygmoAlgorithm alias.

Also documents the new constraint that field annotations must be resolvable at
runtime in how_to_document_optimizers.md, since pydantic now resolves them and
a TYPE_CHECKING-only name in a field type raises on instantiation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removes CLEANUP_NOTES.MD, CONSTRAINTS_REFACTOR_REVIEW.md and REPORT.md, which were
committed by accident, and fixes "libray" and "simple have a look" in
how_to_add_optimizers.ipynb.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every example in algorithms.md now passes params as a NumPy array, drops the `...`
placeholders and is self-contained, so each code block runs as is. Bounds are added
for all algorithms that need them, and least-squares and likelihood examples mark
their functions accordingly. This also fixes examples that used options that don't
exist (bayes_opt `n_iter`, pyswarms `topology_type` and `k_neighbors`), a syntax
error in the iminuit example, a shgo example that crashed without bounds, and a
nag_pybobyqa string-interface example whose option was silently dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since mark.minimizer re-creates algorithm classes as pydantic dataclasses that
inherit from the original class, autodoc treated all documented fields as inherited
and did not show them. Every autoclass directive in algorithms.md now uses
`:inherited-members: Algorithm, object`, as the gfo and pyswarms entries already did,
and the how-to guide explains why. The guide's quote of the ScipyLBFGSB docstring is
synced with the corrected docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sources.

Every class and field docstring was checked against the optimagic wrapper code
and the upstream sources (scipy 1.17.1, NLopt 2.10.1, pagmo2, Ipopt 3.14 /
cyipopt 1.6.1, DFO-LS 1.6.2, Py-BOBYQA 1.5.0, fides 0.7.4, tranquilo 0.1.1).
Wrong formulas, defaults, option semantics and references are corrected,
undocumented deviations from upstream defaults are stated, and where the wrapper
behaves unexpectedly the docstrings describe the actual behavior. The stale
module-level constant docstrings in nag_optimizers.py, which contradicted the
class docs, are removed. Typos in a few error and warning messages are fixed; no
logic changes. refs.bib gets corrected author fields and titles and a new entry
for the Ipopt negative curvature test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/source/how_to/how_to_add_optimizers.ipynb
# Conflicts:
#	docs/source/algorithms.md
#	src/optimagic/optimizers/nlopt_optimizers.py
…lopt_direct.

- nlopt_newuoa ignored one-sided bounds because the bounded variant was
  only used if both lower and upper bounds were present.
- nlopt_praxis was marked as not supporting bounds, although NLopt
  enforces them via a variable transformation and they were forwarded.
- nlopt_direct raised an UnboundLocalError with random_search=True and
  locally_biased=False. It now raises a ValueError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from standardize-algo-docs to main November 15, 2026 13:04
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/optimagic/algorithms.py 88.85% <100.00%> (+0.02%) ⬆️
src/optimagic/optimizers/nlopt_optimizers.py 97.83% <100.00%> (+0.26%) ⬆️
tests/estimagic/test_estimate_ml.py 99.45% <100.00%> (ø)
...ests/optimagic/optimizers/test_nlopt_optimizers.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

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

janosg and others added 2 commits November 16, 2026 08:26
Co-Authored-By: Claude <noreply@anthropic.com>
The fixture drew 10,000 samples without a seed, so the test failed on
rare unlucky draws (about 1 in 6,000) when a sample covariance missed
the true value by more than the 0.15 tolerance.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant