From e38b9911531e32ac8f1e1c809525b07723ba0f62 Mon Sep 17 00:00:00 2001 From: c-bata Date: Sat, 28 Mar 2026 16:15:53 +0900 Subject: [PATCH 1/2] Migrate to uv --- .gitignore | 2 ++ pyproject.toml | 36 ++++++++++++++++++++++++ requirements-bench.txt | 3 -- requirements-dev.txt | 18 ------------ tests/test_fuzzing.py | 63 ------------------------------------------ 5 files changed, 38 insertions(+), 84 deletions(-) delete mode 100644 requirements-bench.txt delete mode 100644 requirements-dev.txt delete mode 100644 tests/test_fuzzing.py diff --git a/.gitignore b/.gitignore index bdcbff5..8ade8ca 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ benchmark/*.json *.stats *.sqlite3 +uv.lock + diff --git a/pyproject.toml b/pyproject.toml index 9e21181..b64b522 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,3 +75,39 @@ ignore = [ "E203", ] +[tool.uv] +exclude-newer = "1 week" +exclude-newer-package = { torch = false } + +[[tool.uv.index]] +name = "pytorch-cpu" +url = "https://download.pytorch.org/whl/cpu" +explicit = true + +[tool.uv.sources] +torch = [ + { index = "pytorch-cpu" }, +] + +[dependency-groups] +dev = [ + # lint + "mypy", + "ruff", + # tests + "pytest", + # visualization + "matplotlib", +] +optional = [ + # for Safe CMA-ES + "torch", + "gpytorch", + # for CMA with margin + "scipy", +] +benchmark = [ + "kurobako", + "cma", + "optuna", +] diff --git a/requirements-bench.txt b/requirements-bench.txt deleted file mode 100644 index c28302c..0000000 --- a/requirements-bench.txt +++ /dev/null @@ -1,3 +0,0 @@ -kurobako -cma -optuna diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 4373516..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,18 +0,0 @@ -# install_requires -numpy>=1.20.0 - -# for Safe CMA-ES -torch -gpytorch - -# visualization -matplotlib -scipy - -# Fuzzing -hypothesis -atheris - -# lint -ruff - diff --git a/tests/test_fuzzing.py b/tests/test_fuzzing.py deleted file mode 100644 index da753cf..0000000 --- a/tests/test_fuzzing.py +++ /dev/null @@ -1,63 +0,0 @@ -import hypothesis.extra.numpy as npst -import unittest -from hypothesis import given, strategies as st - -from cmaes import CMA, SepCMA - - -class TestFuzzing(unittest.TestCase): - @given( - data=st.data(), - ) - def test_cma_tell(self, data): - dim = data.draw(st.integers(min_value=1, max_value=100)) - mean = data.draw(npst.arrays(dtype=float, shape=dim)) - sigma = data.draw(st.floats(min_value=1e-16)) - n_iterations = data.draw(st.integers(min_value=1)) - try: - optimizer = CMA(mean, sigma) - except AssertionError: - return - popsize = optimizer.population_size - for _ in range(n_iterations): - tell_solutions = data.draw( - st.lists( - st.tuples(npst.arrays(dtype=float, shape=dim), st.floats()), - min_size=popsize, - max_size=popsize, - ) - ) - optimizer.ask() - try: - optimizer.tell(tell_solutions) - except AssertionError: - return - optimizer.ask() - - @given( - data=st.data(), - ) - def test_sepcma_tell(self, data): - dim = data.draw(st.integers(min_value=2, max_value=100)) - mean = data.draw(npst.arrays(dtype=float, shape=dim)) - sigma = data.draw(st.floats(min_value=1e-16)) - n_iterations = data.draw(st.integers(min_value=1)) - try: - optimizer = SepCMA(mean, sigma) - except AssertionError: - return - popsize = optimizer.population_size - for _ in range(n_iterations): - tell_solutions = data.draw( - st.lists( - st.tuples(npst.arrays(dtype=float, shape=dim), st.floats()), - min_size=popsize, - max_size=popsize, - ) - ) - optimizer.ask() - try: - optimizer.tell(tell_solutions) - except AssertionError: - return - optimizer.ask() From 391ee0baa1a7adaf124d3db8e210833547eb64cd Mon Sep 17 00:00:00 2001 From: c-bata Date: Sat, 28 Mar 2026 16:16:00 +0900 Subject: [PATCH 2/2] Update workflow for uv --- .github/workflows/examples.yml | 48 ++++++++++++------------------ .github/workflows/pypi-publish.yml | 13 +++----- .github/workflows/tests.yml | 45 ++++++++-------------------- 3 files changed, 35 insertions(+), 71 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index e5bbb6e..1b9e2b8 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -15,40 +15,30 @@ jobs: python-version: ["3.9", "3.14"] steps: - uses: actions/checkout@v6 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v6 + - name: Install the latest version of uv and set the python version + uses: astral-sh/setup-uv@v7 with: python-version: ${{ matrix.python-version }} - architecture: x64 - name: Install dependencies - run: | - pip install -U pip setuptools - pip install --progress-bar off optuna numpy scipy gpytorch torch - pip install --progress-bar off -U . - - run: python examples/quadratic_2d_function.py - - run: python examples/ipop_cma.py - - run: python examples/bipop_cma.py - - run: python examples/ellipsoid_function.py - - run: python examples/optuna_sampler.py - - run: python examples/lra_cma.py - - run: python examples/ws_cma.py - - run: python examples/cma_with_margin_binary.py - - run: python examples/cma_with_margin_integer.py - - run: python examples/safecma.py - - run: python examples/cma_sop.py + run: uv sync --group optional --group benchmark + - run: uv run python examples/quadratic_2d_function.py + - run: uv run python examples/ipop_cma.py + - run: uv run python examples/bipop_cma.py + - run: uv run python examples/ellipsoid_function.py + - run: uv run python examples/optuna_sampler.py + - run: uv run python examples/lra_cma.py + - run: uv run python examples/ws_cma.py + - run: uv run python examples/cma_with_margin_binary.py + - run: uv run python examples/cma_with_margin_integer.py + - run: uv run python examples/safecma.py + - run: uv run python examples/cma_sop.py examples-cmawm-without-scipy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - name: Set up Python - uses: actions/setup-python@v6 - with: - python-version: '3.x' - architecture: x64 - check-latest: true + - name: Install the latest version of uv and set the python version + uses: astral-sh/setup-uv@v7 - name: Install dependencies - run: | - pip install -U pip setuptools - pip install --progress-bar off -U . - - run: python examples/cma_with_margin_binary.py - - run: python examples/cma_with_margin_integer.py + run: uv sync + - run: uv run python examples/cma_with_margin_binary.py + - run: uv run python examples/cma_with_margin_integer.py diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index d46aecd..c1c05f4 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -13,19 +13,15 @@ jobs: id-token: write steps: - uses: actions/checkout@v6 - - name: Set up Python - uses: actions/setup-python@v6 + - name: Install the latest version of uv and set the python version + uses: astral-sh/setup-uv@v7 with: python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools - pip install --progress-bar off twine wheel build - name: Build distribution packages - run: python -m build --sdist --wheel + run: uv build --sdist --wheel --no-sources - name: Verify the distributions - run: twine check dist/* + run: uvx twine check dist/* - uses: actions/upload-artifact@v4 with: @@ -44,4 +40,3 @@ jobs: run: | export TAGNAME=$(jq --raw-output .ref "$GITHUB_EVENT_PATH" | sed -e "s/refs\/tags\///") gh release create ${TAGNAME} --draft dist/* - diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5027393..1110b91 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,46 +12,25 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - name: Set up Python - uses: actions/setup-python@v6 - with: - python-version: '3.x' - architecture: x64 + - name: Install uv + uses: astral-sh/setup-uv@v7 - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools - pip install --progress-bar off numpy matplotlib scipy mypy ruff torch gpytorch - - run: ruff check . - - run: ruff format --check . - - run: mypy cmaes + run: uv sync --group dev --group optional + - run: uv run ruff check . + - run: uv run ruff format --check . + - run: uv run mypy cmaes test: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] + python-version: ["3.9", "3.14"] steps: - uses: actions/checkout@v6 - - name: Setup Python${{ matrix.python-version }} - uses: actions/setup-python@v6 + - name: Install the latest version of uv and set the python version + uses: astral-sh/setup-uv@v7 with: python-version: ${{ matrix.python-version }} - architecture: x64 - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools numpy scipy hypothesis pytest torch gpytorch - pip install --progress-bar off . - - run: python -m pytest tests - test-numpy2: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Setup Python - uses: actions/setup-python@v6 - with: - architecture: x64 - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools scipy hypothesis pytest torch gpytorch - python -m pip install --pre --upgrade numpy - pip install --progress-bar off . - - run: python -m pytest tests + run: uv sync --group dev --group optional + - run: uv run pytest tests +