in code/src/utils.py [0:0]
def get_dump_path(params):
"""
Create a directory to store the experiment.
"""
assert params.dump_path != ''
dump_path = params.dump_path
assert len(params.name) > 0
assert os.path.isdir(dump_path)
# create the sweep path if it does not exist
sweep_path = os.path.join(dump_path, params.name)
if not os.path.exists(sweep_path):
subprocess.Popen("mkdir %s" % sweep_path, shell=True).wait()
# create an ID for the job if it is not given in the parameters.
# if we run on the cluster, the job ID is the one of Chronos.
# otherwise, it is randomly generated
if params.exp_id == '':
exp_id = None # os.environ.get('EXP_ID')
if exp_id is None:
exp_id = os.environ.get('CHRONOS_JOB_ID')
if exp_id is None:
exp_id = os.environ.get('SLURM_JOB_ID')
if exp_id is None:
chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
while True:
exp_id = ''.join(random.choice(chars) for _ in range(10))
if not os.path.isdir(os.path.join(sweep_path, exp_id)):
break
else:
assert exp_id.isdigit()
params.exp_id = exp_id
# else:
# assert os.path.isdir(os.path.join(sweep_path, params.exp_id)) # reload an experiment
# create the dump folder / update parameters
params.dump_path = os.path.join(sweep_path, params.exp_id)
if not os.path.isdir(params.dump_path):
subprocess.Popen("mkdir %s" % params.dump_path, shell=True).wait()