From 804fb71ecb2005473af178052d8b847739bd9c51 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 1 Nov 2023 03:04:54 +0100 Subject: [PATCH 01/12] Remove MOTPESampler from the doc because it is deprecated --- optuna/multi_objective/samplers/_motpe.py | 22 ++++++++++++++++ optuna/samplers/_tpe/sampler.py | 31 +++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index 87b0787e15..1f6cc27dfc 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -28,6 +28,28 @@ class MOTPEMultiObjectiveSampler(BaseMultiObjectiveSampler): This sampler is a multiobjective version of :class:`~optuna.samplers.TPESampler`. + .. note:: + For `v2.9.0 `_ or later, + MOTPEMultiObjectiveSampler is deprecated and :class:`~optuna.samplers.TPESampler` should be + used instead. The following code shows how you run TPESampler on a multi-objective task: + + .. testcode:: + + import optuna + + def objective(trial): + x = trial.suggest_float("x", -100, 100) + y = trial.suggest_categorical("y", [-1, 0, 1]) + f1 = x**2 + y + f2 = -((x - 2) ** 2 + y) + return f1, f2 + + + # We minimize the first objective and the second objective. + sampler = optuna.samplers.TPESampler() + study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) + study.optimize(objective, n_trials=100) + For further information about MOTPE algorithm, please refer to the following paper: - `Multiobjective tree-structured parzen estimator for computationally expensive optimization diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index fe4e1fb596..dd091662ca 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -74,11 +74,16 @@ class TPESampler(BaseSampler): `_ - `Making a Science of Model Search: Hyperparameter Optimization in Hundreds of Dimensions for Vision Architectures `_ - - `Multiobjective tree-structured parzen estimator for computationally expensive optimization - problems `_ + - `Tree-Structured Parzen Estimator: Understanding Its Algorithm Components and Their Roles for + Better Empirical Performance `_ + + For multi-objective TPE (MOTPE), please refer to the following papers: + - `Multiobjective Tree-Structured Parzen Estimator for Computationally Expensive Optimization + Problems `_ - `Multiobjective Tree-Structured Parzen Estimator `_ Example: + An example of a single-objective optimization is as follows: .. testcode:: @@ -94,6 +99,28 @@ def objective(trial): study = optuna.create_study(sampler=TPESampler()) study.optimize(objective, n_trials=10) + .. note:: + For `v2.9.0 `_ or later, + :class:`~optuna.samplers.MOTPESampler` is deprecated and TPESampler should be used instead. + The following code shows how you run TPESampler on a multi-objective task: + + .. testcode:: + + import optuna + + def objective(trial): + x = trial.suggest_float("x", -100, 100) + y = trial.suggest_categorical("y", [-1, 0, 1]) + f1 = x**2 + y + f2 = -((x - 2) ** 2 + y) + return f1, f2 + + + # We minimize the first objective and the second objective. + sampler = optuna.samplers.TPESampler() + study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) + study.optimize(objective, n_trials=100) + Args: consider_prior: Enhance the stability of Parzen estimator by imposing a Gaussian prior when From d63d0cc00dd103d7f79fe18135d463d29979fe0d Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 1 Nov 2023 03:18:18 +0100 Subject: [PATCH 02/12] Apply black --- optuna/multi_objective/samplers/_motpe.py | 1 + optuna/samplers/_tpe/sampler.py | 1 + 2 files changed, 2 insertions(+) diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index 1f6cc27dfc..d16f5ab5d5 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -37,6 +37,7 @@ class MOTPEMultiObjectiveSampler(BaseMultiObjectiveSampler): import optuna + def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_categorical("y", [-1, 0, 1]) diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index dd091662ca..59a04b4f20 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -108,6 +108,7 @@ def objective(trial): import optuna + def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_categorical("y", [-1, 0, 1]) From 8c1ca930fc496fb13c9eb2e596223a899d521d57 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 1 Nov 2023 05:54:15 +0100 Subject: [PATCH 03/12] [temp] Deactivate tests for quick check --- .github/workflows/mac-tests.yml | 138 ------------------ .github/workflows/tests-integration.yml | 78 ---------- .github/workflows/tests-mpi.yml | 82 ----------- .github/workflows/tests-storage.yml | 130 ----------------- .../workflows/tests-with-minimum-versions.yml | 92 ------------ .github/workflows/tests.yml | 89 ----------- .github/workflows/windows-tests.yml | 135 ----------------- optuna/multi_objective/samplers/_motpe.py | 7 +- .../samplers/_tpe/multi_objective_sampler.py | 28 +++- optuna/samplers/_tpe/sampler.py | 5 +- 10 files changed, 33 insertions(+), 751 deletions(-) diff --git a/.github/workflows/mac-tests.yml b/.github/workflows/mac-tests.yml index 526d6795d4..e69de29bb2 100644 --- a/.github/workflows/mac-tests.yml +++ b/.github/workflows/mac-tests.yml @@ -1,138 +0,0 @@ -# Run tests and integration tests on Mac, which are triggered by each master push. -# Currently, Python3.8 is only used as an environment. -# This is mainly for the sake of speed. -name: mac-tests - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - tests-mac: - runs-on: macos-latest - - # Scheduled Tests are disabled for forks. - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python3.8 - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test - with: - path: ~/Library/Caches/pip - key: ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Install - run: | - python -m pip install --upgrade pip - pip install --progress-bar off -U setuptools - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - - name: Scheduled tests - if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - run: | - pytest tests -m "not integration" - - name: Tests - if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} - run: | - pytest tests -m "not integration and not slow" - - - tests-integration-mac: - runs-on: macos-latest - - # Scheduled Tests are disabled for forks. - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python3.8 - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test-integration - with: - path: ~/Library/Caches/pip - key: ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Setup mac environment - run: | - brew install libomp - brew install open-mpi - brew install openblas - - - name: Install - run: | - python -m pip install --upgrade pip - - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] - pip install --progress-bar off .[integration] - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - - name: Tests - run: | - pytest tests -m "integration" - - env: - OMP_NUM_THREADS: 1 - - - name: Tests MPI - run: | - export OMPI_MCA_rmaps_base_oversubscribe=yes - mpirun -n 2 -- pytest tests/integration_tests/test_pytorch_distributed.py - env: - OMP_NUM_THREADS: 1 diff --git a/.github/workflows/tests-integration.yml b/.github/workflows/tests-integration.yml index 2255fc11cc..e69de29bb2 100644 --- a/.github/workflows/tests-integration.yml +++ b/.github/workflows/tests-integration.yml @@ -1,78 +0,0 @@ -name: Tests (Integration) - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - tests-integration: - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - runs-on: ubuntu-latest - - strategy: - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test-integration - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Setup environment - run: | - sudo apt-get update - sudo apt-get -y install openmpi-bin libopenmpi-dev libopenblas-dev - - - name: Install - run: | - python -m pip install --upgrade pip - - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu - pip install --progress-bar off .[integration] --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Scheduled tests - if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - run: | - pytest tests -m "integration" - - - name: Tests - if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} - run: | - pytest tests -m "integration and not slow" diff --git a/.github/workflows/tests-mpi.yml b/.github/workflows/tests-mpi.yml index 3ea1f1f46f..e69de29bb2 100644 --- a/.github/workflows/tests-mpi.yml +++ b/.github/workflows/tests-mpi.yml @@ -1,82 +0,0 @@ -name: Tests (MPI) - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - tests-mpi: - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - runs-on: ubuntu-latest - - strategy: - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test-mpi - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Setup environment - run: | - sudo apt-get update - sudo apt-get -y install openmpi-bin libopenmpi-dev - - - name: Install - run: | - python -m pip install --upgrade pip - - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu - - # TODO(not522): Remove this line when torchmetrics can be installed with extra-index-url - pip install --progress-bar off torchmetrics - - pip install --progress-bar off .[integration] --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Tests - run: | - export OMPI_MCA_rmaps_base_oversubscribe=yes - - if [ ${{ matrix.python-version }} != 3.11 ]; then - mpirun -n 2 -- pytest tests/integration_tests/test_pytorch_distributed.py - fi - - env: - OMP_NUM_THREADS: 1 diff --git a/.github/workflows/tests-storage.yml b/.github/workflows/tests-storage.yml index bf45161d2c..e69de29bb2 100644 --- a/.github/workflows/tests-storage.yml +++ b/.github/workflows/tests-storage.yml @@ -1,130 +0,0 @@ -name: Tests (Storage with server) - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - # TODO(masap): Modify job name to "tests-storage-with-server" because this test is not only for - # RDB. Since current name "tests-rdbstorage" is required in the Branch protection rules, you - # need to modify the Branch protection rules as well. - tests-rdbstorage: - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - runs-on: ubuntu-latest - - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] - - services: - mysql: - image: mysql:5.7 - ports: - - 3306:3306 - env: - MYSQL_ROOT_PASSWORD: mandatory_arguments - MYSQL_DATABASE: optunatest - MYSQL_USER: user - MYSQL_PASSWORD: test - options: >- - --health-cmd "mysqladmin ping -h localhost" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - postgres: - image: postgres:10.1-alpine - ports: - - 5432:5432 - env: - POSTGRES_DB: optunatest - POSTGRES_USER: user - POSTGRES_PASSWORD: test - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - redis: - image: redis - ports: - - 6379:6379 - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test-storage-with-server - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Setup environment - run: | - sudo apt-get update - sudo apt-get -y install openmpi-bin libopenmpi-dev - - - name: Install - run: | - python -m pip install --upgrade pip - pip install --progress-bar off -U setuptools - - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Install DB bindings - run: | - pip install --progress-bar off PyMySQL cryptography psycopg2-binary redis - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Tests MySQL - run: | - pytest tests/storages_tests/test_with_server.py - env: - SQLALCHEMY_WARN_20: 1 - OMP_NUM_THREADS: 1 - TEST_DB_URL: mysql+pymysql://user:test@127.0.0.1/optunatest - - - name: Tests PostgreSQL - run: | - pytest tests/storages_tests/test_with_server.py - env: - OMP_NUM_THREADS: 1 - TEST_DB_URL: postgresql+psycopg2://user:test@127.0.0.1/optunatest - - - name: Tests Journal Redis - run: | - pytest tests/storages_tests/test_with_server.py - env: - OMP_NUM_THREADS: 1 - TEST_DB_URL: redis://localhost:6379 - TEST_DB_MODE: journal-redis diff --git a/.github/workflows/tests-with-minimum-versions.yml b/.github/workflows/tests-with-minimum-versions.yml index 679d9ef7e6..e69de29bb2 100644 --- a/.github/workflows/tests-with-minimum-versions.yml +++ b/.github/workflows/tests-with-minimum-versions.yml @@ -1,92 +0,0 @@ -name: Tests with minimum versions - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - tests-with-minimum-versions: - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - runs-on: ubuntu-latest - - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9'] - - services: - redis: - image: redis - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test-with-minimum-versions - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/setup.py') }}-v1 - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/setup.py') }} - - - - name: Setup pip - run: | - python -m pip install --upgrade pip - pip install --progress-bar off -U setuptools - - - name: Install - run: | - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Install dependencies with minimum versions - run: | - # Install dependencies with minimum versions. - pip uninstall -y alembic cmaes packaging sqlalchemy plotly scikit-learn - pip install alembic==1.5.0 cmaes==0.10.0 packaging==20.0 sqlalchemy==1.3.0 numpy==1.20.3 tqdm==4.27.0 colorlog==0.3 PyYAML==5.1 - pip install plotly==5.0.0 scikit-learn==0.24.2 # optional extras - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Scheduled tests - if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - run: | - pytest tests -m "not integration" - - - name: Tests - if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} - run: | - pytest tests -m "not integration and not slow" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4c8d172139..e69de29bb2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,89 +0,0 @@ -name: Tests - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - tests: - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - runs-on: ubuntu-latest - - strategy: - matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] - - services: - redis: - image: redis - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: test - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - - name: Setup pip - run: | - python -m pip install --upgrade pip - pip install --progress-bar off -U setuptools - - - name: Install - run: | - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Scheduled tests - if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - run: | - pytest tests -m "not integration" - env: - SQLALCHEMY_WARN_20: 1 - - - name: Tests - if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} - run: | - pytest tests -m "not integration and not slow" - env: - SQLALCHEMY_WARN_20: 1 diff --git a/.github/workflows/windows-tests.yml b/.github/workflows/windows-tests.yml index 7b46856277..e69de29bb2 100644 --- a/.github/workflows/windows-tests.yml +++ b/.github/workflows/windows-tests.yml @@ -1,135 +0,0 @@ -# Run tests and integration tests on Windows, which are triggered by each master push. -# Currently, Python3.9 is only used as an environment. -# This is mainly for the sake of speed. -name: windows-tests - -on: - push: - branches: - - master - pull_request: {} - schedule: - - cron: '0 23 * * SUN-THU' - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} - cancel-in-progress: true - -jobs: - tests-windows: - runs-on: windows-latest - - # Not intended for forks. - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python3.9 - uses: actions/setup-python@v4 - with: - python-version: "3.9" - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: windows-test - with: - path: ~\\AppData\\Local\\pip\\Cache - key: ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Install - run: | - python -m pip install --upgrade pip - pip install --progress-bar off -U setuptools - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] - pip install PyQt6 # Install PyQT for using QtAgg as matplotlib backend. - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Scheduled tests - if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} - run: | - pytest -m "not integration" - env: - SQLALCHEMY_WARN_20: 1 - MPLBACKEND: "QtAgg" # Use QtAgg as matplotlib backend. - - - name: Tests - if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} - run: | - pytest -m "not integration and not slow" - env: - MPLBACKEND: "QtAgg" # Use QtAgg as matplotlib backend. - - tests-integration-windows: - runs-on: windows-latest - - # Not intended for forks. - if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Python3.9 - uses: actions/setup-python@v4 - with: - python-version: "3.9" - - - name: Setup cache - uses: actions/cache@v3 - env: - cache-name: windows-test-integration - with: - path: ~\\AppData\\Local\\pip\\Cache - key: ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 - restore-keys: | - ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} - - - name: Setup MPI - uses: mpi4py/setup-mpi@v1 - with: - mpi: "msmpi" - - - name: Install - run: | - python -m pip install --upgrade pip - pip install --progress-bar off -U setuptools - # Install minimal dependencies and confirm that `import optuna` is successful. - pip install --progress-bar off . - python -c 'import optuna' - optuna --version - pip install --progress-bar off .[test] - pip install --progress-bar off .[optional] - pip install --progress-bar off .[integration] - pip install "distributed<2023.3.2" - - - name: Output installed packages - run: | - pip freeze --all - - name: Output dependency tree - run: | - pip install pipdeptree - pipdeptree - - - name: Tests - # Skip allennlp tests since it's not supported on Windows. - run: | - pytest tests -m "integration" ` - --ignore tests/integration_tests/allennlp_tests/test_allennlp.py ` - env: - OMP_NUM_THREADS: 1 diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index d16f5ab5d5..85831d9b66 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -26,12 +26,13 @@ class MOTPEMultiObjectiveSampler(BaseMultiObjectiveSampler): """Multi-objective sampler using the MOTPE algorithm. - This sampler is a multiobjective version of :class:`~optuna.samplers.TPESampler`. + This sampler is a multi-objective version of :class:`~optuna.samplers.TPESampler`. .. note:: For `v2.9.0 `_ or later, - MOTPEMultiObjectiveSampler is deprecated and :class:`~optuna.samplers.TPESampler` should be - used instead. The following code shows how you run TPESampler on a multi-objective task: + This sampler is deprecated and :class:`~optuna.samplers.TPESampler` should be + used instead. The following code shows how you run :class:`~optuna.samplers.TPESampler` on + a multi-objective task: .. testcode:: diff --git a/optuna/samplers/_tpe/multi_objective_sampler.py b/optuna/samplers/_tpe/multi_objective_sampler.py index ebd35d1352..a32db024a0 100644 --- a/optuna/samplers/_tpe/multi_objective_sampler.py +++ b/optuna/samplers/_tpe/multi_objective_sampler.py @@ -22,9 +22,33 @@ def _default_weights_above(x: int) -> np.ndarray: class MOTPESampler(TPESampler): """Multi-objective sampler using the MOTPE algorithm. - This sampler is a multiobjective version of :class:`~optuna.samplers.TPESampler`. + This sampler is a multi-objective version of :class:`~optuna.samplers.TPESampler`. - For further information about MOTPE algorithm, please refer to the following paper: + .. note:: + For `v2.9.0 `_ or later, + This sampler is deprecated and :class:`~optuna.samplers.TPESampler` should be + used instead. The following code shows how you run :class:`~optuna.samplers.TPESampler` on + a multi-objective task: + + .. testcode:: + + import optuna + + + def objective(trial): + x = trial.suggest_float("x", -100, 100) + y = trial.suggest_categorical("y", [-1, 0, 1]) + f1 = x**2 + y + f2 = -((x - 2) ** 2 + y) + return f1, f2 + + + # We minimize the first objective and the second objective. + sampler = optuna.samplers.TPESampler() + study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) + study.optimize(objective, n_trials=100) + + For further information about MOTPE algorithm, please refer to the following papers: - `Multiobjective tree-structured parzen estimator for computationally expensive optimization problems `_ diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index 59a04b4f20..7a7157af91 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -78,6 +78,7 @@ class TPESampler(BaseSampler): Better Empirical Performance `_ For multi-objective TPE (MOTPE), please refer to the following papers: + - `Multiobjective Tree-Structured Parzen Estimator for Computationally Expensive Optimization Problems `_ - `Multiobjective Tree-Structured Parzen Estimator `_ @@ -101,8 +102,8 @@ def objective(trial): .. note:: For `v2.9.0 `_ or later, - :class:`~optuna.samplers.MOTPESampler` is deprecated and TPESampler should be used instead. - The following code shows how you run TPESampler on a multi-objective task: + :class:`~optuna.samplers.MOTPESampler` is deprecated and this sampler should be used + instead. The following code shows how you apply this sampler to a multi-objective task: .. testcode:: From 96d3c564e7c1f5a4af0632f3fabc5300f3fef74c Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 1 Nov 2023 06:58:24 +0100 Subject: [PATCH 04/12] Revert tests --- .github/workflows/mac-tests.yml | 138 ++++++++++++++++++ .github/workflows/tests-integration.yml | 78 ++++++++++ .github/workflows/tests-mpi.yml | 82 +++++++++++ .github/workflows/tests-storage.yml | 130 +++++++++++++++++ .../workflows/tests-with-minimum-versions.yml | 92 ++++++++++++ .github/workflows/tests.yml | 89 +++++++++++ .github/workflows/windows-tests.yml | 135 +++++++++++++++++ 7 files changed, 744 insertions(+) diff --git a/.github/workflows/mac-tests.yml b/.github/workflows/mac-tests.yml index e69de29bb2..526d6795d4 100644 --- a/.github/workflows/mac-tests.yml +++ b/.github/workflows/mac-tests.yml @@ -0,0 +1,138 @@ +# Run tests and integration tests on Mac, which are triggered by each master push. +# Currently, Python3.8 is only used as an environment. +# This is mainly for the sake of speed. +name: mac-tests + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + tests-mac: + runs-on: macos-latest + + # Scheduled Tests are disabled for forks. + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python3.8 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test + with: + path: ~/Library/Caches/pip + key: ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Install + run: | + python -m pip install --upgrade pip + pip install --progress-bar off -U setuptools + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + + - name: Scheduled tests + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + run: | + pytest tests -m "not integration" + - name: Tests + if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} + run: | + pytest tests -m "not integration and not slow" + + + tests-integration-mac: + runs-on: macos-latest + + # Scheduled Tests are disabled for forks. + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python3.8 + uses: actions/setup-python@v4 + with: + python-version: 3.8 + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test-integration + with: + path: ~/Library/Caches/pip + key: ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-3.8-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Setup mac environment + run: | + brew install libomp + brew install open-mpi + brew install openblas + + - name: Install + run: | + python -m pip install --upgrade pip + + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] + pip install --progress-bar off .[integration] + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + + - name: Tests + run: | + pytest tests -m "integration" + + env: + OMP_NUM_THREADS: 1 + + - name: Tests MPI + run: | + export OMPI_MCA_rmaps_base_oversubscribe=yes + mpirun -n 2 -- pytest tests/integration_tests/test_pytorch_distributed.py + env: + OMP_NUM_THREADS: 1 diff --git a/.github/workflows/tests-integration.yml b/.github/workflows/tests-integration.yml index e69de29bb2..2255fc11cc 100644 --- a/.github/workflows/tests-integration.yml +++ b/.github/workflows/tests-integration.yml @@ -0,0 +1,78 @@ +name: Tests (Integration) + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + tests-integration: + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test-integration + with: + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Setup environment + run: | + sudo apt-get update + sudo apt-get -y install openmpi-bin libopenmpi-dev libopenblas-dev + + - name: Install + run: | + python -m pip install --upgrade pip + + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu + pip install --progress-bar off .[integration] --extra-index-url https://download.pytorch.org/whl/cpu + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Scheduled tests + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + run: | + pytest tests -m "integration" + + - name: Tests + if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} + run: | + pytest tests -m "integration and not slow" diff --git a/.github/workflows/tests-mpi.yml b/.github/workflows/tests-mpi.yml index e69de29bb2..3ea1f1f46f 100644 --- a/.github/workflows/tests-mpi.yml +++ b/.github/workflows/tests-mpi.yml @@ -0,0 +1,82 @@ +name: Tests (MPI) + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + tests-mpi: + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test-mpi + with: + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Setup environment + run: | + sudo apt-get update + sudo apt-get -y install openmpi-bin libopenmpi-dev + + - name: Install + run: | + python -m pip install --upgrade pip + + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu + + # TODO(not522): Remove this line when torchmetrics can be installed with extra-index-url + pip install --progress-bar off torchmetrics + + pip install --progress-bar off .[integration] --extra-index-url https://download.pytorch.org/whl/cpu + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Tests + run: | + export OMPI_MCA_rmaps_base_oversubscribe=yes + + if [ ${{ matrix.python-version }} != 3.11 ]; then + mpirun -n 2 -- pytest tests/integration_tests/test_pytorch_distributed.py + fi + + env: + OMP_NUM_THREADS: 1 diff --git a/.github/workflows/tests-storage.yml b/.github/workflows/tests-storage.yml index e69de29bb2..bf45161d2c 100644 --- a/.github/workflows/tests-storage.yml +++ b/.github/workflows/tests-storage.yml @@ -0,0 +1,130 @@ +name: Tests (Storage with server) + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + # TODO(masap): Modify job name to "tests-storage-with-server" because this test is not only for + # RDB. Since current name "tests-rdbstorage" is required in the Branch protection rules, you + # need to modify the Branch protection rules as well. + tests-rdbstorage: + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + + services: + mysql: + image: mysql:5.7 + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: mandatory_arguments + MYSQL_DATABASE: optunatest + MYSQL_USER: user + MYSQL_PASSWORD: test + options: >- + --health-cmd "mysqladmin ping -h localhost" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + postgres: + image: postgres:10.1-alpine + ports: + - 5432:5432 + env: + POSTGRES_DB: optunatest + POSTGRES_USER: user + POSTGRES_PASSWORD: test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + redis: + image: redis + ports: + - 6379:6379 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test-storage-with-server + with: + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Setup environment + run: | + sudo apt-get update + sudo apt-get -y install openmpi-bin libopenmpi-dev + + - name: Install + run: | + python -m pip install --upgrade pip + pip install --progress-bar off -U setuptools + + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu + + - name: Install DB bindings + run: | + pip install --progress-bar off PyMySQL cryptography psycopg2-binary redis + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Tests MySQL + run: | + pytest tests/storages_tests/test_with_server.py + env: + SQLALCHEMY_WARN_20: 1 + OMP_NUM_THREADS: 1 + TEST_DB_URL: mysql+pymysql://user:test@127.0.0.1/optunatest + + - name: Tests PostgreSQL + run: | + pytest tests/storages_tests/test_with_server.py + env: + OMP_NUM_THREADS: 1 + TEST_DB_URL: postgresql+psycopg2://user:test@127.0.0.1/optunatest + + - name: Tests Journal Redis + run: | + pytest tests/storages_tests/test_with_server.py + env: + OMP_NUM_THREADS: 1 + TEST_DB_URL: redis://localhost:6379 + TEST_DB_MODE: journal-redis diff --git a/.github/workflows/tests-with-minimum-versions.yml b/.github/workflows/tests-with-minimum-versions.yml index e69de29bb2..679d9ef7e6 100644 --- a/.github/workflows/tests-with-minimum-versions.yml +++ b/.github/workflows/tests-with-minimum-versions.yml @@ -0,0 +1,92 @@ +name: Tests with minimum versions + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + tests-with-minimum-versions: + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9'] + + services: + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test-with-minimum-versions + with: + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/setup.py') }}-v1 + restore-keys: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/setup.py') }} + + + - name: Setup pip + run: | + python -m pip install --upgrade pip + pip install --progress-bar off -U setuptools + + - name: Install + run: | + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu + + - name: Install dependencies with minimum versions + run: | + # Install dependencies with minimum versions. + pip uninstall -y alembic cmaes packaging sqlalchemy plotly scikit-learn + pip install alembic==1.5.0 cmaes==0.10.0 packaging==20.0 sqlalchemy==1.3.0 numpy==1.20.3 tqdm==4.27.0 colorlog==0.3 PyYAML==5.1 + pip install plotly==5.0.0 scikit-learn==0.24.2 # optional extras + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Scheduled tests + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + run: | + pytest tests -m "not integration" + + - name: Tests + if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} + run: | + pytest tests -m "not integration and not slow" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e69de29bb2..4c8d172139 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -0,0 +1,89 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + tests: + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + + services: + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: test + with: + path: ~/.cache/pip + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + + - name: Setup pip + run: | + python -m pip install --upgrade pip + pip install --progress-bar off -U setuptools + + - name: Install + run: | + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] --extra-index-url https://download.pytorch.org/whl/cpu + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Scheduled tests + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + run: | + pytest tests -m "not integration" + env: + SQLALCHEMY_WARN_20: 1 + + - name: Tests + if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} + run: | + pytest tests -m "not integration and not slow" + env: + SQLALCHEMY_WARN_20: 1 diff --git a/.github/workflows/windows-tests.yml b/.github/workflows/windows-tests.yml index e69de29bb2..7b46856277 100644 --- a/.github/workflows/windows-tests.yml +++ b/.github/workflows/windows-tests.yml @@ -0,0 +1,135 @@ +# Run tests and integration tests on Windows, which are triggered by each master push. +# Currently, Python3.9 is only used as an environment. +# This is mainly for the sake of speed. +name: windows-tests + +on: + push: + branches: + - master + pull_request: {} + schedule: + - cron: '0 23 * * SUN-THU' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }} + cancel-in-progress: true + +jobs: + tests-windows: + runs-on: windows-latest + + # Not intended for forks. + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python3.9 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: windows-test + with: + path: ~\\AppData\\Local\\pip\\Cache + key: ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Install + run: | + python -m pip install --upgrade pip + pip install --progress-bar off -U setuptools + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] + pip install PyQt6 # Install PyQT for using QtAgg as matplotlib backend. + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Scheduled tests + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + run: | + pytest -m "not integration" + env: + SQLALCHEMY_WARN_20: 1 + MPLBACKEND: "QtAgg" # Use QtAgg as matplotlib backend. + + - name: Tests + if: ${{ github.event_name != 'schedule' && github.event_name != 'workflow_dispatch' }} + run: | + pytest -m "not integration and not slow" + env: + MPLBACKEND: "QtAgg" # Use QtAgg as matplotlib backend. + + tests-integration-windows: + runs-on: windows-latest + + # Not intended for forks. + if: (github.event_name == 'schedule' && github.repository == 'optuna/optuna') || (github.event_name != 'schedule') + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Python3.9 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + + - name: Setup cache + uses: actions/cache@v3 + env: + cache-name: windows-test-integration + with: + path: ~\\AppData\\Local\\pip\\Cache + key: ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}-v1 + restore-keys: | + ${{ runner.os }}-3.9-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }} + + - name: Setup MPI + uses: mpi4py/setup-mpi@v1 + with: + mpi: "msmpi" + + - name: Install + run: | + python -m pip install --upgrade pip + pip install --progress-bar off -U setuptools + # Install minimal dependencies and confirm that `import optuna` is successful. + pip install --progress-bar off . + python -c 'import optuna' + optuna --version + pip install --progress-bar off .[test] + pip install --progress-bar off .[optional] + pip install --progress-bar off .[integration] + pip install "distributed<2023.3.2" + + - name: Output installed packages + run: | + pip freeze --all + - name: Output dependency tree + run: | + pip install pipdeptree + pipdeptree + + - name: Tests + # Skip allennlp tests since it's not supported on Windows. + run: | + pytest tests -m "integration" ` + --ignore tests/integration_tests/allennlp_tests/test_allennlp.py ` + env: + OMP_NUM_THREADS: 1 From ef4c60453192e907caf9bf1eee24636655dc464b Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 1 Nov 2023 07:00:29 +0100 Subject: [PATCH 05/12] Modify an expression a bit --- optuna/multi_objective/samplers/_motpe.py | 6 +++--- optuna/samplers/_tpe/multi_objective_sampler.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index 85831d9b66..5add0c5e86 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -31,8 +31,8 @@ class MOTPEMultiObjectiveSampler(BaseMultiObjectiveSampler): .. note:: For `v2.9.0 `_ or later, This sampler is deprecated and :class:`~optuna.samplers.TPESampler` should be - used instead. The following code shows how you run :class:`~optuna.samplers.TPESampler` on - a multi-objective task: + used instead. The following code shows how you apply :class:`~optuna.samplers.TPESampler` + to a multi-objective task: .. testcode:: @@ -52,7 +52,7 @@ def objective(trial): study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) study.optimize(objective, n_trials=100) - For further information about MOTPE algorithm, please refer to the following paper: + For further information about MOTPE algorithm, please refer to the following papers: - `Multiobjective tree-structured parzen estimator for computationally expensive optimization problems `_ diff --git a/optuna/samplers/_tpe/multi_objective_sampler.py b/optuna/samplers/_tpe/multi_objective_sampler.py index a32db024a0..cee92163f7 100644 --- a/optuna/samplers/_tpe/multi_objective_sampler.py +++ b/optuna/samplers/_tpe/multi_objective_sampler.py @@ -27,8 +27,8 @@ class MOTPESampler(TPESampler): .. note:: For `v2.9.0 `_ or later, This sampler is deprecated and :class:`~optuna.samplers.TPESampler` should be - used instead. The following code shows how you run :class:`~optuna.samplers.TPESampler` on - a multi-objective task: + used instead. The following code shows how you apply :class:`~optuna.samplers.TPESampler` + to a multi-objective task: .. testcode:: From b078625d859d7eb3608cf4e1ca0a824a0d8ad61b Mon Sep 17 00:00:00 2001 From: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com> Date: Thu, 2 Nov 2023 08:59:18 +0100 Subject: [PATCH 06/12] Add a missing `maximize` in the comment Co-authored-by: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com> --- optuna/samplers/_tpe/sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index 7a7157af91..abe403aa30 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -118,7 +118,7 @@ def objective(trial): return f1, f2 - # We minimize the first objective and the second objective. + # We minimize the first objective and maximize the second objective. sampler = optuna.samplers.TPESampler() study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) study.optimize(objective, n_trials=100) From ccd49d9f4b92633352e1921696fba9f82f79431a Mon Sep 17 00:00:00 2001 From: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:00:18 +0100 Subject: [PATCH 07/12] Add a missing `maximize` in the comment Co-authored-by: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com> --- optuna/multi_objective/samplers/_motpe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index 5add0c5e86..e116b453d8 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -47,7 +47,7 @@ def objective(trial): return f1, f2 - # We minimize the first objective and the second objective. + # We minimize the first objective and maximize the second objective. sampler = optuna.samplers.TPESampler() study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) study.optimize(objective, n_trials=100) From 5e25b9455e892fd2796fc30f7ec7bad33461e475 Mon Sep 17 00:00:00 2001 From: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:10:23 +0100 Subject: [PATCH 08/12] Add self-referencing of `TPESampler` in _tpe.sampler.py Co-authored-by: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com> --- optuna/samplers/_tpe/sampler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index abe403aa30..128a060e5c 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -102,8 +102,9 @@ def objective(trial): .. note:: For `v2.9.0 `_ or later, - :class:`~optuna.samplers.MOTPESampler` is deprecated and this sampler should be used - instead. The following code shows how you apply this sampler to a multi-objective task: + :class:`~optuna.samplers.MOTPESampler` is deprecated and + :class:`~optuna.samplers.TPESampler` should be used instead. The following code shows + how you apply :class:`~optuna.samplers.TPESampler` to a multi-objective task: .. testcode:: From 131bbaad1cbacbc5fdd27955b9246adb3aa9dd36 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Thu, 2 Nov 2023 09:19:37 +0100 Subject: [PATCH 09/12] Remove the ref of the TPE paper --- optuna/samplers/_tpe/sampler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index 128a060e5c..8ed6f834e9 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -74,8 +74,6 @@ class TPESampler(BaseSampler): `_ - `Making a Science of Model Search: Hyperparameter Optimization in Hundreds of Dimensions for Vision Architectures `_ - - `Tree-Structured Parzen Estimator: Understanding Its Algorithm Components and Their Roles for - Better Empirical Performance `_ For multi-objective TPE (MOTPE), please refer to the following papers: From ef8cc4b2aa0223d600a3525080c1b09a79fbd8bf Mon Sep 17 00:00:00 2001 From: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:36:43 +0100 Subject: [PATCH 10/12] Add a missing `maximize` in the comment Co-authored-by: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com> --- optuna/samplers/_tpe/multi_objective_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna/samplers/_tpe/multi_objective_sampler.py b/optuna/samplers/_tpe/multi_objective_sampler.py index cee92163f7..83565dacde 100644 --- a/optuna/samplers/_tpe/multi_objective_sampler.py +++ b/optuna/samplers/_tpe/multi_objective_sampler.py @@ -43,7 +43,7 @@ def objective(trial): return f1, f2 - # We minimize the first objective and the second objective. + # We minimize the first objective and maximize the second objective. sampler = optuna.samplers.TPESampler() study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler) study.optimize(objective, n_trials=100) From 42eb9ebea2806e862c1f9bd9b28ea495b7078c21 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Mon, 6 Nov 2023 09:22:51 +0100 Subject: [PATCH 11/12] Fix the deprecated versions in the doc --- optuna/multi_objective/samplers/_motpe.py | 8 ++++---- optuna/samplers/_tpe/multi_objective_sampler.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/optuna/multi_objective/samplers/_motpe.py b/optuna/multi_objective/samplers/_motpe.py index e116b453d8..9f358b798a 100644 --- a/optuna/multi_objective/samplers/_motpe.py +++ b/optuna/multi_objective/samplers/_motpe.py @@ -29,10 +29,10 @@ class MOTPEMultiObjectiveSampler(BaseMultiObjectiveSampler): This sampler is a multi-objective version of :class:`~optuna.samplers.TPESampler`. .. note:: - For `v2.9.0 `_ or later, - This sampler is deprecated and :class:`~optuna.samplers.TPESampler` should be - used instead. The following code shows how you apply :class:`~optuna.samplers.TPESampler` - to a multi-objective task: + For `v2.4.0 `_ or later, + :class:`~optuna.multi_objective.samplers.MOTPEMultiObjectiveSampler` is deprecated and + :class:`~optuna.samplers.TPESampler` should be used instead. The following code shows how + you apply :class:`~optuna.samplers.TPESampler` to a multi-objective task: .. testcode:: diff --git a/optuna/samplers/_tpe/multi_objective_sampler.py b/optuna/samplers/_tpe/multi_objective_sampler.py index 83565dacde..6f9ff9f78e 100644 --- a/optuna/samplers/_tpe/multi_objective_sampler.py +++ b/optuna/samplers/_tpe/multi_objective_sampler.py @@ -26,9 +26,9 @@ class MOTPESampler(TPESampler): .. note:: For `v2.9.0 `_ or later, - This sampler is deprecated and :class:`~optuna.samplers.TPESampler` should be - used instead. The following code shows how you apply :class:`~optuna.samplers.TPESampler` - to a multi-objective task: + :class:`~optuna.samplers.MOTPESampler` is deprecated and + :class:`~optuna.samplers.TPESampler` should be used instead. The following code shows how + you apply :class:`~optuna.samplers.TPESampler` to a multi-objective task: .. testcode:: From 3b0e58ee5fc5401851a381ac964c055ce1c6137e Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Mon, 6 Nov 2023 09:35:26 +0100 Subject: [PATCH 12/12] Address the comment by knshnb --- optuna/samplers/_tpe/sampler.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/optuna/samplers/_tpe/sampler.py b/optuna/samplers/_tpe/sampler.py index 8ed6f834e9..b8a6aaa13d 100644 --- a/optuna/samplers/_tpe/sampler.py +++ b/optuna/samplers/_tpe/sampler.py @@ -99,10 +99,8 @@ def objective(trial): study.optimize(objective, n_trials=10) .. note:: - For `v2.9.0 `_ or later, - :class:`~optuna.samplers.MOTPESampler` is deprecated and - :class:`~optuna.samplers.TPESampler` should be used instead. The following code shows - how you apply :class:`~optuna.samplers.TPESampler` to a multi-objective task: + :class:`~optuna.samplers.TPESampler` can handle a multi-objective task as well and + the following shows an example: .. testcode::