Skip to content

Optuna ​

Record each Optuna trial as a Rundial run.

Start Rundial and create an API key with the Quickstart. Keep the stack running and set RUNDIAL_API_KEY.

Install the packages:

bash
pip install rundial optuna

Create a run in the objective and use a shared group for the trials:

python
import optuna
import rundial as rd

def objective(trial):
    learning_rate = trial.suggest_float("learning_rate", 1e-4, 1e-1, log=True)
    with rd.init(
        workspace="default-workspace", project="default-project",
        name=f"trial-{trial.number}", group="optuna-study", job_type="trial",
        config={"learning_rate": learning_rate},
    ) as run:
        for step in range(10):
            loss = (learning_rate - 0.01) ** 2 + 1 / (step + 1)
            run.log({"loss": loss}, step=step)
        return loss

study = optuna.create_study(direction="minimize")
study.optimize(objective, n_trials=5)

Open Default Project → Train, select Filter, and choose Group under Group by to see the trials together. Open a run's Metrics tab to view its loss chart.

Next steps ​