@@ -36,28 +36,44 @@ def make_trial_directory(trial):
3636 return cwd
3737
3838
39+ def adjust_path_sqlite (storage , workdir ):
40+ """
41+ Make sure the path for SQLite is located either at an absolute path or relative to the specified workdir
42+ """
43+ if not storage :
44+ return None
45+ if storage .find ("sqlite:///" ) != 0 or not workdir :
46+ return storage
47+ path = storage [10 :]
48+ if path [0 ] == "/" :
49+ # Absolute path
50+ return storage
51+ return "sqlite:///" + join (workdir , path )
52+
53+
3954def load_or_create_study (study_name = None , storage = None , sampler = None , workdir = None ):
4055 """
4156 Helper to load or create a study
4257 Returns tuple of whether it can run via DB interface and optuna.study.study.Study
4358 """
59+ storage = adjust_path_sqlite (storage , workdir )
4460 if study_name and storage :
4561 # there is a database we can connect to for multiprocessing
4662 # Although optuna would come up with a unique name when study_name is None,
4763 # we force a name to be given by the user for those cases
4864 try :
4965 study = optuna .load_study (study_name = study_name , storage = storage , sampler = sampler )
5066 LOG .info (f"Loading existing study { study_name } from storage { storage } " )
67+ return True , study
5168 except KeyError :
5269 study = optuna .create_study (study_name = study_name , storage = storage , sampler = sampler )
5370 LOG .info (f"Creating new study { study_name } at storage { storage } " )
71+ return True , study
5472 except ImportError as exc :
5573 # Probably cannot import MySQL stuff
5674 LOG .info ("Probably cannot import what is needed for database access. Will try to attempt a serial run." )
5775 LOG .info (exc )
58- else :
59- return True , study
60- # This is a "one-time" in-memory study so we don't care so much for the name honestly, could be None
76+
6177 if study_name and workdir :
6278 # Try to see if there is a study saved here
6379 # Pickling is unsafe, we should try to find another way eventually
0 commit comments