-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_experiments.py
More file actions
164 lines (138 loc) · 5.3 KB
/
Copy pathcreate_experiments.py
File metadata and controls
164 lines (138 loc) · 5.3 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
import json
import os
from typing import List, Dict, Optional, Any
def create_configuration(
*,
name: str,
case_study: str,
selected_prompt_template: str,
llms_used: List[str],
n_programs_generated: int,
output_folder: str,
temperature: float = 0.7,
debug: bool = False,
# new (optional) pipeline fields:
headers_dir: Optional[str] = None,
include_dirs: Optional[List[str]] = None,
copy_headers_to_output: bool = True,
headers_manifest: Optional[Dict[str, str]] = None,
critics: Optional[List[str]] = None,
timeout_s: int = 60,
) -> Dict[str, Any]:
"""
Creates a pipeline configuration dict matching PipelineConfig.from_dict(...).
Keep it plug & play:
- critics: list of critic names, e.g. ["compile", "cppcheck-misra", ...]
- headers_dir/include_dirs are optional; if omitted, you can still compile if headers are in default include paths.
"""
cfg: Dict[str, Any] = {
"name": name,
"case_study": case_study,
"selected_prompt_template": selected_prompt_template,
"llms_used": llms_used,
"n_programs_generated": n_programs_generated,
"output_folder": output_folder,
"temperature": temperature,
"debug": debug,
"timeout_s": timeout_s,
"copy_headers_to_output": copy_headers_to_output,
}
if headers_dir is not None:
cfg["headers_dir"] = headers_dir
if include_dirs:
cfg["include_dirs"] = list(include_dirs)
if headers_manifest:
cfg["headers_manifest"] = dict(headers_manifest)
if critics:
cfg["critics"] = list(critics)
return cfg
def generate_systematic_configurations(
*,
case_studies: List[str],
prompt_templates: List[str],
llms_list: List[str],
n_programs: int,
base_output_folder: str = "./output",
temperature: float = 0.7,
debug: bool = False,
# optional shared settings:
case_studies_root: str = "../case_studies",
include_dirs_extra: Optional[List[str]] = None,
copy_headers_to_output: bool = True,
headers_manifest: Optional[Dict[str, str]] = None,
critics: Optional[List[str]] = None,
timeout_s: int = 60,
) -> List[Dict[str, Any]]:
"""
Systematically generates configurations.
Assumes headers live at: {case_studies_root}/{case_study}/headers
"""
configurations: List[Dict[str, Any]] = []
count = 1
include_dirs_extra = list(include_dirs_extra or [])
for prompt_template in prompt_templates:
for case_study in case_studies:
config_name = f"config_{case_study}_{prompt_template}_{count}"
output_folder = os.path.join(base_output_folder, config_name)
headers_dir = os.path.join(case_studies_root, case_study, "headers")
include_dirs = list(include_dirs_extra)
# add headers_dir as an include dir (so gcc can find copied or original headers)
include_dirs.append(headers_dir)
configurations.append(
create_configuration(
name=config_name,
case_study=case_study,
selected_prompt_template=prompt_template,
llms_used=llms_list,
n_programs_generated=n_programs,
output_folder=output_folder,
temperature=temperature,
debug=debug,
headers_dir=headers_dir,
include_dirs=include_dirs,
copy_headers_to_output=copy_headers_to_output,
headers_manifest=headers_manifest,
critics=critics,
timeout_s=timeout_s,
)
)
count += 1
return configurations
def save_configurations(configurations: List[Dict[str, Any]], file_path: str) -> None:
os.makedirs(os.path.dirname(file_path) or ".", exist_ok=True)
with open(file_path, "w", encoding="utf-8") as file:
json.dump(configurations, file, indent=2)
print(f"Configurations saved to {file_path}")
def main() -> None:
prompt_templates = ["zero-shot"]
llms_list = ["gpt-4o"]
case_studies = ["sgmm"]
n_programs = 1
headers_manifest = {
"defined_types.h": "Project-wide typedefs/macros used everywhere. Always include this first via other headers.",
"rtdb.h": "RTDB globals for inputs/outputs (extern declarations) used by the function under test.",
"signals.h": "Signal status helpers/macros (if used).",
}
critics = [
"compile",
"cppcheck-misra",
"framac-wp",
"vernfr-control-flow",
"vernfr-data-flow",
]
configurations = generate_systematic_configurations(
case_studies=case_studies,
prompt_templates=prompt_templates,
llms_list=llms_list,
n_programs=n_programs,
base_output_folder="../output",
temperature=0.7,
debug=True,
case_studies_root="../case_studies",
headers_manifest=headers_manifest,
critics=critics,
timeout_s=60,
)
save_configurations(configurations, "input/test-config.json")
if __name__ == "__main__":
main()