jrbourbeau / dask-optuna

Scale Optuna with Dask
https://jrbourbeau.github.io/dask-optuna/
MIT License
35 stars 6 forks source link

Optuna 2.0 | distributed.core - ERROR - Exception while handling op optuna_get_trial #23

Closed aaronchann1227 closed 2 years ago

aaronchann1227 commented 2 years ago

Select Package Versions

dask_optuna: 0.0.2
optuna: 2.0.0
distributed: 2022.01.0

Execute example script

import joblib
import optuna
import dask.distributed
import dask_optuna

def objective(trial):
    x = trial.suggest_uniform("x", -10, 10)
    return (x - 2) ** 2

with dask.distributed.Client() as client:
    # Create a study using Dask-compatible storage
    storage = dask_optuna.DaskStorage()
    study = optuna.create_study(storage=storage)
    # Optimize in parallel on your Dask cluster
    with joblib.parallel_backend("dask"):
        study.optimize(objective, n_trials=100, n_jobs=-1)
    print(f"best_params = {study.best_params}")

error message:

distributed.core - ERROR - Exception while handling op optuna_get_trial
Traceback (most recent call last):
  File "/home/mcchan3/.conda/envs/dask_optuna_test2/lib/python3.7/site-packages/distributed/core.py", line 516, in handle_comm
    result = handler(comm, **msg)
  File "/home/mcchan3/.conda/envs/dask_optuna_test2/lib/python3.7/site-packages/dask_optuna/storage.py", line 244, in get_trial
    return serialize_frozentrial(trial)
  File "/home/mcchan3/.conda/envs/dask_optuna_test2/lib/python3.7/site-packages/dask_optuna/serialize.py", line 32, in serialize_frozentrial
    data[attr] = data.pop(f"_{attr}")
KeyError: '_number'

What seems to be the problem here? Thank you!

aaronchann1227 commented 2 years ago

Fixed after update Optuna to 2.3.0