-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathget_results.py
86 lines (65 loc) · 2.21 KB
/
get_results.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Reproduce the experiments
"""
import json
from gpt4or import *
from configure import api_keys
parser = argparse.ArgumentParser()
parser.add_argument("--model", type=str, default="gpt-3.5-turbo")
parser.add_argument(
"--path", type=str, default="./datasets/lectures_in_lp_modeling/problem_7"
)
parser.add_argument("--maxattempt", type=int, default=5)
parser.add_argument("--aug", type=int, default=3)
parser.add_argument("--keyid", type=int, default=0)
if __name__ == "__main__":
args = parser.parse_args()
prefix = "description"
starting_path = os.getcwd()
print("Using API Key %d: %s" % (args.keyid, api_keys[args.keyid]), flush=True)
test_modes = [
# MODE_STANDARD_PROMPT,
# MODE_COT_ONLY,
# MODE_COT_DEBUG,
# MODE_COT_DEBUG_TEST,
MODE_COT_HUMAN,
]
n_modes = len(test_modes)
# Solve under different modes
n_aug = 0
f = open("res.txt", "a+")
for mode in test_modes:
num_augment = args.aug
if mode != MODE_COT_HUMAN:
num_augment = 1
info = [STATUS_SYNTAX_ERROR, -1]
for n_aug in range(num_augment):
os.chdir(starting_path)
# Augmentation
if n_aug == 0:
std_file = "%s.txt" % prefix
else:
std_file = "%s-r%d.txt" % (prefix, n_aug)
try:
or_agent = GPT4OR(
model_name=args.model, solver="gurobi", api_key=api_keys[args.keyid]
)
info = or_agent.solve_problem(
problem_path=args.path,
problem_file=std_file,
bench_file="test-human.py",
max_attempt=args.maxattempt,
solver="gurobi",
solve_mode=mode,
solve_params=None,
)
if info[0] == STATUS_PASSED:
break
except Exception as e:
info = [STATUS_SYNTAX_ERROR, -1]
print(e, flush=True)
f.write(
"Problem %s Mode %d Iter %d Status %d Try %d\n" % (args.path, mode, info[1], info[0], n_aug)
)
f.close()
os.chdir(starting_path)