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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ jobs:
run: >-
pixi run -e tests-linux-py314
python -m doctest -v docs/source/how_to/how_to_constraints.md
run-mypy:
name: Run mypy
run-ty:
name: Run ty
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
Expand All @@ -145,6 +145,6 @@ jobs:
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: type-checking
- name: Run mypy
- name: Run ty
shell: bash -el {0}
run: pixi run -e type-checking mypy
run: pixi run -e type-checking ty --output-format github
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
--wheel
--outdir dist/
- name: Upload distribution artifacts
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist
path: dist
Expand Down
32 changes: 16 additions & 16 deletions .tools/create_algo_selection_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,62 +104,62 @@ def _get_all_algorithms(modules: list[ModuleType]) -> dict[str, Type[Algorithm]]
def _get_algorithms_in_module(module: ModuleType) -> dict[str, Type[Algorithm]]:
"""Collect all algorithms in a single module."""
candidate_dict = dict(inspect.getmembers(module, inspect.isclass))
candidate_dict = {
k: v for k, v in candidate_dict.items() if hasattr(v, "__algo_info__")
}
algos = {}
for candidate in candidate_dict.values():
name = candidate.algo_info.name
if issubclass(candidate, Algorithm) and candidate is not Algorithm:
algos[name] = candidate
if (
issubclass(candidate, Algorithm)
and candidate is not Algorithm
and candidate.__algo_info__ is not None
):
algos[candidate.__algo_info__.name] = candidate
return algos


# ======================================================================================
# Functions to filter algorithms by selectors
# ======================================================================================
def _is_gradient_based(algo: Type[Algorithm]) -> bool:
return algo.algo_info.needs_jac # type: ignore
return algo.algo_info.needs_jac


def _is_gradient_free(algo: Type[Algorithm]) -> bool:
return not _is_gradient_based(algo)


def _is_global(algo: Type[Algorithm]) -> bool:
return algo.algo_info.is_global # type: ignore
return algo.algo_info.is_global


def _is_local(algo: Type[Algorithm]) -> bool:
return not _is_global(algo)


def _is_bounded(algo: Type[Algorithm]) -> bool:
return algo.algo_info.supports_bounds # type: ignore
return algo.algo_info.supports_bounds


def _is_linear_constrained(algo: Type[Algorithm]) -> bool:
return algo.algo_info.supports_linear_constraints # type: ignore
return algo.algo_info.supports_linear_constraints


def _is_nonlinear_constrained(algo: Type[Algorithm]) -> bool:
return algo.algo_info.supports_nonlinear_constraints # type: ignore
return algo.algo_info.supports_nonlinear_constraints


def _is_scalar(algo: Type[Algorithm]) -> bool:
return algo.algo_info.solver_type == AggregationLevel.SCALAR # type: ignore
return algo.algo_info.solver_type == AggregationLevel.SCALAR


def _is_least_squares(algo: Type[Algorithm]) -> bool:
return algo.algo_info.solver_type == AggregationLevel.LEAST_SQUARES # type: ignore
return algo.algo_info.solver_type == AggregationLevel.LEAST_SQUARES


def _is_likelihood(algo: Type[Algorithm]) -> bool:
return algo.algo_info.solver_type == AggregationLevel.LIKELIHOOD # type: ignore
return algo.algo_info.solver_type == AggregationLevel.LIKELIHOOD


def _is_parallel(algo: Type[Algorithm]) -> bool:
return algo.algo_info.supports_parallelism # type: ignore
return algo.algo_info.supports_parallelism


def _get_filters() -> dict[str, Callable[[Type[Algorithm]], bool]]:
Expand Down Expand Up @@ -385,7 +385,7 @@ def _all(self) -> list[Type[Algorithm]]:
def _available(self) -> list[Type[Algorithm]]:
_all = self._all()
return [
a for a in _all if a.algo_info.is_available # type: ignore
a for a in _all if a.algo_info.is_available
]

@property
Expand Down
10 changes: 5 additions & 5 deletions .tools/update_algo_selection_hook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
import importlib.util
import subprocess
import sys
from pathlib import Path
Expand All @@ -15,13 +14,14 @@ def run(cmd: list[str], **kwargs: Any) -> None:
subprocess.check_call(cmd, cwd=ROOT, **kwargs)


def ensure_optimagic_is_locally_installed() -> None:
if importlib.util.find_spec("optimagic") is None:
run(["uv", "pip", "install", "--python", sys.executable, "-e", "."])
def install_optimagic_locally() -> None:
# Always (re)install so that dependencies added after the hook environment was
# created are picked up. This is fast if nothing changed.
run(["uv", "pip", "install", "--quiet", "--python", sys.executable, "-e", "."])


def main() -> int:
ensure_optimagic_is_locally_installed()
install_optimagic_locally()
run(PYTHON + [".tools/create_algo_selection_code.py"])

ruff_args = [
Expand Down
7 changes: 7 additions & 0 deletions docs/source/development/ep-02-typing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,13 @@ access to currently internal objects such as the MSM objective function.

We choose mypy as static type checker and run it as part of our continuous integration.

```{note}
We have since replaced mypy by [ty](https://docs.astral.sh/ty/). ty is much faster and
also checks the bodies of unannotated functions and our tests. Its configuration lives
in the `[tool.ty]` section of `pyproject.toml`. The mypy settings below are kept for
reference.
```

Once this enhancement proposal is fully implemented, we want to use the following
settings:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/development/how_to_contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi
use:

```console
$ pixi run mypy
$ pixi run ty
```

To see all available pixi tasks, run:
Expand Down
Loading
Loading