diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index a4abfa8b5..335ed9c1c 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -18,25 +18,20 @@ jobs: contents: write steps: - uses: actions/checkout@v3 - - name: Setup Python - uses: actions/setup-python@v3 + - name: Install uv + uses: astral-sh/setup-uv@v6 with: - python-version: '3.10' + python-version: "3.10" - name: Get tag uses: olegtarasov/get-tag@v2.1 - name: Install pandoc run: sudo apt-get install -y pandoc - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 'latest' - name: Install package and test dependencies - run: | - poetry install --with dev,nbtools + run: uv sync --extra dev - name: build sphinx docs run: | cd docsrc - poetry run make github + uv run make github - name: Determine directory to publish docs to id: docs-publish-dir uses: jannekem/run-python-script-action@v1 diff --git a/.github/workflows/format_and_lint.yml b/.github/workflows/format_and_lint.yml index a7fffe021..2f7665f1d 100644 --- a/.github/workflows/format_and_lint.yml +++ b/.github/workflows/format_and_lint.yml @@ -13,16 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python 3.9 - uses: actions/setup-python@v3 + - name: Install uv + uses: astral-sh/setup-uv@v6 with: python-version: "3.9" - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 'latest' - name: Install dependencies - run: | - poetry install --with dev + run: uv sync --extra dev - name: Run pre-commit - run : poetry run pre-commit run --all-files --show-diff-on-failure --color=always + run: uv run pre-commit run --all-files --show-diff-on-failure --color=always diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 5395e7540..30c161763 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,4 +1,4 @@ -# This workflow will upload a Python Package using poetry when a release is created +# This workflow will upload a Python Package using uv when a release is created # Note that you must manually update the version number in pyproject.toml before attempting this. name: Upload Python Package @@ -14,10 +14,10 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Build and publish to pypi - uses: JRubics/poetry-publish@v2.0 - with: - pypi_token: ${{ secrets.PYPI_API_TOKEN }} - # python_version: "3.10" - # poetry_version: "==1.8" # can lock versions if we want + - uses: actions/checkout@v4 + - uses: astral-sh/setup-uv@v6 + - run: uv build + - name: Publish to pypi + env: + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + run: uv publish --token "$PYPI_API_TOKEN" diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 6ae4602ca..61bf7e92b 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -1,4 +1,4 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python +# This workflow will install Python dependencies and run tests in multiple versions of Python # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: tests @@ -25,31 +25,16 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v3 + - name: Install uv and set the python version + uses: astral-sh/setup-uv@v6 with: python-version: ${{ matrix.python-version }} - - name: Install the latest version of uv - uses: astral-sh/setup-uv@v5 - with: - version: "latest" - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - version: 'latest' - name: Install test dependencies run: | - poetry self add poetry-plugin-export - poetry export -f requirements.txt --with dev,nbtools --without-hashes --output requirements-dev.txt - echo "numpy${{ matrix.numpy-version }}" >> constraints.txt - uv pip compile requirements-dev.txt --output-file requirements.txt \ - --python-version ${{ matrix.python-version }} \ - --override constraints.txt - poetry run pip install -r requirements.txt - poetry install --only-root - - name: Test with pytest - run: | - poetry run pytest --cov-report xml --cov=bayes_opt/ + uv sync --extra dev + uv pip install "numpy${{ matrix.numpy-version}}" + - name: Run pytest + run: uv run --no-sync pytest --cov-report xml --cov=bayes_opt/ - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: diff --git a/.gitignore b/.gitignore index 4b159c12f..672b76ddb 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ docsrc/static/* docsrc/README.md poetry.lock +uv.lock # Add log files and optimizer state files to gitignore examples/logs.log diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 999080796..d86185dec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,4 +6,4 @@ repos: name: ruff-format args: [--check] repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.6 \ No newline at end of file + rev: v0.12.3 \ No newline at end of file diff --git a/bayes_opt/__init__.py b/bayes_opt/__init__.py index 7bdc88ead..8fa19ad6b 100644 --- a/bayes_opt/__init__.py +++ b/bayes_opt/__init__.py @@ -15,10 +15,10 @@ __all__ = [ - "acquisition", "BayesianOptimization", - "TargetSpace", "ConstraintModel", "ScreenLogger", "SequentialDomainReductionTransformer", + "TargetSpace", + "acquisition", ] diff --git a/bayes_opt/constraint.py b/bayes_opt/constraint.py index b823c9096..8042cc9fb 100644 --- a/bayes_opt/constraint.py +++ b/bayes_opt/constraint.py @@ -240,7 +240,7 @@ def approx(self, X: NDArray[Float]) -> NDArray[Float]: return self._model[0].predict(X).reshape(X_shape[:-1]) result = np.column_stack([gp.predict(X) for gp in self._model]) - return result.reshape(X_shape[:-1] + (len(self._lb),)) + return result.reshape(*X_shape[:-1], len(self._lb)) def allowed(self, constraint_values: NDArray[Float]) -> NDArray[np.bool_]: """Check whether `constraint_values` fulfills the specified limits. diff --git a/bayes_opt/exception.py b/bayes_opt/exception.py index 628e20d77..642b09092 100644 --- a/bayes_opt/exception.py +++ b/bayes_opt/exception.py @@ -4,9 +4,9 @@ __all__ = [ "BayesianOptimizationError", - "NotUniqueError", "ConstraintNotSupportedError", "NoValidPointRegisteredError", + "NotUniqueError", "TargetSpaceEmptyError", ] diff --git a/pyproject.toml b/pyproject.toml index 94c659735..99c2bfd27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "Bayesian Optimization package" authors = [{ name = "Fernando Nogueira", email = "fmfnogueira@gmail.com" }] license = { file = "LICENSE" } readme = "README.md" -requires-python = ">=3.9,<4.0" +requires-python = ">=3.9" classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", @@ -17,51 +17,40 @@ classifiers = [ "Programming Language :: Python :: 3.13", ] dependencies = [ - "scikit-learn>=1.0.0,<2.0.0", + "colorama>=0.4.6", "numpy>=1.25; python_version<'3.13'", "numpy>=2.1.3; python_version>='3.13'", - "scipy>=1.0.0,<2.0.0; python_version<'3.13'", - "scipy>=1.14.1,<2.0.0; python_version>='3.13'", - "colorama>=0.4.6,<1.0.0", + "scikit-learn>=1.0.0", + "scipy>=1.0.0; python_version<'3.13'", + "scipy>=1.14.1; python_version>='3.13'", ] -[tool.poetry] -requires-poetry = ">=2.0" -packages = [{ include = "bayes_opt" }] - - -[tool.poetry.group.dev] # for testing/developing -optional = true -[tool.poetry.group.dev.dependencies] -pytest = "^8.0.0" -pytest-cov = "^4.1.0" -coverage = "^7.4.1" -ruff = "0.6.6" -pre-commit = "^3.7.1" - - -[tool.poetry.group.nbtools] # for running/converting notebooks -optional = true -[tool.poetry.group.nbtools.dependencies] -nbformat = "^5.9.2" -nbconvert = "^7.14.2" -jupyter = "^1.0.0" -matplotlib = "^3.0" -nbsphinx = "^0.9.4" -sphinx-immaterial = "^0.12.0" -sphinx = [ - { version = "^7.0.0", python = "<3.10" }, - { version = "^8.0.0", python = ">=3.10" }, +[project.optional-dependencies] +dev = [ + "coverage>=7.4.1", + "jupyter>=1.0.0", + "matplotlib>=3.0", + "nbconvert>=7.14.2", + "nbformat>=5.9.2", + "nbsphinx>=0.9.4", + "pre-commit>=3.7.1", + "pytest>=8.0.0", + "pytest-cov>=4.1.0", + "ruff>=0.12.3", + "sphinx-immaterial>=0.12.0", + "sphinx>=7.0.0; python_version<'3.10'", + "sphinx>=8.0.0; python_version>='3.10'", + "sphinx-autodoc-typehints>=2.3.0; python_version<'3.10'", + "sphinx-autodoc-typehints>=2.4.0; python_version>='3.10'", ] -sphinx-autodoc-typehints = [ - { version = "^2.3.0", python = "<3.10" }, - { version = "^2.4.0", python = ">=3.10" }, -] - [build-system] -requires = ["poetry-core>=2.0"] -build-backend = "poetry.core.masonry.api" +requires = ["uv_build>=0.7.21,<0.8.0"] +build-backend = "uv_build" + +[tool.uv.build-backend] +module-name = "bayes_opt" +module-root = "" [tool.coverage.report] exclude_lines = [ diff --git a/scripts/check.sh b/scripts/check.sh index 180d03d95..19c15f5f5 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh set -ex -poetry run ruff format --check bayes_opt tests -poetry run ruff check bayes_opt tests +uv run ruff format --check bayes_opt tests +uv run ruff check bayes_opt tests diff --git a/scripts/check_precommit.sh b/scripts/check_precommit.sh index c58fd7ad6..26956718e 100755 --- a/scripts/check_precommit.sh +++ b/scripts/check_precommit.sh @@ -1,5 +1,5 @@ #!/usr/bin/env sh set -ex -poetry run pre-commit install -poetry run pre-commit run --all-files --show-diff-on-failure \ No newline at end of file +uv run pre-commit install +uv run pre-commit run --all-files --show-diff-on-failure diff --git a/scripts/format.sh b/scripts/format.sh index bff192c01..ea3844b64 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -1,6 +1,5 @@ #!/usr/bin/env sh set -ex -poetry run ruff format bayes_opt tests -poetry run ruff check bayes_opt --fix - +uv run ruff format bayes_opt tests +uv run ruff check bayes_opt --fix diff --git a/tests/test_seq_domain_red.py b/tests/test_seq_domain_red.py index c22dd0d1b..5865d8770 100644 --- a/tests/test_seq_domain_red.py +++ b/tests/test_seq_domain_red.py @@ -156,14 +156,14 @@ def verify_bounds_in_range(new_bounds, global_bounds): # test if both (upper/lower) bounds for a parameter exceed the global bounds new_bounds = np.array([[-50, -20], [20, 50]]) - with pytest.warns(UserWarning): + with pytest.warns(UserWarning, match="A parameter's lower bound is greater than the global upper bound"): trimmed_bounds = bounds_transformer._trim(new_bounds, global_bounds) assert verify_bounds_in_range(trimmed_bounds, global_bounds) # test if both (upper/lower) bounds for a parameter exceed the global bounds # while they are out of order new_bounds = np.array([[-20, -50], [-10, 10]]) - with pytest.warns(UserWarning): + with pytest.warns(UserWarning, match="A parameter's lower bound is greater than the global upper bound"): trimmed_bounds = bounds_transformer._trim(new_bounds, global_bounds) assert verify_bounds_in_range(trimmed_bounds, global_bounds) diff --git a/tests/test_target_space.py b/tests/test_target_space.py index dad89986b..45729cd23 100644 --- a/tests/test_target_space.py +++ b/tests/test_target_space.py @@ -125,7 +125,7 @@ def test_register_point_beyond_bounds(): PBOUNDS = {"p1": (0, 1), "p2": (1, 10)} space = TargetSpace(target_func, PBOUNDS) - with pytest.warns(UserWarning): + with pytest.warns(UserWarning, match="is outside the bounds of the parameter"): space.register(params={"p1": 0.5, "p2": 20}, target=2.5) @@ -209,7 +209,7 @@ def test_y_max_within_pbounds(): assert space._target_max() is None space.probe(params={"p1": 1, "p2": 2}) space.probe(params={"p1": 0, "p2": 1}) - with pytest.warns(UserWarning): + with pytest.warns(UserWarning, match="is outside the bounds of the parameter"): space.probe(params={"p1": 5, "p2": 1}) assert space._target_max() == 3