def test_copy_study(from_storage_mode: str, to_storage_mode: str) -> None: with StorageSupplier(from_storage_mode) as from_storage, StorageSupplier( to_storage_mode) as to_storage: from_study = create_study(storage=from_storage, directions=["maximize", "minimize"]) from_study.set_system_attr("foo", "bar") from_study.set_user_attr("baz", "qux") from_study.optimize( lambda t: (t.suggest_float("x0", 0, 1), t.suggest_float("x1", 0, 1)), n_trials=3) copy_study( from_study_name=from_study.study_name, from_storage=from_storage, to_storage=to_storage, ) to_study = load_study(study_name=from_study.study_name, storage=to_storage) assert to_study.study_name == from_study.study_name assert to_study.directions == from_study.directions assert to_study.system_attrs == from_study.system_attrs assert to_study.user_attrs == from_study.user_attrs assert len(to_study.trials) == len(from_study.trials)
def test_copy_study_to_study_name(from_storage_mode: str, to_storage_mode: str) -> None: with StorageSupplier(from_storage_mode) as from_storage, StorageSupplier( to_storage_mode ) as to_storage: from_study = create_study(study_name="foo", storage=from_storage) _ = create_study(study_name="foo", storage=to_storage) with pytest.raises(DuplicatedStudyError): copy_study( from_study_name=from_study.study_name, from_storage=from_storage, to_storage=to_storage, ) copy_study( from_study_name=from_study.study_name, from_storage=from_storage, to_storage=to_storage, to_study_name="bar", ) _ = load_study(study_name="bar", storage=to_storage)
import optuna # pip install optuna optuna.create_study() optuna.load_study() optuna.delete_study() optuna.copy_study() optuna.get_all_study_summaries() optuna.TrialPruned trial = Trial(study, trial_id) trial.datetime_start trial.distributions trial.number trial.params trial.system_attrs trial.user_attrs trial.report(value, step) trial.set_system_attr(key, value) trial.set_user_attr(key, value) trial.should_prune() trial.suggest_categorical(name, choices) trial.suggest_discrete_uniform(name, low, high, q) trial.suggest_float(name, low, high, *, ?step, ?log) trial.suggest_int(name, low, high, ?step, ?log) trial.suggest_loguniform(name, low, high) trial.suggest_uniform(name, low, high) #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ import tensorflow as tf from tf import keras