Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
117 changes: 83 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ on:
branches:
- '*'
jobs:
# Job names are required status checks on main. Jobs that run with one Python
# version leave it out of their name, so that a version update does not change them.
run-tests-linux:
name: Run tests on ubuntu-latest py${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- '312'
- '313'
- '314'
- '315'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -37,24 +39,40 @@ jobs:
- name: Run pytest
shell: bash -el {0}
run: pixi run -e tests-linux-py${{ matrix.python-version }} tests-with-cov
- name: Upload coverage report.
if: matrix.python-version == '312'
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
# Save the coverage report even if a test fails. Otherwise codecov reports the
# code that only this job tests as uncovered, on top of the failing test.
- name: Save coverage report
if: ${{ !cancelled() && matrix.python-version == '313' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
run-tests-win-and-mac:
name: Run tests on ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
name: coverage-main
path: coverage.xml
retention-days: 7
# Each optimizer library is tested in its own environment, so libraries never have
# to be installable together. `--library <library>` selects the tests of the
# library, including tests that loop over all installed algorithms. It fails if an
# algorithm of the library is not available or if a selected test is skipped (see
# tests/conftest.py).
run-optimizer-library-tests:
name: Run ${{ matrix.library }} tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- windows-latest
python-version:
- '312'
- '313'
- '314'
library:
- bayesopt
- fides
- gfo
- iminuit
- ipopt
- nag
- nevergrad
- nlopt
- pygad
- pygmo
- pyswarms
- tao
- tranquilo
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -65,13 +83,53 @@ jobs:
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-py${{ matrix.python-version }}
environments: tests-${{ matrix.library }}
- name: Run pytest
shell: bash -el {0}
run: pixi run -e tests-py${{ matrix.python-version }} tests-fast
run-tests-with-old-plotly:
name: Run tests on ubuntu-latest with plotly < 6
run: >-
pixi run -e tests-${{ matrix.library }} tests-with-cov
--library ${{ matrix.library }}
# Save the coverage report even if a test fails. Otherwise codecov reports the
# code that only this job tests as uncovered, on top of the failing test.
- name: Save coverage report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage-${{ matrix.library }}
path: coverage.xml
retention-days: 7
upload-coverage:
name: Upload combined coverage report
needs:
- run-tests-linux
- run-optimizer-library-tests
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# yamllint disable-line rule:line-length
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: coverage-*
path: coverage-reports
- name: Upload coverage reports in one upload
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage-reports
run-tests-win-and-mac:
name: Run tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- windows-latest
python-version:
- '314'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -82,20 +140,13 @@ jobs:
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-old-plotly
environments: tests-py${{ matrix.python-version }}
- name: Run pytest
shell: bash -el {0}
run: pixi run -e tests-old-plotly tests-fast
run-tests-nevergrad:
name: Run nevergrad tests py${{ matrix.python-version }}
run: pixi run -e tests-py${{ matrix.python-version }} tests-fast
run-tests-with-old-pandas:
name: Run tests on ubuntu-latest with pandas < 3
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- '312'
- '313'
- '314'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -106,12 +157,10 @@ jobs:
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-nevergrad-py${{ matrix.python-version }}
environments: tests-old-pandas
- name: Run pytest
shell: bash -el {0}
run: >-
pixi run -e tests-nevergrad-py${{ matrix.python-version }}
pytest tests/optimagic/optimizers/test_nevergrad.py
run: pixi run -e tests-old-pandas tests-fast
code-in-docs:
name: Run code snippets in documentation
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python 3.12
- name: Set up Python 3.13
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.12'
python-version: '3.13'
- name: Install pypa/build
run: >-
python -m
Expand Down
10 changes: 7 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ repos:
name: update algo selection code
entry: python .tools/update_algo_selection_hook.py
language: python
# optimagic requires Python >= 3.12; without the pin the hook venv is built
# with whatever Python prek finds first and the editable install fails.
language_version: '3.12'
# The hook installs optimagic, which needs a recent Python; without the pin the
# hook venv is built with whatever Python prek finds first and the install can
# fail.
language_version: '3.14'
files: ^(src/optimagic/optimizers/|src/optimagic/algorithms\.py|\.tools/)
require_serial: true
additional_dependencies:
- hatchling
- ruff
# The hook script runs uv; installing it here keeps commits working when
# uv is not on PATH.
- uv
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ releases are available on [Anaconda.org](https://anaconda.org/optimagic-dev/opti
This release adds experimental support for **SciPy-style callbacks**, replaces pybaum by
**optree** for pytree handling and uses **pydantic** to validate algorithm options.

- {gh}`749` Supports pandas 3 and Python 3.15 and drops Python 3.12. Following
[SPEC 0](https://scientific-python.org/specs/spec-0000/), the minimum supported
versions are now Python 3.13, numpy 2.2, scipy 1.15, pandas 2.3 and plotly 6.0. Fixes
`traceback_report(return_type="dataframe")` and the LaTeX output of
`estimation_table` with confidence intervals under pandas 3. `pygad` no longer
ignores `stopping_maxiter`: it runs the smaller of `num_generations` and
`stopping_maxiter` generations. `nevergrad_bo` is now available if bayes-optim is
installed; before, optimagic did not detect bayes-optim. The nevergrad optimizers
return the best evaluated point if nevergrad's recommendation is worse. Before,
`nevergrad_cmaes` could return a much worse point than it had found, because nevergrad
restarts CMA-ES whenever one of its stopping criteria is met and only recommends the
best point of the last restart. `stopping_maxtime` of `nevergrad_cmaes` now ends the
optimization instead of restarting CMA-ES ({ghuser}`janosg`).
- {gh}`747` Reduces the time it takes to import optimagic from about 2 seconds to about
0.6 seconds. Dependencies that are only needed for some features (scipy, numba,
sqlalchemy, plotly.express and joblib) are imported when they are used, the
Expand Down
21 changes: 20 additions & 1 deletion docs/source/development/how_to_contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,26 @@ $ pixi run tests tests/optimagic/optimization/test_optimize.py

Include relevant slow tests before opening a PR. For broader checks, use
`pixi run tests-fast`; it excludes slow and JAX tests on every platform. For changes to
shared code used across multiple modules, run the full suite with `pixi run tests`.
shared code used across multiple modules, run the full suite with `pixi run tests`. The
tasks run the tests in parallel on all CPU cores; add `-n 0` to run them in one process,
e.g. to debug with `--pdb`.

Each optimizer library has its own test environment, named after the library's pytest
marker. For example, the nlopt tests run with:

```console
$ pixi run -e tests-nlopt tests --library nlopt
```

`--library nlopt` also selects the nlopt algorithms in tests that loop over all
installed algorithms. It fails if an nlopt algorithm is not available or if one of the
selected tests is skipped. The default environment contains all optimizer libraries that
can be installed together, so `pixi run tests` covers most of them at once.

To declare that a test needs an optimizer library, give it the library's marker, e.g.
`pytestmark = pytest.mark.nlopt` for a whole module. Tests that are parametrized with an
algorithm get the marker of its library automatically. Tests with a library marker are
skipped if the library is not installed, so they need no `skipif`.

For changes affecting typing, run:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/estimagic/tutorials/bootstrap_overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"source": [
"df = sns.load_dataset(\"exercise\", index_col=0)\n",
"replacements = {\"1 min\": 1, \"15 min\": 15, \"30 min\": 30}\n",
"df = df.replace({\"time\": replacements})\n",
"df[\"time\"] = df[\"time\"].astype(str).map(replacements)\n",
"df[\"constant\"] = 1\n",
"\n",
"df.head()"
Expand Down
Loading
Loading