diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ea6cc9885..3aca1adf8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,16 +10,6 @@ repos: hooks: - id: yamlfix exclude: tests/optimagic/optimizers/_pounders/fixtures - - repo: local - hooks: - - id: check-mypy-versions - name: verify that pre-commits and pixi use the same mypy version - entry: python .tools/check_mypy_versions.py - language: python - always_run: true - require_serial: true - additional_dependencies: - - pyyaml - repo: local hooks: - id: update-algo-selection-code @@ -68,20 +58,8 @@ repos: hooks: - id: yamllint exclude: tests/optimagic/optimizers/_pounders/fixtures - - repo: https://github.com/PyCQA/docformatter - rev: v1.7.7 - hooks: - - id: docformatter - args: - - --in-place - - --wrap-summaries - - '88' - - --wrap-descriptions - - '88' - - --blank - exclude: src/optimagic/optimization/algo_options.py - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.4 + rev: v0.15.5 hooks: # Run the linter. - id: ruff @@ -132,26 +110,7 @@ repos: )$ args: - --drop-empty-cells - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.19.1 - hooks: - - id: mypy - files: src|tests - additional_dependencies: - - numpy >= 2 - - packaging - - pandas-stubs - - sqlalchemy-stubs - - types-cffi - - types-openpyxl - - types-jinja2 - - bokeh ci: autoupdate_schedule: monthly skip: - update-algo-selection-code - # Skip mypy stubtest on pre-commit.ci due to maximum size limitations. This is - # unlikely to get better in the future as dependencies keep growing. Local runs - # of pre-commit would still execute stubtest. For CI, we have a separate GitHub - # Action that runs stubtest. - - mypy diff --git a/.tools/check_mypy_versions.py b/.tools/check_mypy_versions.py deleted file mode 100644 index 51f1b6993..000000000 --- a/.tools/check_mypy_versions.py +++ /dev/null @@ -1,43 +0,0 @@ -import re -import sys -from pathlib import Path - -import yaml - - -def _get_mypy_version_from_precommit_config() -> str: - config = yaml.safe_load(Path(".pre-commit-config.yaml").read_text()) - mypy_config = [ - hook - 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"]) - if match: - return match.group(1) - raise ValueError("Mypy version not found in pre-commit config.") - - -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 pyproject.toml pixi config.") - - -def main() -> None: - v_precommit = _get_mypy_version_from_precommit_config() - 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" Pixi config: {v_pixi}\n" - ) - sys.exit(1) - sys.exit(0) - - -if __name__ == "__main__": - main() diff --git a/.tools/update_algo_selection_hook.py b/.tools/update_algo_selection_hook.py index 6c17cfe99..91715414d 100644 --- a/.tools/update_algo_selection_hook.py +++ b/.tools/update_algo_selection_hook.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import importlib.util import subprocess import sys from pathlib import Path @@ -8,8 +9,6 @@ # sys.executable guarantees we stay inside the pre‑commit venv PYTHON = [sys.executable] -# "-m" lets us call std‑lib modules (e.g. pip) the same way -PYTHON_MINUS_M = [*PYTHON, "-m"] def run(cmd: list[str], **kwargs: Any) -> None: @@ -17,10 +16,8 @@ def run(cmd: list[str], **kwargs: Any) -> None: def ensure_optimagic_is_locally_installed() -> None: - try: - run(PYTHON_MINUS_M + ["pip", "show", "optimagic"], stdout=subprocess.DEVNULL) - except subprocess.CalledProcessError: - run(PYTHON_MINUS_M + ["pip", "install", "-e", "."]) + if importlib.util.find_spec("optimagic") is None: + run(["uv", "pip", "install", "--python", sys.executable, "-e", "."]) def main() -> int: diff --git a/docs/source/development/how_to_contribute.md b/docs/source/development/how_to_contribute.md index 46c68c2b7..91f07dd07 100644 --- a/docs/source/development/how_to_contribute.md +++ b/docs/source/development/how_to_contribute.md @@ -44,14 +44,14 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi local optimagic repository: ```console - $ pre-commit install + $ prek install ``` This activates pre-commit hooks for linting and style formatting. ```{note} - `pre-commit` is not managed by pixi and must be installed globally. We recommend - installing it globally using pixi or uv. + `prek` is not managed by pixi and must be installed globally. You can find + installation instructions at [github.com/j178/prek](https://github.com/j178/prek). ``` You can then run the test suite with: @@ -60,8 +60,14 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi $ pixi run tests ``` - which installs the development dependencies and runs pytest. To see all available - pixi tasks, run: + which installs the development dependencies and runs pytest. To run the type checker, + use: + + ```console + $ pixi run mypy + ``` + + To see all available pixi tasks, run: ```console $ pixi task list @@ -84,8 +90,8 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi You can also run the test suite locally for [debugging](https://effective-programming-practices.vercel.app/debugging/pdbp/objectives_materials.html). - With pre-commit installed, linters run before each commit. Commits are rejected if - any checks fail. Note that some linters may automatically fix errors by modifying the + With prek installed, linters run before each commit. Commits are rejected if any + checks fail. Note that some linters may automatically fix errors by modifying the code in-place. Remember to re-stage the files after such modifications. ```{tip} @@ -103,9 +109,9 @@ Skip the next paragraph if you haven't worked on the documentation. `docs/build/html/index.html` or any other file. Similar to the online documentation, you can navigate to different pages simply by clicking on the links. -1. Once all tests and pre-commit hooks pass locally, push your changes to your forked - repository and create a pull request through GitHub: Go to the Github repository of - your fork. A banner on your fork's GitHub repository will prompt you to open a PR. +1. Once all tests and hooks pass locally, push your changes to your forked repository + and create a pull request through GitHub: Go to the Github repository of your fork. A + banner on your fork's GitHub repository will prompt you to open a PR. ```{note} Regular contributors with push access can directly push their local branch to the remote optimagic repository and initiate a PR from there. diff --git a/docs/source/development/styleguide.md b/docs/source/development/styleguide.md index e8cfc8dfb..b4847e6d1 100644 --- a/docs/source/development/styleguide.md +++ b/docs/source/development/styleguide.md @@ -105,9 +105,9 @@ Your contribution should fulfill the criteria provided below. refactoring, it is sufficient if the function that calls it is tested. But all functions that are exposed to the user must have unit tests. -- Enable pre-commit hooks by executing `pre-commit install` in a terminal in the root of - the optimagic repository. This makes sure that your formatting is consistent with what - we expect. +- Enable pre-commit hooks by executing `prek install` in a terminal in the root of the + optimagic repository. This makes sure that your formatting is consistent with what we + expect. - Use `pathlib` for all file paths operations. : You can find the pathlib documentation [here](https://docs.python.org/3/library/pathlib.html) diff --git a/docs/source/estimagic/explanation/bootstrap_montecarlo_comparison.ipynb b/docs/source/estimagic/explanation/bootstrap_montecarlo_comparison.ipynb index 7cd6f36b2..faad2116c 100644 --- a/docs/source/estimagic/explanation/bootstrap_montecarlo_comparison.ipynb +++ b/docs/source/estimagic/explanation/bootstrap_montecarlo_comparison.ipynb @@ -71,7 +71,6 @@ " Returns:\n", " pd.DataFrame: Clustered dataset.\n", " \"\"\"\n", - "\n", " x_cluster = np.random.normal(size=nclusters)\n", " x_ind = np.random.normal(size=nobs_per_cluster * nclusters)\n", " eps_cluster = np.random.normal(size=nclusters, scale=0.5)\n", @@ -179,7 +178,6 @@ " Returns:\n", " pd.DataFrame: DataFrame of average rejection rates.\n", " \"\"\"\n", - "\n", " np.zeros(nsim)\n", "\n", " np.zeros(nsim)\n", diff --git a/pixi.lock b/pixi.lock index b26dc69b3..4f9960725 100644 --- a/pixi.lock +++ b/pixi.lock @@ -256,6 +256,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py314h2e6c369_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py314hf07bd8e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -549,6 +550,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py314haad56a0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py314hfc1f868_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -826,6 +828,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py314h9f07db2_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py314h221f224_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -1169,6 +1172,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/roman-numerals-4.1.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py314h2e6c369_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py314hf07bd8e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -1499,6 +1503,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/roman-numerals-4.1.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py314haad56a0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py314hfc1f868_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -1813,6 +1818,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/roman-numerals-4.1.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py314h9f07db2_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py314h221f224_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -2203,6 +2209,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py312h868fb18_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scalapack-2.2.0-h606478a_6.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py312h54fa4ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda @@ -2593,6 +2600,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py313h843e2db_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scalapack-2.2.0-h606478a_6.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py313h4b8bb8b_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda @@ -2982,6 +2990,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py314h2e6c369_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scalapack-2.2.0-h606478a_6.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py314hf07bd8e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda @@ -3327,6 +3336,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py312h868fb18_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py312h54fa4ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -3621,6 +3631,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py312h6ef9ec0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py312h0f234b1_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -3898,6 +3909,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py312hdabe01f_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py312h9b3c559_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -4226,6 +4238,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py313h843e2db_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py313h4b8bb8b_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -4520,6 +4533,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py313h2c089d5_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py313hc753a45_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -4797,6 +4811,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py313hfbe8231_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py313he51e9a2_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -5124,6 +5139,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py314h2e6c369_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py314hf07bd8e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -5419,6 +5435,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py314haad56a0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py314hfc1f868_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -5697,6 +5714,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py314h9f07db2_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py314h221f224_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -6026,6 +6044,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py312h868fb18_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py312h54fa4ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -6314,6 +6333,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py312h6ef9ec0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py312h0f234b1_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -6585,6 +6605,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py312hdabe01f_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py312h9b3c559_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -6906,6 +6927,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py312h868fb18_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py312h54fa4ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -7198,6 +7220,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py312h6ef9ec0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py312h0f234b1_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -7473,6 +7496,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py312hdabe01f_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py312h9b3c559_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -7799,6 +7823,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py313h843e2db_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py313h4b8bb8b_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -8091,6 +8116,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py313h2c089d5_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py313hc753a45_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -8366,6 +8392,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py313hfbe8231_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py313he51e9a2_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -8692,6 +8719,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py314h2e6c369_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py314hf07bd8e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -8985,6 +9013,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py314haad56a0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py314hfc1f868_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -9262,6 +9291,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py314h9f07db2_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py314h221f224_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -9588,6 +9618,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rpds-py-0.30.0-py314h2e6c369_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/scipy-1.17.1-py314hf07bd8e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -9888,6 +9919,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/rpds-py-0.30.0-py314haad56a0_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/scipy-1.17.1-py314hfc1f868_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -10172,6 +10204,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-validator-0.1.1-pyh9f0ad1d_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3987-syntax-1.1.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/win-64/rpds-py-0.30.0-py314h9f07db2_0.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/scipy-1.17.1-py314h221f224_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-0.13.2-hd8ed1ab_3.conda - conda: https://conda.anaconda.org/conda-forge/noarch/seaborn-base-0.13.2-pyhd8ed1ab_3.conda @@ -19369,8 +19402,8 @@ packages: timestamp: 1733688053334 - pypi: ./ name: optimagic - version: 0.5.4.dev20+g4106914eb.d20260312 - sha256: 2cf6e94127e559c26caf2e9977d1ac8f045e59116290db2e36be1084a5131009 + version: 0.5.4.dev5+g8654d6292.d20260312 + sha256: 72e7ed28837a3da869c13448a83bee607a85ab9f1e2d9dc5b5e7604d8ce2bf94 requires_dist: - annotated-types>=0.4 - cloudpickle>=2.2 @@ -23484,6 +23517,52 @@ packages: - pkg:pypi/rpds-py?source=hash-mapping size: 235780 timestamp: 1764543046065 +- conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.15.5-h40fa522_0.conda + noarch: python + sha256: da5d47b231a590257b4ee0f3459e6ec30012ae549e3c29601cd15de178dafe9c + md5: 2ad709f7abc95e934d96e7a20b837b6e + depends: + - python + - __glibc >=2.17,<3.0.a0 + - libgcc >=14 + constrains: + - __glibc >=2.17 + license: MIT + license_family: MIT + purls: + - pkg:pypi/ruff?source=hash-mapping + size: 9273260 + timestamp: 1772780208047 +- conda: https://conda.anaconda.org/conda-forge/osx-arm64/ruff-0.15.5-h279115b_0.conda + noarch: python + sha256: 89cb3edc0239200b83cece7e27dce096facf2db0d3370dc46f047db65b1f1126 + md5: 02f7f9ffb450e26b44120c1cc8e543a4 + depends: + - python + - __osx >=11.0 + constrains: + - __osx >=11.0 + license: MIT + license_family: MIT + purls: + - pkg:pypi/ruff?source=hash-mapping + size: 8476952 + timestamp: 1772780440888 +- conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.15.5-h5739096_0.conda + noarch: python + sha256: d0bba8615cc662c684bb79a30145b8d4940a80d6906d12ef5ed074f1f1879bc8 + md5: 4b5fef0aa16f91d1286205ff19f2123c + depends: + - python + - vc >=14.3,<15 + - vc14_runtime >=14.44.35208 + - ucrt >=10.0.20348.0 + license: MIT + license_family: MIT + purls: + - pkg:pypi/ruff?source=hash-mapping + size: 9732695 + timestamp: 1772780220897 - conda: https://conda.anaconda.org/conda-forge/linux-64/scalapack-2.2.0-h606478a_6.conda sha256: 7743582add5741805eb30674d0941659ca692885053efaa295c75bd225b4541b md5: f7e03a004cbecfa1db983ece99285b08 diff --git a/pyproject.toml b/pyproject.toml index 856780a90..af1ac9a23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,10 +121,25 @@ select = [ "TID", # implicit string concatenation "ISC", + # pydocstyle + "D", ] extend-ignore = [ + # Missing docstrings — not enforced for now + "D100", # public module + "D101", # public class + "D102", # public method + "D103", # public function + "D104", # public package + "D105", # magic method + "D107", # __init__ + # Docstring content/style rules — too noisy to enforce for now + "D205", # blank line between summary and description + "D414", # section has no body + "D415", # first line punctuation + "D417", # missing argument descriptions # allow module import not at top of file, important for notebooks "E402", # do not assign a lambda expression, use a def @@ -423,6 +438,7 @@ iminuit = ">=2.25" cma = ">=3.3" pygad = ">=3.2" pytorch-cpu = ">=2.2" +ruff = ">=0.15.5,<0.16" [tool.pixi.pypi-dependencies] optimagic = { path = ".", editable = true } diff --git a/src/estimagic/estimate_ml.py b/src/estimagic/estimate_ml.py index 4044fee1d..a4f4882ef 100644 --- a/src/estimagic/estimate_ml.py +++ b/src/estimagic/estimate_ml.py @@ -153,7 +153,6 @@ def estimate_ml( LikelihoodResult: A LikelihoodResult object. """ - # ================================================================================== # handle deprecations # ================================================================================== diff --git a/src/estimagic/estimate_msm.py b/src/estimagic/estimate_msm.py index b207e9829..bf17d8f73 100644 --- a/src/estimagic/estimate_msm.py +++ b/src/estimagic/estimate_msm.py @@ -157,7 +157,7 @@ def estimate_msm( step_size by a factor of 2 compared to the rule of thumb for optimal step sizes. This is because many msm criterion functions are slightly noisy. - Returns: + Returns: dict: The estimated parameters, standard errors and sensitivity measures and covariance matrix of the parameters. diff --git a/src/estimagic/estimation_table.py b/src/estimagic/estimation_table.py index 9c953007c..731d925ac 100644 --- a/src/estimagic/estimation_table.py +++ b/src/estimagic/estimation_table.py @@ -134,6 +134,7 @@ def estimation_table( proper compilation of when working with siunitx package. Default True. escape_special_characters (bool): If True, replaces special characters in parameter and model names with LaTeX or HTML safe sequences. + Returns: res_table (data frame, str or dictionary): depending on the rerturn type, data frame with formatted strings, a string for html or latex tables, @@ -503,8 +504,9 @@ def render_html( def _process_model(model): """Check model validity, convert to dictionary. - Args + Args: model: Estimation result. See docstring of estimation_table for more info. + Returns: processed_model: A dictionary with keys params, info and name. @@ -805,7 +807,6 @@ def _get_cols_to_format(show_inference, confidence_intervals): def _apply_number_formatting_frames(dfs, columns, number_format, add_trailing_zeros): """Apply string formatter to specific columns of a list of DataFrames.""" - raw_formatted = [ _apply_number_format(df[columns], number_format, format_integers=False) for df in dfs @@ -1021,7 +1022,6 @@ def _convert_frame_to_string_series( """Return processed value series with significance stars and inference information. Args: - df (DataFrame): params DataFrame of the model significance_levels (list): see main docstring number_format (int, str, iterable or callable): see main docstring diff --git a/src/optimagic/benchmarking/benchmark_reports.py b/src/optimagic/benchmarking/benchmark_reports.py index 7dee5e5eb..2698aecc5 100644 --- a/src/optimagic/benchmarking/benchmark_reports.py +++ b/src/optimagic/benchmarking/benchmark_reports.py @@ -151,7 +151,6 @@ def traceback_report(problems, results, return_type="dataframe"): algorithms for problems where they stopped with an error. """ - if return_type == "text": report = [] for result in results.values(): diff --git a/src/optimagic/differentiation/derivatives.py b/src/optimagic/differentiation/derivatives.py index a521703c2..e2caf5daf 100644 --- a/src/optimagic/differentiation/derivatives.py +++ b/src/optimagic/differentiation/derivatives.py @@ -413,6 +413,7 @@ def second_derivative( key: str | None = None, ) -> NumdiffResult: """Evaluate second derivative of func at params according to method and step + options. Internally, the function is converted such that it maps from a 1d array to a 1d @@ -482,7 +483,6 @@ def second_derivative( NumdiffResult: A numerical differentiation result. """ - # ================================================================================== # handle deprecations # ================================================================================== @@ -1122,7 +1122,7 @@ def _nan_skipping_batch_evaluator( arguments (list): List with inputs for func. n_cores (int): Number of processes. - Returns + Returns: evaluations (list): The function evaluations, same length as arguments. """ diff --git a/src/optimagic/logging/logger.py b/src/optimagic/logging/logger.py index 9d6238340..f1a02ef85 100644 --- a/src/optimagic/logging/logger.py +++ b/src/optimagic/logging/logger.py @@ -438,6 +438,7 @@ def set_sqlite_pragma(dbapi_connection: Any, connection_record: Any) -> None: # class SQLiteLogReader(LogReader[SQLiteLogOptions]): """A class that manages the retrieving of optimization and exploration data from a + SQLite database. This class exposes methods to retrieve optimization logging data from stores. @@ -475,6 +476,7 @@ def _create(cls, log_options: SQLiteLogOptions) -> SQLiteLogReader: class _SQLiteLogStore(LogStore[SQLiteLogOptions, SQLiteLogReader]): """A logger class that stores and manages optimization and exploration data using + SQLite. It supports different strategies for handling existing databases, such as extending, diff --git a/src/optimagic/logging/read_log.py b/src/optimagic/logging/read_log.py index c8fee267d..bd4253773 100644 --- a/src/optimagic/logging/read_log.py +++ b/src/optimagic/logging/read_log.py @@ -1,5 +1,4 @@ -""" -Deprecated module: +"""Deprecated module: Functions to read data from the database used for logging. diff --git a/src/optimagic/logging/sqlalchemy.py b/src/optimagic/logging/sqlalchemy.py index d15097df6..a21f4fc45 100644 --- a/src/optimagic/logging/sqlalchemy.py +++ b/src/optimagic/logging/sqlalchemy.py @@ -442,6 +442,7 @@ class ProblemStore( SQLAlchemyTableStore[ProblemInitialization, ProblemInitializationWithId] ): """Store for managing optimization problem initialization data in an SQLite + database. Args: diff --git a/src/optimagic/optimization/internal_optimization_problem.py b/src/optimagic/optimization/internal_optimization_problem.py index ffceb23d6..5216bbda5 100644 --- a/src/optimagic/optimization/internal_optimization_problem.py +++ b/src/optimagic/optimization/internal_optimization_problem.py @@ -872,7 +872,6 @@ def _process_jac_value( The Jacobian value for the algorithm. """ - out_value = converter.derivative_to_internal(value, x) if direction == Direction.MAXIMIZE: out_value = -out_value @@ -966,6 +965,7 @@ class SphereExampleInternalOptimizationProblemWithConverter( InternalOptimizationProblem ): """Super simple example of an internal optimization problem with PyTree Converter. + Note: params should be a dict with key-value pairs `"x{i}" : val . eg. `{'x0': 1, 'x1': 2, ...}`. diff --git a/src/optimagic/optimization/multistart.py b/src/optimagic/optimization/multistart.py index e990dd79f..6048eb779 100644 --- a/src/optimagic/optimization/multistart.py +++ b/src/optimagic/optimization/multistart.py @@ -413,7 +413,6 @@ def update_convergence_state( bool: A bool that indicates if the optimizer has converged. """ - # ================================================================================== # unpack some variables # ================================================================================== diff --git a/src/optimagic/optimization/optimize.py b/src/optimagic/optimization/optimize.py index cd3b0caab..fdd500ca7 100644 --- a/src/optimagic/optimization/optimize.py +++ b/src/optimagic/optimization/optimize.py @@ -430,7 +430,6 @@ def minimize( multistart_options: Deprecated. Use multistart instead. """ - problem = create_optimization_problem( direction=Direction.MINIMIZE, fun=fun, diff --git a/src/optimagic/optimizers/_pounders/_trsbox.py b/src/optimagic/optimizers/_pounders/_trsbox.py index 33dc9db71..9e520929a 100644 --- a/src/optimagic/optimizers/_pounders/_trsbox.py +++ b/src/optimagic/optimizers/_pounders/_trsbox.py @@ -42,6 +42,7 @@ def minimize_trust_trsbox( upper_bounds (np.ndarray): 1d array of shape (n,) with upper bounds for the parameter vector x. trustregion_radius (float): Radius of the trust-region. + Returns: np.ndarray: Solution vector for the quadratic trust-region subproblem of shape (n,). diff --git a/src/optimagic/optimizers/_pounders/gqtpar.py b/src/optimagic/optimizers/_pounders/gqtpar.py index 04648f7f9..7b03c9ba6 100644 --- a/src/optimagic/optimizers/_pounders/gqtpar.py +++ b/src/optimagic/optimizers/_pounders/gqtpar.py @@ -550,7 +550,7 @@ def _solve_scalar_quadratic_equation(z, d): d (float): Smallest singular value of the upper triangular of the hessian matrix. - Returns + Returns: Tuple: The two values of t, sorted from low to high. - (float) Lower value of t. - (float) Higher value of t. diff --git a/src/optimagic/optimizers/bayesian_optimizer.py b/src/optimagic/optimizers/bayesian_optimizer.py index 312f446f5..ff90a9d2a 100644 --- a/src/optimagic/optimizers/bayesian_optimizer.py +++ b/src/optimagic/optimizers/bayesian_optimizer.py @@ -374,7 +374,6 @@ def _process_acquisition_function( instance, a class inheriting from AcquisitionFunction, or None. """ - from bayes_opt import acquisition acquisition_function_aliases = { diff --git a/src/optimagic/optimizers/gfo_optimizers.py b/src/optimagic/optimizers/gfo_optimizers.py index 39db14c7f..9c82ca3c3 100644 --- a/src/optimagic/optimizers/gfo_optimizers.py +++ b/src/optimagic/optimizers/gfo_optimizers.py @@ -610,7 +610,7 @@ def _solve_internal_problem( ) @dataclass(frozen=True) class GFOParticleSwarmOptimization(Algorithm, GFOCommonOptions): - """Minimize a scalar function using the Particle Swarm Optimization algorithm. + r"""Minimize a scalar function using the Particle Swarm Optimization algorithm. This algorithm is a Python implementation of the Particle Swarm Optimization algorithm through the gradient_free_optimizers package. @@ -694,7 +694,7 @@ def _solve_internal_problem( ) @dataclass(frozen=True) class GFOParallelTempering(Algorithm, GFOCommonOptions): - """Minimize a scalar function using the Parallel Tempering algorithm. + r"""Minimize a scalar function using the Parallel Tempering algorithm. This algorithm is a Python implementation of the Parallel Tempering algorithm through the gradient_free_optimizers package. @@ -767,7 +767,7 @@ def _solve_internal_problem( ) @dataclass(frozen=True) class GFOSpiralOptimization(Algorithm, GFOCommonOptions): - """Minimize a scalar function using the Spiral Optimization algorithm. + r"""Minimize a scalar function using the Spiral Optimization algorithm. This algorithm is a Python implementation of the Spiral Optimization algorithm through the gradient_free_optimizers package. @@ -969,7 +969,7 @@ def _solve_internal_problem( ) @dataclass(frozen=True) class GFOEvolutionStrategy(Algorithm, GFOCommonOptions): - """Minimize a scalar function using the Evolution Strategy algorithm. + r"""Minimize a scalar function using the Evolution Strategy algorithm. This algorithm is a Python implementation of the Evolution Strategy algorithm through the gradient_free_optimizers package. @@ -1058,7 +1058,7 @@ def _solve_internal_problem( ) @dataclass(frozen=True) class GFODifferentialEvolution(Algorithm, GFOCommonOptions): - """Minimize a scalar function using the Differential Evolution algorithm. + r"""Minimize a scalar function using the Differential Evolution algorithm. This algorithm is a Python implementation of the Differential Evolution algorithm through the gradient_free_optimizers package. diff --git a/src/optimagic/optimizers/iminuit_migrad.py b/src/optimagic/optimizers/iminuit_migrad.py index 27721131b..6ee25b034 100644 --- a/src/optimagic/optimizers/iminuit_migrad.py +++ b/src/optimagic/optimizers/iminuit_migrad.py @@ -42,7 +42,7 @@ ) @dataclass(frozen=True) class IminuitMigrad(Algorithm): - """Minimize a scalar differentiable function using the MIGRAD algorithm from + r"""Minimize a scalar differentiable function using the MIGRAD algorithm from iminuit. This optimizer wraps the MIGRAD algorithm from the iminuit package, which provides a @@ -117,7 +117,6 @@ def wrapped_objective(x: NDArray[np.float64]) -> float: def _process_minuit_result(minuit_result: Minuit) -> InternalOptimizeResult: """Convert iminuit result to optimagic's internal result format.""" - res = InternalOptimizeResult( x=np.array(minuit_result.values), fun=minuit_result.fval, @@ -155,14 +154,14 @@ def _convert_bounds_to_minuit_limits( upper_bounds : Optional[NDArray[np.float64]] Array of upper bounds for parameters. - Returns + Returns: ------- list[tuple[Optional[float], Optional[float]]] List of (lower, upper) limit tuples in Minuit format, where: - None indicates unbounded (equivalent to infinity) - Float values represent actual bounds - Notes + Notes: ----- Minuit expects bounds as tuples of (lower, upper) where: - `None` indicates no bound (equivalent to -inf or +inf) diff --git a/src/optimagic/optimizers/neldermead.py b/src/optimagic/optimizers/neldermead.py index 4e45da13a..ab5ddce84 100644 --- a/src/optimagic/optimizers/neldermead.py +++ b/src/optimagic/optimizers/neldermead.py @@ -41,7 +41,7 @@ ) @dataclass(frozen=True) class NelderMeadParallel(Algorithm): - """Parallel Nelder-Mead algorithm following Lee D., Wiswall M., A parallel + r"""Parallel Nelder-Mead algorithm following Lee D., Wiswall M., A parallel implementation of the simplex function minimization routine, Computational Economics, 2007. @@ -75,7 +75,7 @@ class NelderMeadParallel(Algorithm): batch_evaluator (string or callable): See :ref:`batch_evaluators` for details. Default "joblib". - Returns + Returns: ------- TYPE DESCRIPTION. diff --git a/src/optimagic/optimizers/nevergrad_optimizers.py b/src/optimagic/optimizers/nevergrad_optimizers.py index ee4c257fe..ecb45557a 100644 --- a/src/optimagic/optimizers/nevergrad_optimizers.py +++ b/src/optimagic/optimizers/nevergrad_optimizers.py @@ -1013,7 +1013,7 @@ def _solve_internal_problem( ) @dataclass(frozen=True) class NevergradTBPSA(Algorithm): - """Minimize a scalar function using the Test-based Population Size Adaptation + r"""Minimize a scalar function using the Test-based Population Size Adaptation algorithm. TBPSA adapts population size based on fitness trend detection using linear @@ -1531,7 +1531,6 @@ def _nevergrad_internal( InternalOptimizeResult: Internal optimization result """ - import nevergrad as ng param = ng.p.Array( diff --git a/src/optimagic/optimizers/pygad_optimizer.py b/src/optimagic/optimizers/pygad_optimizer.py index 85d4bc86f..b8a39bbcb 100644 --- a/src/optimagic/optimizers/pygad_optimizer.py +++ b/src/optimagic/optimizers/pygad_optimizer.py @@ -884,7 +884,6 @@ def _validate_user_defined_functions( gene_constraint: list[GeneConstraintFunction | None] | None, ) -> None: """Validate user-provided functions for selection, crossover, and constraints.""" - if parent_selection_type is None: pass elif isinstance(parent_selection_type, str): @@ -954,7 +953,6 @@ def _validate_protocol_function( func: Callable[..., Any], protocol: Any, name: str ) -> None: """Ensure a callable satisfies the expected protocol interface.""" - if not isinstance(func, protocol): raise TypeError(f"{name} must implement {protocol.__name__}.") diff --git a/src/optimagic/optimizers/pyswarms_optimizers.py b/src/optimagic/optimizers/pyswarms_optimizers.py index ced263cf4..7dd2ccd61 100644 --- a/src/optimagic/optimizers/pyswarms_optimizers.py +++ b/src/optimagic/optimizers/pyswarms_optimizers.py @@ -577,7 +577,8 @@ def _resolve_topology_config( config: Literal["star", "ring", "vonneumann", "random", "pyramid"] | Topology, ) -> tuple[Any, dict[str, float | int]]: """Resolves the topology config into a pyswarms topology instance and options - dict.""" + dict. + """ from pyswarms.backend.topology import Pyramid, Random, Ring, Star, VonNeumann if isinstance(config, str): diff --git a/src/optimagic/parameters/kernel_transformations.py b/src/optimagic/parameters/kernel_transformations.py index d371b6851..f1e2734b1 100644 --- a/src/optimagic/parameters/kernel_transformations.py +++ b/src/optimagic/parameters/kernel_transformations.py @@ -1,4 +1,4 @@ -"""Functions and derivatives thereof to transform external and internal params. +r"""Functions and derivatives thereof to transform external and internal params. Remarks on the mathematical notation: ------------------------------------- diff --git a/src/optimagic/parameters/nonlinear_constraints.py b/src/optimagic/parameters/nonlinear_constraints.py index 3479246ac..0cdd8e345 100644 --- a/src/optimagic/parameters/nonlinear_constraints.py +++ b/src/optimagic/parameters/nonlinear_constraints.py @@ -94,7 +94,6 @@ def _process_nonlinear_constraint( c, constraint_eval, params, bounds, converter, numdiff_options ): """Process a single nonlinear constraint.""" - # ================================================================================== # Process selector and evaluate functions if necessary # ================================================================================== diff --git a/src/optimagic/parameters/process_constraints.py b/src/optimagic/parameters/process_constraints.py index df53e7176..15bdd243b 100644 --- a/src/optimagic/parameters/process_constraints.py +++ b/src/optimagic/parameters/process_constraints.py @@ -48,7 +48,6 @@ def process_constraints( good error messages. Returns: - transformations (list): A processed version of those constraints that entail actual transformations and not just fixing parameters. constr_info (dict): Dict of 1d numpy arrays of length n_params (or None) with diff --git a/src/optimagic/parameters/space_conversion.py b/src/optimagic/parameters/space_conversion.py index 6bc86ec04..7e96e4833 100644 --- a/src/optimagic/parameters/space_conversion.py +++ b/src/optimagic/parameters/space_conversion.py @@ -367,7 +367,6 @@ def pre_replace(internal_values, fixed_values, pre_replacements): Examples: - >>> internal_values = np.array([1., 2.]) >>> fixed_values = np.array([np.nan, 0, np.nan]) >>> pre_replacements = np.array([1, -1, 0]) diff --git a/src/optimagic/typing.py b/src/optimagic/typing.py index db03c24cc..9b389ced2 100644 --- a/src/optimagic/typing.py +++ b/src/optimagic/typing.py @@ -41,9 +41,10 @@ class Direction(str, Enum): @dataclass(frozen=True) class DictLikeAccess: - """Useful base class for replacing string-based dictionaries with dataclass + r"""Useful base class for replacing string-based dictionaries with dataclass instances and keeping backward compatability regarding read access to the data - structure.""" + structure. + """ def __getitem__(self, key: str) -> Any: if key in self.__dict__: @@ -69,8 +70,9 @@ def values(self) -> ValuesView[str]: @dataclass(frozen=True) class TupleLikeAccess: - """Useful base class for replacing tuples with dataclass instances and keeping - backward compatability regarding read access to the data structure.""" + r"""Useful base class for replacing tuples with dataclass instances and keeping + backward compatability regarding read access to the data structure. + """ def __getitem__(self, index: int | slice) -> Any: field_values = [getattr(self, field.name) for field in fields(self)] diff --git a/src/optimagic/utilities.py b/src/optimagic/utilities.py index 447a09d70..c86f560e6 100644 --- a/src/optimagic/utilities.py +++ b/src/optimagic/utilities.py @@ -284,7 +284,7 @@ def hash_array(arr): def calculate_trustregion_initial_radius(x): - """Calculate the initial trust region radius. + r"""Calculate the initial trust region radius. It is calculated as :math:`0.1\\max(|x|_{\\infty}, 1)`. @@ -363,7 +363,6 @@ def dict_of_lists_to_list_of_dicts(dict_of_lists): list Examples: - >>> dict_of_lists_to_list_of_dicts({'a': [1, 3], 'b': [2, 4]}) [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}] diff --git a/src/optimagic/visualization/backends.py b/src/optimagic/visualization/backends.py index 361de1a35..01e5bc644 100644 --- a/src/optimagic/visualization/backends.py +++ b/src/optimagic/visualization/backends.py @@ -557,7 +557,6 @@ def _grid_line_plot_bokeh( A Bokeh gridplot object. """ - from bokeh.layouts import gridplot from bokeh.plotting import figure diff --git a/tests/estimagic/test_estimate_ml.py b/tests/estimagic/test_estimate_ml.py index f3e806311..c9e9c9a3c 100644 --- a/tests/estimagic/test_estimate_ml.py +++ b/tests/estimagic/test_estimate_ml.py @@ -150,8 +150,8 @@ def test_estimate_ml_with_logit_no_constraints( hessian, ): """Test that estimate_ml computes correct params and covariances under different - scenarios.""" - + scenarios. + """ # ================================================================================== # estimate # ================================================================================== @@ -254,7 +254,8 @@ def test_estimate_ml_with_logit_constraints( constraints, ): """Test that estimate_ml computes correct params and standard errors under different - scenarios with constraints.""" + scenarios with constraints. + """ seed = 1234 # ================================================================================== diff --git a/tests/optimagic/logging/test_sqlalchemy.py b/tests/optimagic/logging/test_sqlalchemy.py index 49571fcf6..5d1ae4d2d 100644 --- a/tests/optimagic/logging/test_sqlalchemy.py +++ b/tests/optimagic/logging/test_sqlalchemy.py @@ -89,7 +89,6 @@ def test_serialization(self, store): ) def test_parallel_insert(self, store, executor_factory): """Test multithreaded writing and reading in the IterationStore.""" - with executor_factory() as executor: # Insert data concurrently to_insert = list(map(self.create_test_point, range(10))) @@ -207,7 +206,6 @@ def test_serialization(self, store): ) def test_parallel_insert(self, store, executor_factory): """Test multithreaded writing and reading in the IterationStore.""" - with executor_factory() as executor: # Insert data concurrently to_insert = list(map(self.create_test_point, range(10))) @@ -233,7 +231,6 @@ def test_parallel_insert(self, store, executor_factory): ) def test_parallel_update(self, store, executor_factory): """Test multithreaded writing and reading in the IterationStore.""" - with executor_factory() as executor: # Insert data concurrently to_insert = list(map(self.create_test_point, range(10))) diff --git a/tests/optimagic/optimization/test_with_constraints.py b/tests/optimagic/optimization/test_with_constraints.py index dc0f4fd8a..f943c728f 100644 --- a/tests/optimagic/optimization/test_with_constraints.py +++ b/tests/optimagic/optimization/test_with_constraints.py @@ -306,7 +306,8 @@ def return_all_but_working_hours(params): def test_constraint_inheritance(): """Test that probability constraint applies both sets of parameters in a pairwise - equality constraint, no matter to which set they were applied originally.""" + equality constraint, no matter to which set they were applied originally. + """ for loc in [[0, 1], [2, 3]]: def selector(x, loc=loc):