Skip to content

Add seed options for stochastic NLopt algorithms - #732

Open
timmens wants to merge 5 commits into
mainfrom
codex/nlopt-random-seed
Open

timmens wants to merge 5 commits into
mainfrom
codex/nlopt-random-seed

Conversation

@timmens

@timmens timmens commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

NLopt's ESCH, ISRES, CRS2-LM, PRAXIS, and randomized DIRECT algorithms use randomness but their optimagic wrappers do not expose a seed. This can make optimization results vary between runs and causes the ESCH binding-bounds test to fail intermittently.

Add an optional 32-bit seed to those wrappers and initialize NLopt's generator in the shared optimization function. The existing generic optimizer tests use a fixed seed when an algorithm exposes one. Document that NLopt shares random state between optimizer calls on the same thread on supported builds, including nested optimizations. Deterministic DIRECT variants leave the random state alone.

NLopt 2.10.1 selects deterministic unscaled DIRECT-L for all unscaled DIRECT variants, including the randomized one, so its seed cannot change the search. This upstream issue has been corrected on NLopt's development branch and is documented here.

Validation

  • Focused NLopt seed tests cover reproducible evaluations, seed bounds, external seeding, and deterministic DIRECT.
  • Existing NLopt optimizer integration tests pass with the shared fixed seed on macOS and Python 3.13.
  • pixi run -e type-checking ty and repository pre-commit checks pass.

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/optimagic/optimizers/nlopt_optimizers.py 96.79% <100.00%> (+1.59%) ⬆️
...ests/optimagic/optimizers/test_nlopt_optimizers.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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