Skip to content

Commit

Permalink
Update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
verifit committed Oct 18, 2023
1 parent b0ee498 commit 39ad81b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 32 deletions.
Empty file removed results/data/.gitkeep
Empty file.
37 changes: 22 additions & 15 deletions scripts/massage_arguments.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@ def peak_type(automaton: str):
return line


def should_regenerate(automata):
for aut in automata:
if not os.path.exists(aut):
return True
return False


def massage_automata(automata_sources: list[str]) -> list[str]:
automata_type = peak_type(automata_sources[0]).strip()
if '@NFA-bits' in automata_type:
targets = []
for aut_src in automata_sources:
aut_tgt = os.path.splitext(aut_src)[0] + MATA_EXT + MINTERM_EXT
targets.append(aut_tgt)
if any(not os.path.exists(aut) for aut in targets):
alphabet = alph.OnTheFlyAlphabet()
parsed_automata = ps.from_mata(automata_sources, alphabet)
for aut, tgt in zip(parsed_automata, targets):
initial = " ".join(f"q{i}" for i in aut.initial_states)
final = " ".join(f"q{i}" for i in aut.final_states)
transitions = "\n".join(
f"q{t.source} {t.symbol} q{t.target}" for t in aut.iterate()
)

with open(tgt, 'w') as tgt_handle:
tgt_handle.write(f"@NFA-explicit\n")
tgt_handle.write(f"%Initial {initial}\n")
tgt_handle.write(f"%Final {final}\n")
tgt_handle.write(transitions)
alphabet = alph.OnTheFlyAlphabet()
parsed_automata = ps.from_mata(automata_sources, alphabet)
for aut, tgt in zip(parsed_automata, targets):
initial = " ".join(f"q{i}" for i in aut.initial_states)
final = " ".join(f"q{i}" for i in aut.final_states)
transitions = "\n".join(
f"q{t.source} {t.symbol} q{t.target}" for t in aut.iterate()
)

with open(tgt, 'w') as tgt_handle:
tgt_handle.write(f"@NFA-explicit\n")
tgt_handle.write(f"%Initial {initial}\n")
tgt_handle.write(f"%Final {final}\n")
tgt_handle.write(transitions)
tgt_handle.write('\n')

return targets
else:
Expand Down
49 changes: 34 additions & 15 deletions scripts/pycobench
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,11 @@ measured using system "time" command.
return result


###########################################
def execute_benchmark(params):
"""execute_benchmark(params) -> None
Executes one benchmark.
"""
global g_cmd_dict
name = params['method']
in_params = params['params']
cmd = g_cmd_dict[name]['cmd']
cmd = cmd.split()
# in_params = in_params.split()

def substitute_cmd(in_cmd, in_params):
cmd = in_cmd[:]
# substitute $1, $2, etc. with the real parameters
for i in range(len(cmd)):
if len(cmd[i]) == 2 and cmd[i][0] == '$':
if len(cmd[i]) == 2 and cmd[i][0] == '$' and cmd[i][1] != '(':
try:
x = int(cmd[i][1])
except Exception:
Expand All @@ -249,6 +238,22 @@ Executes one benchmark.
" parameters passed) in `" + " ".join(cmd) + '`')
else:
cmd[i] = in_params[x-1]
return cmd[:]


###########################################
def execute_benchmark(params):
"""execute_benchmark(params) -> None
Executes one benchmark.
"""
global g_cmd_dict
name = params['method']
in_params = params['params']
cmd = g_cmd_dict[name]['cmd']
cmd = cmd.split()
# in_params = in_params.split()
cmd = substitute_cmd(cmd, in_params)

try:
# result = run_subproc(cmd)
Expand Down Expand Up @@ -326,7 +331,7 @@ christian]).
g_cnt_finished_tasks,
g_cnt_tasks,
result['method'],
result['params'],
f"[{' '.join(substitute_cmd(g_cmd_dict[result['method']]['cmd'].split(), result['params']))}]",
res_string)))


Expand Down Expand Up @@ -412,6 +417,16 @@ Runs the main program according to the arguments obtained from the parser.

g_cmd_dict = new_cmd_dict

if args.exclude:
methods = args.exclude.split(';')
methods = [meth for meth in methods if meth != ""]
new_cmd_dict = dict()
for m in g_cmd_dict:
if m not in methods:
new_cmd_dict[m] = g_cmd_dict[m]

g_cmd_dict = new_cmd_dict

# process additional program parameters
global g_timeout
g_timeout = args.timeout
Expand Down Expand Up @@ -512,6 +527,10 @@ if __name__ == '__main__':
dest='methods',
help="Which methods from the configuration file to "
"execute, separated by ';' (default: all)")
parser.add_argument('-e', '--exclude', metavar='METHODS', type=str,
dest='exclude',
help="Which methods from the configuration file will be ignored,"
"separated by ';' (default=None)")
parser.add_argument('-v', '--verbose', action="store_true",
help="verbose output")
parser.add_argument('-c', '--conf', metavar='config.yaml', nargs=1, required=True,
Expand Down
8 changes: 8 additions & 0 deletions scripts/run_automata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
binary=$1
shift
program=$1
shift
automata="$@"

$binary $program $(python3 ~/scripts/massage_arguments.py $automata)
8 changes: 8 additions & 0 deletions scripts/run_mona.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
binary=$1
shift
program=$1
shift
automata="$@"

$binary $program $(python3 ~/scripts/to_mona_mata.py $automata)
9 changes: 7 additions & 2 deletions scripts/run_pyco.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ usage() { {
echo " -c|--config <conf.yaml> configuration file in yaml format [default=jobs/bench-cade-23.yaml]"
echo " -t|--timeout <int> timeout for each benchmark in seconds [default=60s]"
echo " -m|--methods will measure only selected tools"
echo " -e|--exclude will exclude selected tools"
echo " -j|--jobs number of paralel jobs"
echo " -s|--suffix adds suffix to the target file"
echo " -v|--verbose adds verbosity to pycobench"
Expand All @@ -32,6 +33,7 @@ timeout=60
benchmarks=()
jobs=6
methods=
exclude=
suffix=""
basedir=$(realpath $(dirname "$0"))
rootdir=$(realpath "$basedir/..")
Expand Down Expand Up @@ -65,6 +67,9 @@ while [ $# -gt 0 ]; do
-m|--methods)
methods="-m $2"
shift 2;;
-e|--exclude)
exclude="-e $2"
shift 2;;
-d|--test-run)
testrun=true
shift 1;;
Expand Down Expand Up @@ -135,9 +140,9 @@ do
sub_result_file="$result_file.log"
intermediate+=( $sub_result_file )
if [ "$testrun" = true ]; then
cat "$benchmark_file" | head -1 | "$basedir/"pycobench $methods $verbose -j "$jobs" -c "$config" -t "$timeout" -o "$sub_result_file"
cat "$benchmark_file" | head -1 | "$basedir/"pycobench $exclude $methods $verbose -j "$jobs" -c "$config" -t "$timeout" -o "$sub_result_file"
else
"$basedir/"pycobench $methods $verbose -j "$jobs" -c "$config" -t "$timeout" -o "$sub_result_file" < "$benchmark_file"
"$basedir/"pycobench $exclude $methods $verbose -j "$jobs" -c "$config" -t "$timeout" -o "$sub_result_file" < "$benchmark_file"
fi

number_of_params=$(($(head -1 < "$benchmark_file" | tr -cd ';' | wc -c) + 1))
Expand Down

0 comments on commit 39ad81b

Please sign in to comment.