Commit 76705fa2 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

wta: Add support for --transitions to bench.py

This allows to call the generator not only with --zero-frequency, but also with
--transitions.
parent 48c6e383
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import argparse import argparse
import os import os
import sys
import subprocess import subprocess
import json import json
import numpy as np import numpy as np
...@@ -10,33 +11,51 @@ import scipy.stats as st ...@@ -10,33 +11,51 @@ import scipy.stats as st
samples = 5 samples = 5
def coalg_file(states, monoid, symbols, zero_frequency, different_values, i): # Edge Spec should be ("transitions", str) or ("zero-frequency", str)
return "bench/wta_%s_%s_%s_%s_%s_%d" % (monoid, symbols, zero_frequency, def coalg_file(states, monoid, symbols, edge_spec, different_values, i):
if edge_spec[0] == "transitions":
return "bench/wta_%s_%s_t%s_%s_%s_%d" % (monoid, symbols, edge_spec[1],
different_values, states, i) different_values, states, i)
else:
return "bench/wta_%s_%s_%s_%s_%s_%d" % (monoid, symbols, edge_spec[1],
different_values, states, i)
def check_zerotrans(args):
if args.zero_frequency:
edge_spec = ("zero-frequency", args.zero_frequency)
elif args.transitions:
edge_spec = ("transitions", args.transitions)
else:
print("One of --zero-frequency and --transitions must be provided")
sys.exit(1)
args.edge_spec = edge_spec
def generate(args): def generate(args):
check_zerotrans(args)
generator = args.generator generator = args.generator
states = args.states states = args.states
monoid = args.monoid monoid = args.monoid
symbols = args.symbols symbols = args.symbols
zero_frequency = args.zero_frequency
different_values = args.different_values different_values = args.different_values
edge_spec = args.edge_spec
os.makedirs("bench", exist_ok=True) os.makedirs("bench", exist_ok=True)
for i in range(0, samples): for i in range(0, samples):
f = coalg_file(states, monoid, symbols, zero_frequency, different_values, f = coalg_file(states, monoid, symbols, edge_spec, different_values,
i) + ".coalgebra" i) + ".coalgebra"
if os.path.exists(f): if os.path.exists(f):
continue continue
cmd = [ cmd = [generator, "--states", states, "--monoid", monoid, "--symbols", symbols]
generator, "--states", states, "--monoid", monoid, "--symbols", cmd += ["--" + edge_spec[0], edge_spec[1]]
symbols, "--zero-frequency", zero_frequency, cmd += ["--different-values", different_values]
"--different-values", different_values
]
subprocess.run(cmd, stdout=open(f, "w+")) subprocess.run(cmd, stdout=open(f, "w+"))
...@@ -45,10 +64,10 @@ def run_one(args, i): ...@@ -45,10 +64,10 @@ def run_one(args, i):
states = args.states states = args.states
monoid = args.monoid monoid = args.monoid
symbols = args.symbols symbols = args.symbols
zero_frequency = args.zero_frequency
different_values = args.different_values different_values = args.different_values
edge_spec = args.edge_spec
f = coalg_file(states, monoid, symbols, zero_frequency, different_values, i) + ".coalgebra" f = coalg_file(states, monoid, symbols, edge_spec, different_values, i) + ".coalgebra"
copar_args = [copar, 'refine', '--stats-json', f] copar_args = [copar, 'refine', '--stats-json', f]
...@@ -62,7 +81,7 @@ def run_one(args, i): ...@@ -62,7 +81,7 @@ def run_one(args, i):
stats['monoid'] = monoid stats['monoid'] = monoid
stats['symbols'] = symbols stats['symbols'] = symbols
stats['zero-freq'] = zero_frequency stats['edge-spec'] = str(edge_spec)
stats['mon-values'] = different_values stats['mon-values'] = different_values
stats['i'] = i stats['i'] = i
...@@ -74,10 +93,10 @@ def run_one_simple(args, i): ...@@ -74,10 +93,10 @@ def run_one_simple(args, i):
states = args.states states = args.states
monoid = args.monoid monoid = args.monoid
symbols = args.symbols symbols = args.symbols
zero_frequency = args.zero_frequency edge_spec = args.edge_spec
different_values= args.different_values different_values= args.different_values
f = coalg_file(states, monoid, symbols, zero_frequency, different_values, i) + ".coalgebra" f = coalg_file(states, monoid, symbols, edge_spec, different_values, i) + ".coalgebra"
copar_args = [copar, 'refine', f] copar_args = [copar, 'refine', f]
...@@ -144,6 +163,8 @@ def print_row(d, header, stddev): ...@@ -144,6 +163,8 @@ def print_row(d, header, stddev):
def run(args): def run(args):
check_zerotrans(args)
results = [run_one(args, i) for i in range(0, samples)] results = [run_one(args, i) for i in range(0, samples)]
def confidencekey(vals, k): def confidencekey(vals, k):
...@@ -199,6 +220,8 @@ def find_bad(args, good): ...@@ -199,6 +220,8 @@ def find_bad(args, good):
def bisect_states(args): def bisect_states(args):
check_zerotrans(args)
states = args.start_states states = args.start_states
good = args.good or 0 good = args.good or 0
...@@ -232,7 +255,8 @@ def main(): ...@@ -232,7 +255,8 @@ def main():
gen_parser.add_argument('--states', required=True) gen_parser.add_argument('--states', required=True)
gen_parser.add_argument('--monoid', required=True) gen_parser.add_argument('--monoid', required=True)
gen_parser.add_argument('--symbols', required=True) gen_parser.add_argument('--symbols', required=True)
gen_parser.add_argument('--zero-frequency', required=True) gen_parser.add_argument('--zero-frequency')
gen_parser.add_argument('--transitions')
gen_parser.add_argument('--different-values', required=True) gen_parser.add_argument('--different-values', required=True)
gen_parser.set_defaults(func=generate) gen_parser.set_defaults(func=generate)
...@@ -241,7 +265,8 @@ def main(): ...@@ -241,7 +265,8 @@ def main():
run_parser.add_argument('--states', required=True) run_parser.add_argument('--states', required=True)
run_parser.add_argument('--monoid', required=True) run_parser.add_argument('--monoid', required=True)
run_parser.add_argument('--symbols', required=True) run_parser.add_argument('--symbols', required=True)
run_parser.add_argument('--zero-frequency', required=True) run_parser.add_argument('--zero-frequency')
run_parser.add_argument('--transitions')
run_parser.add_argument('--different-values', required=True) run_parser.add_argument('--different-values', required=True)
run_parser.add_argument( run_parser.add_argument(
'--stddev', action='store_true', help="report stddev for timings") '--stddev', action='store_true', help="report stddev for timings")
...@@ -256,7 +281,8 @@ def main(): ...@@ -256,7 +281,8 @@ def main():
bisect_parser.add_argument('copar') bisect_parser.add_argument('copar')
bisect_parser.add_argument('--monoid', required=True) bisect_parser.add_argument('--monoid', required=True)
bisect_parser.add_argument('--symbols', required=True) bisect_parser.add_argument('--symbols', required=True)
bisect_parser.add_argument('--zero-frequency', required=True) bisect_parser.add_argument('--zero-frequency')
bisect_parser.add_argument('--transitions')
bisect_parser.add_argument('--different-values', required=True) bisect_parser.add_argument('--different-values', required=True)
bisect_parser.add_argument('--start-states', type=int, default=50) bisect_parser.add_argument('--start-states', type=int, default=50)
bisect_parser.add_argument('--good', type=int) bisect_parser.add_argument('--good', type=int)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment