Skip to content
Snippets Groups Projects
Commit c02c5630 authored by Noordijk, Ben's avatar Noordijk, Ben
Browse files

Bugfixed optimize_hyperparams.py

parent cf2c79f1
No related branches found
No related tags found
1 merge request!3Added data preparation, hyperparameter optimisation, benchmarking code and k-mer library visualisation
...@@ -69,7 +69,10 @@ def main(args): ...@@ -69,7 +69,10 @@ def main(args):
ranges_dict = yaml.load(fh, yaml.FullLoader) ranges_dict = yaml.load(fh, yaml.FullLoader)
# Generate dbs # Generate dbs
with open(args.kmer_list, 'r') as fh: kmer_list = [k.strip() for k in fh.readlines() if len(k.strip())] with open(args.kmer_list, 'r') as fh:
kmer_list = [k.strip() for k in fh.readlines() if len(k.strip())]
kmer_list = kmer_list[:2]
db_dir = parse_output_path(f'{args.out_dir}dbs/') db_dir = parse_output_path(f'{args.out_dir}dbs/')
logs_dir = parse_output_path(f'{args.out_dir}logs/') logs_dir = parse_output_path(f'{args.out_dir}logs/')
...@@ -108,30 +111,26 @@ def main(args): ...@@ -108,30 +111,26 @@ def main(args):
"--directoryperdb", "--fork", "--journal", "--directoryperdb", "--fork", "--journal",
"--logpath", f"{args.out_dir}mongodb_log.log"]) "--logpath", f"{args.out_dir}mongodb_log.log"])
try:
# start worker processses
worker_cmd_list = ["hyperopt-mongo-worker", "--mongo=localhost:1234/db"]
worker_list = [subprocess.Popen(worker_cmd_list,
stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))
for _ in range(args.hyperopt_parallel_jobs)]
# minimize objective
trials = MongoTrials('mongo://localhost:1234/db/jobs')
# trials = hp.Trials()
out_param_dict = hp.fmin(fmin_objective,
space=space,
algo=hp.tpe.suggest,
trials=trials,
max_evals=args.hyperopt_iters,
max_queue_len=args.hyperopt_parallel_jobs)
for worker in worker_list:
worker.terminate()
subprocess.run(['mongod', '--shutdown', '--dbpath', mongodb_pth])
except Exception as e:
print(f'Had to exit: {e}')
subprocess.run(['mongod', '--shutdown', '--dbpath', mongodb_pth]) # todo can't this be done more elegantly?
# start worker processses
worker_cmd_list = ["hyperopt-mongo-worker", "--mongo=localhost:1234/db"]
worker_list = [subprocess.Popen(worker_cmd_list,
stdout=open(os.devnull, 'wb'),
stderr=open(os.devnull, 'wb'))
for _ in range(args.hyperopt_parallel_jobs)]
# minimize objective
trials = MongoTrials('mongo://localhost:1234/db/jobs', exp_key='test_1')
out_param_dict = hp.fmin(fmin_objective,
space=space,
algo=hp.tpe.suggest,
trials=trials,
max_evals=args.hyperopt_iters)
for worker in worker_list:
worker.terminate()
subprocess.run(['mongod', '--shutdown', '--dbpath', mongodb_pth])
print(out_param_dict)
for p in out_param_dict: for p in out_param_dict:
if ranges_dict['variable'][p]['type'] == 'int': out_param_dict[p] = int(out_param_dict[p]) if ranges_dict['variable'][p]['type'] == 'int': out_param_dict[p] = int(out_param_dict[p])
for p in ranges_dict['nonvariable']: out_param_dict[p] = ranges_dict['nonvariable'][p] for p in ranges_dict['nonvariable']: out_param_dict[p] = ranges_dict['nonvariable'][p]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment