mirror of
https://github.com/c-sooyoung/bo-ptycho.git
synced 2026-09-17 19:29:07 +09:00
moved to jobs **BROKEN**
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
from .sobo import sobo_job
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
import os
|
||||||
|
import bo
|
||||||
|
import ptycho
|
||||||
|
|
||||||
|
def sobo_job(config):
|
||||||
|
|
||||||
|
print("Hello")
|
||||||
|
# result_dir = config['io']['result_dir']
|
||||||
|
# os.makedirs(result_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# randombo = bo.RandomBOEngine(config)
|
||||||
|
|
||||||
|
# bo_txt = os.path.join(result_dir, "bo.txt")
|
||||||
|
# with open(bo_txt, "w") as f:
|
||||||
|
# f.write(f" iter\tmetric\t{"\t".join([p[:7] for p in randombo.params])}\n")
|
||||||
|
|
||||||
|
# for j in range(J):
|
||||||
|
# print(f"RANDOM sampling iteration {j}")
|
||||||
|
# job_config = randombo.ask()
|
||||||
|
# ptycho_engine = ptycho.FoldSlicePtychoEngine(job_config)
|
||||||
|
# ptycho_engine.run(run_id=f"bo-{j:03d}")
|
||||||
|
# y_value = ptycho_engine._metric
|
||||||
|
# randombo.tell(job_config, y_value)
|
||||||
|
# with open(bo_txt, "a") as f:
|
||||||
|
# p = [f'{job_config['ptycho']['params'][key]:.2f}' for key in randombo.params]
|
||||||
|
# f.write(f"{j: 8d}\t{y_value:.4f}\t{"\t".join(p)}\n")
|
||||||
|
|
||||||
|
|
||||||
|
# sobo = bo.SingleObjectiveBOEngine(config)
|
||||||
|
# sobo.train_x = randombo.train_x
|
||||||
|
# sobo.train_y = randombo.train_y
|
||||||
|
# for j in range(J, J + config['bo']['max_iterations'] + 1):
|
||||||
|
# print(f"SOBO sampling iteration {j}")
|
||||||
|
# job_config = sobo.ask()
|
||||||
|
# ptycho_engine = ptycho.FoldSlicePtychoEngine(job_config)
|
||||||
|
# ptycho_engine.run(run_id=f"bo-{j:03d}")
|
||||||
|
# y_value = ptycho_engine._metric
|
||||||
|
# sobo.tell(job_config, y_value)
|
||||||
|
# with open(bo_txt, "a") as f:
|
||||||
|
# p = [f'{job_config['ptycho']['params'][key]:.2f}' for key in sobo.params]
|
||||||
|
# f.write(f"{j: 8d}\t{y_value:.4f}\t{"\t".join(p)}\n")
|
||||||
@@ -1,54 +1,19 @@
|
|||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import shutil
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
import bo
|
import job
|
||||||
import ptycho
|
|
||||||
|
|
||||||
def main(config_yaml):
|
def main(config_yaml):
|
||||||
|
|
||||||
with open(config_yaml, 'r') as f:
|
with open(config_yaml, 'r') as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
|
|
||||||
result_dir = config['io']['result_dir']
|
job_types = {
|
||||||
os.makedirs(result_dir, exist_ok=True)
|
'random+sobo': job.sobo_job
|
||||||
shutil.copy(config_yaml, os.path.join(result_dir, os.path.basename(config_yaml)))
|
}
|
||||||
|
|
||||||
# RANDOM BO SAMPLING PREPARATIONS; 20 SAMPLES
|
job_types[config['job']['type']](config)
|
||||||
J = 20
|
|
||||||
randombo = bo.RandomBOEngine(config)
|
|
||||||
|
|
||||||
bo_txt = os.path.join(result_dir, "bo.txt")
|
|
||||||
with open(bo_txt, "w") as f:
|
|
||||||
f.write(f" iter\tmetric\t{"\t".join([p[:7] for p in randombo.params])}\n")
|
|
||||||
|
|
||||||
for j in range(J):
|
|
||||||
print(f"RANDOM sampling iteration {j}")
|
|
||||||
job_config = randombo.ask()
|
|
||||||
ptycho_engine = ptycho.FoldSlicePtychoEngine(job_config)
|
|
||||||
ptycho_engine.run(run_id=f"bo-{j:03d}")
|
|
||||||
y_value = ptycho_engine._metric
|
|
||||||
randombo.tell(job_config, y_value)
|
|
||||||
with open(bo_txt, "a") as f:
|
|
||||||
p = [f'{job_config['ptycho']['params'][key]:.2f}' for key in randombo.params]
|
|
||||||
f.write(f"{j: 8d}\t{y_value:.4f}\t{"\t".join(p)}\n")
|
|
||||||
|
|
||||||
# MAIN SINGLE OBJECTIVE BAYESIAN OPTIMIZATION
|
|
||||||
sobo = bo.SingleObjectiveBOEngine(config)
|
|
||||||
sobo.train_x = randombo.train_x
|
|
||||||
sobo.train_y = randombo.train_y
|
|
||||||
for j in range(J, J + config['bo']['max_iterations'] + 1):
|
|
||||||
print(f"SOBO sampling iteration {j}")
|
|
||||||
job_config = sobo.ask()
|
|
||||||
ptycho_engine = ptycho.FoldSlicePtychoEngine(job_config)
|
|
||||||
ptycho_engine.run(run_id=f"bo-{j:03d}")
|
|
||||||
y_value = ptycho_engine._metric
|
|
||||||
sobo.tell(job_config, y_value)
|
|
||||||
with open(bo_txt, "a") as f:
|
|
||||||
p = [f'{job_config['ptycho']['params'][key]:.2f}' for key in sobo.params]
|
|
||||||
f.write(f"{j: 8d}\t{y_value:.4f}\t{"\t".join(p)}\n")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
|
|||||||
Reference in New Issue
Block a user