Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# so we ignore it.
return None
success = True
try:
seml_config = exp['seml']
slurm_config = exp['slurm']
if use_stored_sources:
random_int = np.random.randint(0, 999999)
temp_dir = f"/tmp/{random_int}"
while os.path.exists(temp_dir):
random_int = np.random.randint(0, 999999)
temp_dir = f"/tmp/{random_int}"
os.mkdir(temp_dir, mode=0o700)
load_sources_from_db(exp, collection, to_directory=temp_dir)
# update the command to use the temp dir
cmd = f'PYTHONPATH="{temp_dir}:$PYTHONPATH" python {temp_dir}/{exe} with {" ".join(config)}'
if 'conda_environment' in seml_config and seml_config['conda_environment'] is not None:
cmd = (f". $(conda info --base)/etc/profile.d/conda.sh "
f"&& conda activate {seml_config['conda_environment']} "
f"&& {cmd} "
f"&& conda deactivate")
logging.verbose(f'Running the following command:\n {cmd}')
if output_dir_path:
exp_name = get_exp_name(exp, collection.name)
output_file = f"{output_dir_path}/{exp_name}_{exp['_id']}.out"
collection.find_and_modify({'_id': exp['_id']}, {"$set": {"seml.output_file": output_file}})
with open(output_file, "w") as log_file:
help="Activate post-mortem debugging with pdb.")
parser.add_argument("--stored-sources-dir", default=None, type=str,
help="Load source files into this directory before starting.")
args = parser.parse_args()
exp_id = args.experiment_id
db_collection_name = args.db_collection_name
collection = get_collection(db_collection_name)
exp = collection.find_one({'_id': exp_id})
use_stored_sources = args.stored_sources_dir is not None
if use_stored_sources and not os.listdir(args.stored_sources_dir):
assert "source_files" in exp['seml'],\
"--stored-sources-dir was supplied but queued experiment does not contain stored source files."
load_sources_from_db(exp, collection, to_directory=args.stored_sources_dir)
exe, config = get_command_from_exp(exp, db_collection_name, verbose=args.verbose,
unobserved=args.unobserved, post_mortem=args.post_mortem)
config_args = ' '.join(config)
cmd = f"python {exe} with {config_args}"
if use_stored_sources:
# add command without the temp_dir prefix
# also add the temp dir for debugging purposes
collection.update_one(
{'_id': exp_id},
{'$set': {'seml.command': cmd, 'seml.temp_dir': args.stored_sources_dir}})
# add the temp_dir prefix to the command
cmd = f"python {args.stored_sources_dir}/{exe} with {config_args}"
else:
collection.update_one(