Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions optuna/storages/journal/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,19 @@ def _apply_create_study(self, log: dict[str, Any]) -> None:
study_name = log["study_name"]
directions = [StudyDirection(d) for d in log["directions"]]

if study_name in [s.study_name for s in self._studies.values()]:
if self._is_issued_by_this_worker(log):
raise DuplicatedStudyError(
"Another study with name '{}' already exists. "
"Please specify a different name, or reuse the existing one "
"by setting `load_if_exists` (for Python API) or "
"`--skip-if-exists` flag (for CLI).".format(study_name)
)
return
# Optimize for checking duplicate study name by avoiding list comprehension
# Build a set of current study names for O(1) lookup if studies exist
if self._studies:
study_names = set(s.study_name for s in self._studies.values())
if study_name in study_names:
if self._is_issued_by_this_worker(log):
raise DuplicatedStudyError(
"Another study with name '{}' already exists. "
"Please specify a different name, or reuse the existing one "
"by setting `load_if_exists` (for Python API) or "
"`--skip-if-exists` flag (for CLI).".format(study_name)
)
return

study_id = self._next_study_id
self._next_study_id += 1
Expand Down