-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.py
54 lines (45 loc) · 1.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import hydra
import logging
import os
from pathlib import Path
import subprocess
from utils.utils import init_client
ROOT_DIR = os.getcwd()
logging.basicConfig(level=logging.INFO)
@hydra.main(version_base=None, config_path="cfg", config_name="config")
def main(cfg):
workspace_dir = Path.cwd()
# Set logging level
logging.info(f"Workspace: {workspace_dir}")
logging.info(f"Project Root: {ROOT_DIR}")
logging.info(f"Using LLM: {cfg.get('model', cfg.llm_client.model)}")
logging.info(f"Using Algorithm: {cfg.algorithm}")
client = init_client(cfg)
if cfg.algorithm == "reevo":
from reevo import ReEvo as LHH
elif cfg.algorithm == "ael":
from baselines.ael.ga import AEL as LHH
elif cfg.algorithm == "eoh":
from baselines.eoh import EoH as LHH
else:
raise NotImplementedError
# Main algorithm
lhh = LHH(cfg, ROOT_DIR, client)
best_code_overall, best_code_path_overall = lhh.evolve()
logging.info(f"Best Code Overall: {best_code_overall}")
logging.info(f"Best Code Path Overall: {best_code_path_overall}")
# Run validation and redirect stdout to a file "best_code_overall_stdout.txt"
with open(f"{ROOT_DIR}/problems/{cfg.problem.problem_name}/gpt.py", 'w') as file:
file.writelines(best_code_overall + '\n')
test_script = f"{ROOT_DIR}/problems/{cfg.problem.problem_name}/eval.py"
test_script_stdout = "best_code_overall_val_stdout.txt"
logging.info(f"Running validation script...: {test_script}")
with open(test_script_stdout, 'w') as stdout:
subprocess.run(["python", test_script, "-1", ROOT_DIR, "val"], stdout=stdout)
logging.info(f"Validation script finished. Results are saved in {test_script_stdout}.")
# Print the results
with open(test_script_stdout, 'r') as file:
for line in file.readlines():
logging.info(line.strip())
if __name__ == "__main__":
main()