pypi optuna 4.1.0
v4.1.0

one month ago

This is the release note of v4.1.0. Highlights of this release include:

  • 🤖 AutoSampler: Automatic Selection of Optimization Algorithms
  • 🚀 More scalable RDB Storage Backend
  • 🧑‍💻 Five New Algorithms in OptunaHub (MO-CMA-ES, MOEA/D, etc.)
  • 🐍 Support Python 3.13

The updated list of tested and supported Python releases is as follows:

Highlights

AutoSampler: Automatic Selection of Optimization Algorithms

Blog-1

AutoSampler automatically selects a sampler from those implemented in Optuna, depending on the situation. Using AutoSampler, as in the code example below, users can achieve optimization performance equal to or better than Optuna's default without being aware of which optimization algorithm to use.

$ pip install optunahub cmaes torch scipy
import optuna
import optunahub

auto_sampler_module = optunahub.load_module("samplers/auto_sampler")
study = optuna.create_study(sampler=auto_sampler_module.AutoSampler())

See the Medium blog post for details.

Enhanced RDB Storage Backend

This release incorporates comprehensive performance tuning on Optuna’s RDBStorage, leading to significant performance improvements. The table below shows the comparison results of execution times between versions 4.0 and 4.1.

# trials v4.0.0 v4.1.0 Diff
1000 72.461 sec (±1.026) 59.706 sec (±1.216) -17.60%
10000 1153.690 sec (±91.311) 664.830 sec (±9.951) -42.37%
50000 12118.413 sec (±254.870) 4435.961 sec (±190.582) -63.39%

For fair comparison, all experiments were repeated 10 times, and the mean execution time was compared. Additional detailed benchmark settings include the following:

  • Objective Function: Each trial consists of 10 parameters and 10 user attributes
  • Storage: MySQL 8.0 (with PyMySQL)
  • Sampler: RandomSampler
  • Execution Environment: Kubernetes Pod with 5 cpus and 8Gi RAM

Please note, due to extensive execution time, the figure for v4.0.0 with 50,000 trials represents the average of 7 runs instead of 10.

Benchmark Script
import optuna
import time
import os
import numpy as np

optuna.logging.set_verbosity(optuna.logging.ERROR)
storage_url = "mysql+pymysql://user:password@<ipaddr>:<port>/<dbname>"
n_repeat = 10

def objective(trial: optuna.Trial) -> float:
    s = 0
    for i in range(10):
        trial.set_user_attr(f"attr{i}", "dummy user attribute")
        s += trial.suggest_float(f"x{i}", -10, 10) ** 2
    return s


def bench(n_trials):
    elapsed = []
    for i in range(n_repeat):
        start = time.time()
        study = optuna.create_study(
            storage=storage_url,
            sampler=optuna.samplers.RandomSampler()
        )
        study.optimize(objective, n_trials=n_trials, n_jobs=10)
        elapsed.append(time.time() - start)
        optuna.delete_study(study_name=study.study_name, storage=storage_url)
    print(f"{np.mean(elapsed)=} {np.std(elapsed)=}")


for n_trials in [1000, 10000, 50000]:
    bench(n_trials)

Five New Algorithms in OptunaHub (MO-CMA-ES, MOEA/D, etc.)

The following five new algorithms were added to OptunaHub!

MO-CMA-ES is an extension of CMA-ES for multi-objective optimization. Its search mechanism is based on multiple (1+1)-CMA-ES and inherits good invariance properties from CMA-ES, such as invariance against rotation of the search space.

mocmaes

MOEA/D solves a multi-objective optimization problem by decomposing it into multiple single-objective problems. It allows for the maintenance of a good diversity of solutions during optimization. Please take a look at the article from Hiroaki NATSUME(@hrntsm) for more details.

moead

Enhancements

  • Update sklearn.py by addind catch to OptunaSearchCV (optuna/optuna-integration#163, thanks @muhlbach!)
  • Reduce SELECT statements by passing study_id to check_and_add in TrialParamModel (#5702)
  • Introduce UPSERT in set_trial_user_attr (#5703)
  • Reduce SELECT statements of _CachedStorage.get_all_trials by fixing filtering conditions (#5704)
  • Reduce SELECT statements by removing unnecessary distribution compatibility check in set_trial_param() (#5709)
  • Introduce UPSERT in set_trial_system_attr (#5741)

Bug Fixes

Installation

  • Drop the support for Python 3.7 and update package metadata for Python 3.13 support (#5727)
  • Remove dependency specifier for installing SciPy (#5736)

Documentation

  • Add badges of PyPI and Conda Forge (optuna/optuna-integration#167)
  • Update news (#5655)
  • Update news section in README.md (#5657)
  • Add InMemoryStorage to document (#5672, thanks @kAIto47802!)
  • Add the news about blog of JournalStorage to README.md (#5674)
  • Fix broken link in the artifacts tutorial (#5677, thanks @kAIto47802!)
  • Add pandas installation guide to RDB tutorial (#5685, thanks @kAIto47802!)
  • Add installation guide to multi-objective tutorial (#5686, thanks @kAIto47802!)
  • Update document and notice interoperability between NSGA-II and Pruners (#5688)
  • Fix typo in EMMREvaluator (#5694)
  • Fix RegretBoundEvaluator document (#5696)
  • Update news section in README.md (#5705)
  • Add link to related blog post in emmr.py (#5707)
  • Update FAQ entry for model preservation using Optuna Artifact (#5716, thanks @chitvs!)
  • Escape \D for Python 3.12 with sphinx build (#5735)
  • Avoid using functions in sphinx_gallery_conf to remove document build error with Python 3.12 (#5738)
  • Remove all generated directories in docs/source recursively (#5739)
  • Add information about AutoSampler to the docs (#5745)

Examples

Code Fixes

  • Add a comment for an unexpected bug in CategoricalDistribution (#5683)
  • Add more information about the hack in WFG (#5687)
  • Simplify type annotations to _imports.py (#5692, thanks @Prabhat-Thapa45!)
  • Use __future__.annotations in optuna/_experimental.py (#5714, thanks @Jonathan43!)
  • Use __future__.annotations in tests/importance_tests/fanova_tests/test_tree.py (#5731, thanks @guisp03!)
  • Resolve TODO comments related to dropping Python 3.7 support (#5734)

Continuous Integration

Other

Thanks to All the Contributors!

This release was made possible by the authors and the people who participated in the reviews and discussions.

@HideakiImamura, @Jonathan43, @Prabhat-Thapa45, @c-bata, @chitvs, @contramundum53, @eukaryo, @gen740, @guisp03, @kAIto47802, @muhlbach, @nabenabe0928, @not522, @nzw0301, @porink0424, @toshihikoyanase, @y0z, @yu9824

Don't miss a new optuna release

NewReleases is sending notifications on new releases.