mirror of
https://github.com/c-sooyoung/bo-ptycho.git
synced 2026-09-17 23:29:07 +09:00
new job
This commit is contained in:
@@ -17,26 +17,38 @@ def main(config_yaml):
|
||||
shutil.copy(config_yaml, os.path.join(result_dir, os.path.basename(config_yaml)))
|
||||
|
||||
# RANDOM BO SAMPLING PREPARATIONS; 20 SAMPLES
|
||||
J = 20
|
||||
randombo = bo.RandomBOEngine(config)
|
||||
for j in range(20):
|
||||
print(f"RANDOM sampling iteration {j+1}")
|
||||
|
||||
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()
|
||||
y_value = -np.log(ptycho_engine.metric())
|
||||
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(config['bo']['max_iterations']):
|
||||
print(f"SOBO sampling iteration {j+1}")
|
||||
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(header=f"[BO {j:03d}] ")
|
||||
y_value = -np.log(ptycho_engine.metric())
|
||||
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 len(sys.argv) != 2:
|
||||
|
||||
Reference in New Issue
Block a user