Skip to content

derakding/optuna-examples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optuna Examples

This page contains a list of example codes written with Optuna.

The simplest codeblock looks like this:

import optuna


def objective(trial):
    x = trial.suggest_float("x", -100, 100)
    return x ** 2


if __name__ == "__main__":
    study = optuna.create_study()
    # The optimization finishes after evaluating 1000 times or 3 seconds.
    study.optimize(objective, n_trials=1000, timeout=3)
    print(f"Best params is {study.best_params} with value {study.best_value}")

The examples below provide codeblocks similar to the example above for various different scenarios.

Simple Black-box Optimization

Examples with ML Libraries

An example of Optuna Dashboard

The following example demonstrates how to use Optuna Dashboard.

An example where an objective function uses additional arguments

The following example demonstrates how to implement an objective function that uses additional arguments other than trial.

Examples of Pruning

The following example demonstrates how to implement pruning logic with Optuna.

In addition, integration modules are available for the following libraries, providing simpler interfaces to utilize pruning.

Examples of Samplers

Examples of User-Defined Sampler

Examples of Terminator

Examples of Multi-Objective Optimization

Examples of Visualization

An example to enqueue trials with given parameter values

Examples of aim

Examples of MLflow

Examples of Weights & Biases

Examples of Hydra

Examples of Distributed Optimization

Examples of Reinforcement Learning

External projects using Optuna

PRs to add additional projects welcome!

Running with Optuna's Docker images?

You can use our docker images with the tag ending with -dev to run most of the examples. For example, you can run PyTorch Simple via docker run --rm -v $(pwd):/prj -w /prj optuna/optuna:py3.7-dev python pytorch/pytorch_simple.py. Also, you can try our visualization example in Jupyter Notebook by opening localhost:8888 in your browser after executing this:

docker run -p 8888:8888 --rm optuna/optuna:py3.7-dev jupyter notebook --allow-root --no-browser --port 8888 --ip 0.0.0.0 --NotebookApp.token='' --NotebookApp.password=''

Packages

No packages published

Languages

  • Python 91.0%
  • Jupyter Notebook 7.5%
  • Other 1.5%