0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Optuna の SQLite ストレージ内の study_name をリネームする

0
Posted at

Optuna の SQLite ストレージに保存した study_name を、後からやっぱりリネームしたいとなったときのスクリプトです。

from sqlalchemy import create_engine, text


def rename_study(storage, old_name, new_name):
    engine = create_engine(storage)
    with engine.begin() as conn:
        conn.execute(
            text('update studies set study_name = :new where study_name = :old'),
            {'old': old_name, 'new': new_name},
        )


def print_studies(storage):
    engine = create_engine(storage)
    with engine.connect() as conn:
        rows = conn.execute(text('select * from studies')).mappings().all()
    for row in rows:
        print(dict(row))


storage = 'sqlite:///optuna.db'
print_studies(storage)
rename_study(storage, 'Optuna Adam', 'Optuna 0')
print_studies(storage)
{'study_id': 1, 'study_name': 'Optuna Adam'}
{'study_id': 1, 'study_name': 'Optuna 0'}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?