2

Is there a way to be able to pause/kill the optuna study, then resume it either by running the incomplete trials from the beginning, or resuming the incomplete trials from the latest checkpoint?

study = optuna.create_study()
study.optimize(objective)
gameveloster
  • 901
  • 1
  • 6
  • 18

1 Answers1

3

Yes, you can resume an optuna study by using the load_if_exists=True .

For example, if you have a study named 'example-study' and an SQLite file example.db you can:

study = optuna.create_study(study_name='example-study', storage='sqlite:///example.db', load_if_exists=True)
study.optimize(objective, n_trials=3)

You can rerun all the FAIL trials by:

for trial in study.trials:
    if trial.state == optuna.trial.TrialState.FAIL: 
        study.enqueue_trial(trial.params)
study.optimize(objective)

And also, re-evaluate the last trial:

study.enqueue_trial(study.trials[-1].params)
study.optimize(objective, n_trials=1)

will run the objective function with the incomplete trial parameters.