Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement filtered autocomplete for algorithm selection #534

Merged
merged 34 commits into from
Nov 5, 2024
Merged

Conversation

janosg
Copy link
Member

@janosg janosg commented Sep 24, 2024

Short description

After this PR, algorithms can for example be selected as follows:

import optimagic as om
import numpy as np 
 
om.minimize(
    fun=lambda x: x @ x,
    params=np.arange(3),
    algorithm=om.algos.Bounded.scipy_lbfgsb,
)

After typing om.algos.Bounded, the autocomplete in any modern editor will only suggest algorithms that support bound constraints.

Categories that can be used to filter algorithms are:

  • GradientBased
  • GradientFree
  • Global
  • Local
  • Bounded
  • LinearConstrained
  • NonlinearConstrained
  • Scalar
  • LeastSquares
  • Likelihood
  • Parallel

Categories can be selected in any order. We make sure that mutually exclusive categories (e.g. Local and Global) cannot be selected at the same time.

Detailed description

The changes are described in EP-02: Static Typing

Deviations from the EP

  • The Unbounded and Unconstrained categories were removed because people rarely want to specifically choose an optimizer that does not support constraints or bounds.
  • om.algorithms was renamed to om.algos because it is still unambiguous and makes the code shorter, which hopefully improves adoption of using this instead of strings for algorithm selection.

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/optimagic/__init__.py 100.00% <100.00%> (+6.89%) ⬆️
src/optimagic/algorithms.py 85.58% <ø> (-14.42%) ⬇️
src/optimagic/config.py 70.96% <100.00%> (+0.47%) ⬆️

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@janosg janosg requested a review from timmens October 4, 2024 14:48
Copy link
Member

@timmens timmens left a comment

Choose a reason for hiding this comment

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

Looks very good already, only a few things that need updates.

This is a great step towards much better auto complete 🎉

.tools/create_algo_selection_code.py Outdated Show resolved Hide resolved
.tools/create_algo_selection_code.py Outdated Show resolved Hide resolved
.tools/create_algo_selection_code.py Outdated Show resolved Hide resolved
.tools/create_algo_selection_code.py Outdated Show resolved Hide resolved
.tools/create_and_format_algo_selection_code.sh Outdated Show resolved Hide resolved
tests/optimagic/test_create_algo_selection.py Outdated Show resolved Hide resolved
@janosg
Copy link
Member Author

janosg commented Oct 11, 2024

Tests are failing due to the release of DFO-LS 1.5.1; This is unrelated to the current changes and would affect all currently open PRs (@timmens, @mpetrosian).

@janosg janosg requested a review from timmens October 31, 2024 10:54
Copy link
Member

@timmens timmens left a comment

Choose a reason for hiding this comment

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

Looks very good! I only have two minor comments on the documentation.

@janosg janosg merged commit 181bab9 into main Nov 5, 2024
17 checks passed
@janosg janosg deleted the algo-selection branch November 5, 2024 18:30
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