forked from SMT-COMP/smt-comp.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchexec.py
More file actions
346 lines (281 loc) · 12.9 KB
/
benchexec.py
File metadata and controls
346 lines (281 loc) · 12.9 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
from pathlib import Path
from os.path import relpath
from typing import List, cast, Optional
from yattag import Doc, indent
from smtcomp import defs
from smtcomp.archive import find_command, archive_unpack_dir, command_path
from pydantic import BaseModel
import shlex
from re import sub
def get_suffix(track: defs.Track) -> str:
match track:
case defs.Track.Incremental:
return "_inc"
case defs.Track.ModelValidation:
return "_model"
case defs.Track.UnsatCore:
return "_unsatcore"
case defs.Track.UnsatCoreValidation:
return "_unsatcorevalidation"
case defs.Track.SingleQuery:
return ""
case defs.Track.Parallel:
return "_parallel"
case defs.Track.Cloud:
return "_cloud"
case defs.Track.ProofExhibition:
return "_proof"
def get_xml_name(s: defs.Submission, track: defs.Track, division: defs.Division) -> str:
suffix = get_suffix(track)
return sub(r"\W+", "", s.name.lower()) + suffix + "_" + str(division) + ".xml"
def tool_module_name(s: defs.Submission, incremental: bool) -> str:
suffix = "_inc" if incremental else ""
return sub(r"\W+", "", s.name.lower()) + suffix
class CmdTask(BaseModel):
name: str
options: List[str]
taskdirs: List[str]
def generate_benchmark_yml(
ymlfile: Path, benchmark: Path, expected_result: Optional[bool], orig_file: Optional[Path] = None
) -> None:
with ymlfile.open("w") as f:
f.write("format_version: '2.0'\n\n")
f.write(f"input_files: '{str(benchmark.name)}'\n\n")
if orig_file is not None:
f.write(f"# original_files: '{str(orig_file)}'\n\n")
expected_str = "true" if expected_result else "false"
f.write("properties:\n")
f.write(f" - property_file: '../../properties/SMT.prp'\n")
if expected_result is not None:
f.write(f" expected_verdict: {expected_str}\n")
def generate_tool_module(s: defs.Submission, cachedir: Path, incremental: bool) -> None:
name = tool_module_name(s, incremental)
file = cachedir / "tools" / f"{name}.py"
with file.open("w") as f:
if incremental:
base_module = "incremental_tool"
base_class = "IncrementalSMTCompTool"
else:
base_module = "tool"
base_class = "SMTCompTool"
f.write(f"from tools.{base_module} import {base_class}\n\n")
f.write(f"class Tool({base_class}): # type: ignore\n")
f.write(f" NAME = '{s.name}'\n")
if s.command is not None:
assert s.archive is not None
if s.command.compa_starexec:
executable_path = find_command(s.command, s.archive, cachedir)
executable = str(relpath(executable_path, start=str(cachedir)))
else:
executable = str(command_path(s.command, s.archive, Path()))
f.write(f" EXECUTABLE = '{executable}'\n")
required_paths = ["benchexec"]
if s.archive is not None:
archive_path = relpath(archive_unpack_dir(s.archive, cachedir), start=str(cachedir))
required_paths.append(str(archive_path))
for p in s.participations.root:
if p.archive is not None:
archive_path = relpath(archive_unpack_dir(p.archive, cachedir), start=str(cachedir))
required_paths.append(str(archive_path))
if required_paths:
f.write(f" REQUIRED_PATHS = {required_paths}\n")
def generate_tool_modules(s: defs.Submission, cachedir: Path) -> None:
generate_tool_module(s, cachedir, True)
generate_tool_module(s, cachedir, False)
def generate_xml(
config: defs.Config, cmdtasks: List[CmdTask], file: Path, tool_module_name: str, track: defs.Track, test: bool
) -> None:
doc, tag, text = Doc().tagtext()
doc.asis('<?xml version="1.0"?>')
doc.asis(
'<!DOCTYPE benchmark PUBLIC "+//IDN sosy-lab.org//DTD BenchExec benchmark 2.3//EN"'
' "https://www.sosy-lab.org/benchexec/benchmark-2.2.3dtd">'
)
timelimit = config.timelimit_s_test if test else config.timelimit_s
cpuCores = config.cpuCores_parallel if track == defs.Track.Parallel else config.cpuCores
memlimit = config.memlimit_M_parallel if track == defs.Track.Parallel else config.memlimit_M
if test:
cpuCores = config.cpuCores_parallel_test if track == defs.Track.Parallel else config.cpuCores_test
memlimit = config.memlimit_M_parallel_test if track == defs.Track.Parallel else config.memlimit_M_test
with tag(
"benchmark",
tool=f"tools.{tool_module_name}",
timelimit=f"{timelimit * cpuCores}s",
walltimelimit=f"{timelimit}s",
memlimit=f"{memlimit} MB",
cpuCores=f"{cpuCores}",
):
if track != defs.Track.Parallel:
# we run the test jobs on different machines (main machines are used)
used_cpuModel = "Intel Core i7" if test else "Intel Xeon E3-1230 v5 @ 3.40 GHz"
with tag("require", cpuModel=used_cpuModel):
text()
with tag("resultfiles"):
text("**/error.log")
for cmdtask in cmdtasks:
with tag("rundefinition", name=f"{cmdtask.name}"):
for option in cmdtask.options:
with tag("option"):
text(option)
with tag("tasks", name="task"):
for taskdir in cmdtask.taskdirs:
with tag("include"):
text(f"{taskdir}/*.yml")
with tag("propertyfile"):
text("benchmarks/properties/SMT.prp")
file.write_text(indent(doc.getvalue()))
def generate_unsatcore_validation_xml(
config: defs.Config, cmdtasks: List[CmdTask], file: Path, tool_module_name: str
) -> None:
doc, tag, text = Doc().tagtext()
doc.asis('<?xml version="1.0"?>')
doc.asis(
'<!DOCTYPE benchmark PUBLIC "+//IDN sosy-lab.org//DTD BenchExec benchmark 2.3//EN"'
' "https://www.sosy-lab.org/benchexec/benchmark-2.2.3dtd">'
)
with tag(
"benchmark",
tool=f"tools.{tool_module_name}",
timelimit=f"{config.unsatcore_validation_timelimit_s * config.unsatcore_validation_cpuCores}s",
walltimelimit=f"{config.unsatcore_validation_timelimit_s}s",
memlimit=f"{config.unsatcore_validation_memlimit_M} MB",
cpuCores=f"{config.unsatcore_validation_cpuCores}",
):
with tag("require", cpuModel="Intel Xeon E3-1230 v5 @ 3.40 GHz"):
text()
for cmdtask in cmdtasks:
with tag("rundefinition", name=f"{cmdtask.name}"):
for option in cmdtask.options:
with tag("option"):
text(option)
with tag("tasks", name="task"):
for taskdir in cmdtask.taskdirs:
with tag("include"):
text(f"{taskdir}/*.smt2")
with tag("propertyfile"):
text("benchmarks/properties/SMT.prp")
file.write_text(indent(doc.getvalue()))
def cmdtask_for_submission(
s: defs.Submission, cachedir: Path, target_track: defs.Track, target_division: defs.Division
) -> List[CmdTask]:
res: List[CmdTask] = []
for i, p in enumerate(s.participations.root):
command = cast(defs.Command, p.command if p.command else s.command)
archive = cast(defs.Archive, p.archive if p.archive else s.archive)
for track, divisions in p.get().items():
# if target track is UnsatCoreValidation, use SingleQuery configuration
if track != target_track and not (
target_track == defs.Track.UnsatCoreValidation and track == defs.Track.SingleQuery
):
continue
suffix = get_suffix(target_track)
taskdirs: list[str] = [
f"../benchmarks/files{suffix}/{logic}" for logic in divisions.get(target_division, [])
]
if taskdirs:
if command.compa_starexec:
assert command.arguments == []
executable_path = find_command(command, archive, cachedir)
executable = str(relpath(executable_path, start=str(cachedir)))
dirname = str(relpath(executable_path.parent, start=str(cachedir)))
options = [
"bash",
"-c",
f'FILE=$(realpath $1); (cd {shlex.quote(dirname)}; exec ./{shlex.quote(executable_path.name)} "$FILE")',
"compa_starexec",
]
else:
executable = str(command_path(command, archive, Path()))
options = [executable] + command.arguments
cmdtask = CmdTask(
name=f"{s.name},{i},{target_track}",
options=options,
taskdirs=taskdirs,
)
res.append(cmdtask)
return res
def generate(s: defs.Submission, cachedir: Path, config: defs.Config, test: bool) -> None:
generate_tool_modules(s, cachedir)
dst = cachedir / "benchmarks"
prop_dir = dst.joinpath("properties")
prop_dir.mkdir(parents=True, exist_ok=True)
(prop_dir / "SMT.prp").touch()
run_defs = cachedir / "run_definitions"
run_defs.mkdir(parents=True, exist_ok=True)
tool = tool_module_name(s, False)
run_scripts = cachedir / "run_scripts"
run_scripts.mkdir(parents=True, exist_ok=True)
for target_track, divisions in defs.tracks.items():
# cloud and parallel tracks are not executed via benchexec
if target_track in (
defs.Track.Cloud,
defs.Track.UnsatCoreValidation,
defs.Track.ProofExhibition,
):
continue
generated_divisions = []
for division in divisions.keys():
res = cmdtask_for_submission(s, cachedir, target_track, division)
if res:
basename = get_xml_name(s, target_track, division)
file = run_defs / basename
generate_xml(
config=config,
cmdtasks=res,
file=file,
tool_module_name=tool_module_name(s, target_track == defs.Track.Incremental),
track=target_track,
test=test,
)
generated_divisions.append(division)
track_suffix = get_suffix(target_track)
script = run_scripts / (f"{tool}{track_suffix}.sh")
with open(script, "w") as f:
out = lambda s: f.write(s + "\n")
division_list = " ".join('"' + str(d) + '"' for d in generated_divisions)
out("#!/usr/bin/env bash")
out("set -x")
out(f"for DIVISION in {division_list}")
out(" do\n")
out(f' TARGET="../results/results{track_suffix}/$DIVISION/{tool}"')
out(" rm -rf $TARGET")
out(" mkdir -p $TARGET")
extra_args = ""
out(
f" PYTHONPATH=$(pwd) benchexec/contrib/vcloud-benchmark.py run_definitions/{tool}{track_suffix}_$DIVISION.xml --read-only-dir / --overlay-dir . --overlay-dir /home --vcloudClientHeap 500 --vcloudPriority URGENT --cgroupAccess -o $TARGET"
)
out("done")
def generate_unsatcore_validation(s: defs.Submission, cachedir: Path, config: defs.Config) -> None:
run_defs = cachedir / "run_definitions"
divisions = defs.tracks[defs.Track.UnsatCore]
generated_divisions = []
for division in divisions.keys():
res = cmdtask_for_submission(s, cachedir, defs.Track.UnsatCoreValidation, division)
if res:
basename = get_xml_name(s, defs.Track.UnsatCoreValidation, division)
file = run_defs / basename
generate_unsatcore_validation_xml(
config=config,
cmdtasks=res,
file=file,
tool_module_name=tool_module_name(s, False),
)
generated_divisions.append(division)
run_scripts = cachedir / "run_scripts"
run_scripts.mkdir(parents=True, exist_ok=True)
tool = tool_module_name(s, False)
script = run_scripts / (tool + "_unsatcorevalidation.sh")
with open(script, "w") as f:
out = lambda s: f.write(s + "\n")
division_list = " ".join('"' + str(d) + '"' for d in generated_divisions)
out("#!/usr/bin/env bash")
out("set -x")
out(f"for DIVISION in {division_list}")
out(" do\n")
out(f' TARGET="../unsat_core_validation_results/$DIVISION/{tool}"')
out(" rm -rf $TARGET")
out(" mkdir -p $TARGET")
out(
f" PYTHONPATH=$(pwd) benchexec/contrib/vcloud-benchmark.py run_definitions/{tool}_unsatcorevalidation_$DIVISION.xml --read-only-dir / --overlay-dir . --overlay-dir /home --vcloudClientHeap 500 --vcloudPriority URGENT --cgroupAccess -o $TARGET"
)
out("done")