question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to convert study.pkl to study.db?

See original GitHub issue

Note to the questioner

1.As a new user of Optuna, I really love it. However, in the beginning I saved an existing study to .pkl file, but now I wish to convert it to RDB backend in order to perform the parallelization . How can I have that?

I may wish something like

existing_study=joblib.load("existing_study.pkl")

#save it to .db file
existing_study.save( 'sql_base.db')

Is there any solution?

  1. In addition, how can I list all study names which have been saved in .db file? Sorry, I do not have so much knowledge in RDB also…

Thank you in advance.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:14

github_iconTop GitHub Comments

4reactions
nzw0301commented, Mar 16, 2021

I think the following way should work.

Let’s assume that we have finished a few trials and saved the study as existing_study.pkl.

import optuna
import joblib


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

study = optuna.create_study()
study.optimize(objective, n_trials=3)

joblib.dump(study, "existing_study.pkl")

Then we load the existing_study.pkl and save the study into a database, example.db. I think that can be done by using create_new_study and create_new_trial.

import optuna
import joblib


study = joblib.load("existing_study.pkl")

storage = optuna.storages.RDBStorage(
    url="sqlite:///example.db"
)
study_id = storage.create_new_study(study_name="study_on_db")

for trial in study.get_trials():
    storage.create_new_trial(study_id=study_id, template_trial=trial)

study = optuna.load_study(study_name="study_on_db", storage=storage)

study.optimize(objective, n_trials=10)

len(study.get_trials())  # == 13
1reaction
yywangvrcommented, Mar 17, 2021

Thank you again. I guess this may because I run Optuna in two processes as indicated in here, and therefore I do not have values but obtain intermediate_values instead.

When I retry my code in one process, everything seems fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQ — Optuna 3.0.4 documentation
study = optuna.create_study() joblib.dump(study, "study.pkl") ... You can change logging levels by using optuna.logging.set_verbosity() .
Read more >
How to put my dataset in a .pkl file in the exact format and data ...
I use the code in this address: DBN full code. This code use the MNIST Handwritten database. This file is already in pickle...
Read more >
Optuna vs Hyperopt: Which Hyperparameter Optimization ...
artifacts/study.pkl') study.optimize(objective, n_trials=200). That's it. For distributed setups you can use the name of the study the URL to the database ...
Read more >
Save and Load Machine Learning Models in Python with scikit ...
Covers self-study tutorials and end-to-end projects like: Loading data, visualization, modeling, tuning, and much more... Finally Bring Machine ...
Read more >
faqs.pdf - PKL Software
www.pklsoftware.com/disabling_popup_blockers.htm ... 'Change User Data' in the software program and make any change you would like.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found