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
224 changes: 72 additions & 152 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
name: main
# Automatically cancel a previous run.
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand All @@ -13,39 +12,34 @@ on:
- '*'
jobs:
run-tests-linux:
name: Run tests for ${{ matrix.os }} on ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
name: Run tests on ubuntu-latest py${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- '312'
- '313'
- '314'
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/setup-pixi@v0.9.4
with:
environment-file: ./.tools/envs/testenv-linux.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pytest --cov-report=xml --cov=./
pixi-version: v0.65.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-linux-py${{ matrix.python-version }}
- 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: runner.os == 'Linux' && matrix.python-version == '3.10'
if: matrix.python-version == '312'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
run-tests-win-and-mac:
name: Run tests for ${{ matrix.os }} on ${{ matrix.python-version }}
name: Run tests on ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -54,163 +48,89 @@ jobs:
- macos-latest
- windows-latest
python-version:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: 1.5.6-0
environment-file: ./.tools/envs/testenv-others.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pytest -m "not slow and not jax"
run-tests-with-old-pandas:
# This job is only for testing if optimagic works with pandas<2, as many pandas
# functions we use will be deprecated in pandas 3. optimagic's behavior for older
# verions is handled in src/optimagic/compat.py. For compatibility with we have to
# restrict numpy<2.
name: Run tests for ${{ matrix.os}} on ${{ matrix.python-version }} with pandas 1
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- '3.10'
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ./.tools/envs/testenv-pandas.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pytest -m "not slow and not jax"
run-tests-with-old-numpy:
# This job is only for testing if optimagic works with numpy<2. Because we already
# test pandas<2 with numpy<2, in this environment we restrict pandas>=2.
name: Run tests for ${{ matrix.os}} on ${{ matrix.python-version }} with numpy 1
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- '3.10'
- '312'
- '313'
- '314'
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/setup-pixi@v0.9.4
with:
environment-file: ./.tools/envs/testenv-numpy.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pytest -m "not slow and not jax"
pixi-version: v0.65.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-py${{ matrix.python-version }}
- 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 for ubuntu-latest on 3.10 with plotly < 6 and kaleido < 0.3
name: Run tests on ubuntu-latest with plotly < 6
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/setup-pixi@v0.9.4
with:
environment-file: ./.tools/envs/testenv-plotly.yml
cache-environment: true
create-args: |
python=3.10
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pytest -m "not slow and not jax"
pixi-version: v0.65.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-old-plotly
- name: Run pytest
shell: bash -el {0}
run: pixi run -e tests-old-plotly tests-fast
run-tests-nevergrad:
# This job is for running test related to nevergrad with pinned version of
# bayesian_optimization == 1.4.0
name: Run tests for ubuntu-latest on ${{ matrix.python-version }} bayes_opt==1.4.0
runs-on: ${{ matrix.os }}
name: Run nevergrad tests py${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- '312'
- '313'
- '314'
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/setup-pixi@v0.9.4
with:
environment-file: ./.tools/envs/testenv-nevergrad.yml
cache-environment: true
create-args: |
python=${{ matrix.python-version }}
- name: run pytest
shell: bash -l {0}
run: |
micromamba activate optimagic
pixi-version: v0.65.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-nevergrad-py${{ matrix.python-version }}
- name: Run pytest
shell: bash -el {0}
run: >-
pixi run -e tests-nevergrad-py${{ matrix.python-version }}
pytest tests/optimagic/optimizers/test_nevergrad.py
code-in-docs:
name: Run code snippets in documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/setup-pixi@v0.9.4
with:
environment-file: ./.tools/envs/testenv-linux.yml
environment-name: optimagic
cache-environment: true
create-args: |
python=3.12
- name: run sphinx
shell: bash -l {0}
run: |-
micromamba activate optimagic
cd docs/source
python -m doctest -v how_to/how_to_constraints.md
pixi-version: v0.65.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: tests-linux-py314
- name: Run doctest
shell: bash -el {0}
run: >-
pixi run -e tests-linux-py314
python -m doctest -v docs/source/how_to/how_to_constraints.md
run-mypy:
name: Run mypy
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: create build environment
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/setup-pixi@v0.9.4
with:
environment-file: ./.tools/envs/testenv-linux.yml
environment-name: optimagic
cache-environment: true
create-args: |
python=3.10
pixi-version: v0.65.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: type-checking
- name: Run mypy
shell: bash -l {0}
run: |-
micromamba activate optimagic
mypy
shell: bash -el {0}
run: pixi run -e type-checking mypy
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'
- name: Install pypa/build
run: >-
python -m
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ venv/
ENV/
env.bak/
venv.bak/
.pixi/

# Spyder project settings
.spyderproject
Expand Down
12 changes: 2 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,10 @@ repos:
hooks:
- id: yamlfix
exclude: tests/optimagic/optimizers/_pounders/fixtures
- repo: local
hooks:
- id: update-environment-files
name: check environment file updates
entry: python .tools/update_envs.py
language: python
always_run: true
require_serial: true
- repo: local
hooks:
- id: check-mypy-versions
name: verify that pre-commits and dev env use the same mypy version
name: verify that pre-commits and pixi use the same mypy version
entry: python .tools/check_mypy_versions.py
language: python
always_run: true
Expand All @@ -44,7 +36,7 @@ repos:
hooks:
- id: check-added-large-files
args:
- --maxkb=1300
- --maxkb=2500
exclude: tests/optimagic/optimizers/_pounders/fixtures/
- id: check-case-conflict
- id: check-merge-conflict
Expand Down
19 changes: 11 additions & 8 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
version: 2
build:
os: ubuntu-22.04
os: ubuntu-24.04
tools:
python: mambaforge-4.10
conda:
environment: docs/rtd_environment.yml
sphinx:
builder: html
configuration: docs/source/conf.py
fail_on_warning: false
python: '3.14'
jobs:
create_environment:
- asdf plugin add pixi
- asdf install pixi latest
- asdf global pixi latest
post_build:
- pixi run -e docs build-docs
- mkdir --parents $READTHEDOCS_OUTPUT/html/
- cp -a docs/build/html/. "$READTHEDOCS_OUTPUT/html" && rm -r docs/build
17 changes: 8 additions & 9 deletions .tools/check_mypy_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ def _get_mypy_version_from_precommit_config() -> str:
for hook in config["repos"]
if hook["repo"] == "https://github.com/pre-commit/mirrors-mypy"
][0]
match = re.search(r"v([\d.]+)", mypy_config["rev"]) # Remove "v" prefix
match = re.search(r"v([\d.]+)", mypy_config["rev"])
if match:
return match.group(1)
raise ValueError("Mypy version not found in pre-commit config.")


def _get_mypy_version_from_conda_environment() -> str:
config = yaml.safe_load(Path("environment.yml").read_text())
mypy_line = [dep for dep in config["dependencies"] if "mypy" in dep][0]
match = re.search(r"mypy=([\d.]+)", mypy_line)
def _get_mypy_version_from_pixi() -> str:
text = Path("pyproject.toml").read_text()
match = re.search(r'mypy\s*=\s*"==([\d.]+)"', text)
if match:
return match.group(1)
raise ValueError("Mypy version not found in conda environment.")
raise ValueError("Mypy version not found in pyproject.toml pixi config.")


def main() -> None:
v_precommit = _get_mypy_version_from_precommit_config()
v_conda = _get_mypy_version_from_conda_environment()
if v_precommit != v_conda:
v_pixi = _get_mypy_version_from_pixi()
if v_precommit != v_pixi:
print(
f"Error: Mypy versions do not match:\n"
f" Pre-commit config: {v_precommit}\n"
f" Conda environment: {v_conda}\n"
f" Pixi config: {v_pixi}\n"
)
sys.exit(1)
sys.exit(0)
Expand Down
Loading
Loading