-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_syntax.py
More file actions
233 lines (169 loc) · 9.2 KB
/
eval_syntax.py
File metadata and controls
233 lines (169 loc) · 9.2 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
"""
A script to evaluate the syntax error of llm generated PDDL domain on our dataset.
1. use different prompt methods and compare.
2. use different LLMs and compare.
"""
import os
import sys
from action_gen import action_generator
import json
import copy
from datetime import datetime
def dict_reset(dict_obj):
"""
Reset the dictionary to have all keys with value 0.
"""
for key in dict_obj.keys():
dict_obj[key] = 0
return dict_obj
############## generate llm domain ##################
def syntax_eval():
date_str = datetime.today().strftime('%Y-%m-%d-%H-%M')
dataset_root = "uav_domain_benchmark"
engine_list = ['deepseek-chat'] # deepseek-chat gpt-4.1-mini-2025-04-14
############### in case any generation fail because of the format of output, restart the evaluation from the stop point:
prompt_method_restart_list = [
'basic_blockworld',
'basic_best',
'basic_cot',
'basic_cot_best'
]
restart_domain = 'Watering'
restart_domain_signal = 0
restart_method = 'basic_blockworld'
restart_method_signal = 0
restart_engine = 'deepseek-chat' # 'gpt-4.1-mini-2025-04-14' 'deepseek-chat'
restart_engine_signal = 0
total_error_types_dict = {'has_unsupported_keywords': 0,
'messed_output_feedback': 0,
'invalid_object_type': 0,
'invalid_predicate_names': 0,
'invalid_predicate_format': 0,
'invalid_predicate_usage': 0,
'invalid_fluents_usage': 0,
'invalid_function_names': 0,
'invalid_function_format': 0,
'invalid_function_usage': 0,
'invalid_numeric_usage': 0}
########## for all available models ###########
for engine in engine_list:
if engine == restart_engine:
restart_engine_signal = 1
print(f"Restarting from engine: {engine}")
if restart_engine_signal == 0:
print(f"Skipping engine: {engine} until restart signal is set.")
continue
print(f"Using engine: {engine}")
########## for all available domains ###########
for dataset_domain in os.listdir(dataset_root):
if dataset_domain != restart_domain:
continue
if dataset_domain == restart_domain:
restart_domain_signal = 1
print(f"Restarting from domain: {dataset_domain}")
if restart_domain_signal == 0:
print(f"Skipping domain: {dataset_domain} until restart signal is set.")
continue
if dataset_domain == 'BlockWorld' or dataset_domain == ".git" or dataset_domain == ".gitignore" or dataset_domain == "README.md":
continue
print(f"Processing domain: {dataset_domain}")
########## for all available prompt methods ###########
for prompt_method in prompt_method_restart_list:
if prompt_method == restart_method:
restart_method_signal = 1
print(f"Restarting from prompt method: {prompt_method}")
if restart_method_signal == 0:
print(f"Skipping method: {prompt_method} until restart signal is set.")
continue
print(f"Using prompt method: {prompt_method}")
# for all the domains in the dataset:
dict_reset(total_error_types_dict)
count = 0
result_log_dir = f'results/{date_str}/{engine}/{dataset_domain}/{prompt_method}/'
os.makedirs(result_log_dir, exist_ok=True)
error_type_total = action_generator(
_domain_name_str=dataset_domain,
_engine=engine,
_prompt_method=prompt_method,
_result_log_dir=result_log_dir
)
for key in total_error_types_dict.keys():
for key1 in error_type_total.keys():
if key == key1:
total_error_types_dict[key] += error_type_total[key1]
count += 1
print(f"Save Total error types for {engine} with domain {dataset_domain} for this prompt method to json file:")
######### save the total error types to a json file
with open(os.path.join(f'results/{date_str}/{engine}/{dataset_domain}/{prompt_method}/', f'{engine}_{dataset_domain}_{prompt_method}_error_count.json'), "w", encoding="utf-8") as f:
json.dump(total_error_types_dict, f, indent=4, ensure_ascii=False)
############
# return
def total_error_count():
prompt_method_restart_list = [
'basic_best',
'basic_blockworld',
'basic_cot',
'basic_cot_best'
]
total_error_types_dict = {'has_unsupported_keywords': 0,
'messed_output_feedback': 0,
'invalid_object_type': 0,
'invalid_predicate_names': 0,
'invalid_predicate_format': 0,
'invalid_predicate_usage': 0,
'invalid_fluents_usage': 0,
'invalid_function_names': 0,
'invalid_function_format': 0,
'invalid_function_usage': 0,
'invalid_numeric_usage': 0}
total_error_types_dict_simple = copy.deepcopy(total_error_types_dict)
total_error_types_dict_complex = copy.deepcopy(total_error_types_dict)
domain_comp = [('MultiCamLand', 15.23), ('MovableObs', 12.41), ('CeilingPaint', 11.48),
('SpeedAdapt', 8.82), ('GraspFruit', 8.69), ('Watering', 8.3),
('MaintenanceComponent', 7.77), ('AirPassenger', 7.5), ('DeliveryDurative', 6.92),
('DeliveryCapacity', 6.89), ('MedsDeliveryEnergy', 6.61), ('GraspDelivery', 6.23),
('CityCargo', 5.95), ('Gate', 5.7), ('MarsExploration', 5.58), ('MealDelivery', 5.4),
('BlockWorld', 5.23), ('DeliveryPriority', 5.05), ('TerrainAdapt', 5.05),
('WindDisturbance', 4.95), ('GridExplore', 4.94), ('Tracking', 4.92), ('Perching', 4.89),
('Landing', 4.42), ('2DNavigation', 4.39), ('AirPollution', 4.27),
('ForestFireCollaboration', 4.21), ('MedsDelivery', 4.21), ('Delivery', 4.15),
('SimpleNavigation', 3.11), ('HouseNavigation', 2.79)]
simple_domain_list = [d[0] for d in domain_comp if d[1] <= 5.24]
complex_domain_list = [d[0] for d in domain_comp if d[1] > 5.24]
engine = 'gpt-4.1-mini-2025-04-14' # 'gpt-4.1-mini-2025-04-14' 'deepseek-chat'
result_root = r'results/2025-07-15-21-58/gpt-4.1-mini-2025-04-14'
# result_root = r'results\2025-07-29-01-20\deepseek-chat'
for prompt_method in prompt_method_restart_list:
for domain_name in os.listdir(result_root):
if domain_name == '.git' or domain_name == '.gitignore' or domain_name == 'val_plans' or domain_name == 'README.md' or domain_name == 'BlockWorld':
continue
error_file_path = os.path.join(result_root, domain_name, prompt_method, f'{engine}_{prompt_method}_error_count.json')
if not os.path.exists(error_file_path):
print(f"Error file not found for {domain_name} - {prompt_method}.")
continue
with open(error_file_path, "r", encoding="utf-8") as f:
error_count = json.load(f)
for key in total_error_types_dict.keys():
if key in error_count:
if domain_name in simple_domain_list:
total_error_types_dict_simple[key] += error_count[key]
elif domain_name in complex_domain_list:
total_error_types_dict_complex[key] += error_count[key]
total_error_types_dict[key] += error_count[key]
print(f"Total error count across all domains for method {prompt_method}:")
print(total_error_types_dict)
print('=============================\n\n')
print(f"Total error count across simple domains for method {prompt_method}:")
print(total_error_types_dict_simple)
print('=============================\n\n')
print(f"Total error count across complex domains for method {prompt_method}:")
print(total_error_types_dict_complex)
print('=============================\n\n')
total_error_types_dict = {k: 0 for k in total_error_types_dict}
total_error_types_dict_simple = {k: 0 for k in total_error_types_dict_simple}
total_error_types_dict_complex = {k: 0 for k in total_error_types_dict_complex}
if __name__ == '__main__':
# syntax_eval() # domain generation
# print("domain generation completed.")
total_error_count()
print("Syntax evaluation completed.")