optuna.study.copy_study

optuna.study.copy_study(from_study_name, from_storage, to_storage, to_study_name=None)[source]

Copy study from one storage to another.

The direction(s) of the objective(s) in the study, trials, user attributes and system attributes are copied.

Example

import optuna


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


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

optuna.copy_study(
    from_study_name="example-study",
    from_storage="sqlite:///example.db",
    to_storage="sqlite:///example_copy.db",
)

study = optuna.load_study(
    study_name=None,
    storage="sqlite:///example_copy.db",
)
Parameters
  • from_study_name (str) – Name of study.

  • from_storage (Union[str, optuna.storages._base.BaseStorage]) – Source database URL such as sqlite:///example.db. Please see also the documentation of create_study() for further details.

  • to_storage (Union[str, optuna.storages._base.BaseStorage]) – Destination database URL.

  • to_study_name (Optional[str]) – Name of the created study. If omitted, from_study_name is used.

Raises

DuplicatedStudyError – If a study with a conflicting name already exists in the destination storage.

Return type

None

Note

Added in v2.8.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v2.8.0.