def _setup_studies( storage: BaseStorage, n_study: int, n_trial: int, seed: int, direction: Optional[StudyDirection] = None, ) -> Tuple[Dict[int, FrozenStudy], Dict[int, Dict[int, FrozenTrial]]]: generator = random.Random(seed) study_id_to_frozen_study: Dict[int, FrozenStudy] = {} study_id_to_trials: Dict[int, Dict[int, FrozenTrial]] = {} for i in range(n_study): study_name = "test-study-name-{}".format(i) study_id = storage.create_new_study(study_name=study_name) if direction is None: direction = generator.choice( [StudyDirection.MINIMIZE, StudyDirection.MAXIMIZE]) storage.set_study_directions(study_id, (direction, )) storage.set_study_user_attr(study_id, "u", i) storage.set_study_system_attr(study_id, "s", i) trials = {} for j in range(n_trial): trial = _generate_trial(generator) trial.number = j trial._trial_id = storage.create_new_trial(study_id, trial) trials[trial._trial_id] = trial study_id_to_trials[study_id] = trials study_id_to_frozen_study[study_id] = FrozenStudy( study_name=study_name, direction=direction, user_attrs={"u": i}, system_attrs={"s": i}, study_id=study_id, ) return study_id_to_frozen_study, study_id_to_trials
def _setup_studies( storage: BaseStorage, n_study: int, n_trial: int, seed: int, direction: Optional[StudyDirection] = None, ) -> Tuple[Dict[int, StudySummary], Dict[int, Dict[int, FrozenTrial]]]: generator = random.Random(seed) study_id_to_summary = {} # type: Dict[int, StudySummary] study_id_to_trials = {} # type: Dict[int, Dict[int, FrozenTrial]] for i in range(n_study): study_name = "test-study-name-{}".format(i) study_id = storage.create_new_study(study_name=study_name) if direction is None: direction = generator.choice( [StudyDirection.MINIMIZE, StudyDirection.MAXIMIZE]) storage.set_study_direction(study_id, direction) best_trial = None trials = {} datetime_start = None for j in range(n_trial): trial = _generate_trial(generator) trial.number = j trial._trial_id = storage.create_new_trial(study_id, trial) trials[trial._trial_id] = trial if datetime_start is None: datetime_start = trial.datetime_start else: datetime_start = min(datetime_start, trial.datetime_start) if trial.state == TrialState.COMPLETE and trial.value is not None: if best_trial is None: best_trial = trial else: if direction == StudyDirection.MINIMIZE and trial.value < best_trial.value: best_trial = trial elif direction == StudyDirection.MAXIMIZE and best_trial.value < trial.value: best_trial = trial study_id_to_trials[study_id] = trials study_id_to_summary[study_id] = StudySummary( study_name=study_name, direction=direction, best_trial=best_trial, user_attrs={}, system_attrs={}, n_trials=len(trials), datetime_start=datetime_start, study_id=study_id, ) return study_id_to_summary, study_id_to_trials