Examples and clean-ups (#1)
- Attempt at implementing an example for DRS - Complete reactions set - New automaton - Formula - Fixed automaton scaling - Proc index in the formula - Benchmark generators - Scripts to reproduce experiments for reaction mining
This commit was merged in pull request #1.
This commit is contained in:
290
examples/bdd/generators/gen_drs.py
Executable file
290
examples/bdd/generators/gen_drs.py
Executable file
@@ -0,0 +1,290 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import itertools
|
||||
|
||||
|
||||
class SingleReaction:
|
||||
def __init__(self, reactants=None, inhibitors=None, products=None):
|
||||
self.reactants = set(reactants) if reactants is not None else set()
|
||||
self.inhibitors = set(inhibitors) if inhibitors is not None else set()
|
||||
self.products = set(products) if products is not None else set()
|
||||
|
||||
def get_reactants(self):
|
||||
return "{" + ", ".join(self.reactants) + "}"
|
||||
|
||||
def get_inhibitors(self):
|
||||
return "{" + ", ".join(self.inhibitors) + "}"
|
||||
|
||||
def get_products(self):
|
||||
return "{" + ", ".join(self.products) + "}"
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
"{"
|
||||
+ f"{self.get_reactants()}, {self.get_inhibitors()} -> {self.get_products()}"
|
||||
+ "};"
|
||||
)
|
||||
|
||||
|
||||
class Reactions:
|
||||
def __init__(self):
|
||||
self.reactions = []
|
||||
|
||||
def add(self, reaction):
|
||||
self.reactions.append(reaction)
|
||||
|
||||
def __str__(self):
|
||||
ret = ""
|
||||
for r in self.reactions:
|
||||
ret += f"{r}\n"
|
||||
return ret
|
||||
|
||||
|
||||
class Transition:
|
||||
def __init__(self, src, dst, guard, context):
|
||||
self.src = src
|
||||
self.dst = dst
|
||||
self.guard = guard
|
||||
self.context = context
|
||||
|
||||
def get_context_str(self):
|
||||
r = []
|
||||
for proc, entities in self.context:
|
||||
ent_str = ",".join(entities)
|
||||
r.append(f"{proc}={{{ent_str}}}")
|
||||
|
||||
r = " ".join(r)
|
||||
return "{ " + r + " }"
|
||||
|
||||
def __str__(self):
|
||||
if self.guard:
|
||||
return f"{self.get_context_str()}: {self.src} -> {self.dst} : {self.guard};"
|
||||
else:
|
||||
return f"{self.get_context_str()}: {self.src} -> {self.dst};"
|
||||
|
||||
|
||||
class Automaton:
|
||||
def __init__(self):
|
||||
self.transitions = []
|
||||
self.states = []
|
||||
self.init_state = None
|
||||
|
||||
def add_transition(self, transition):
|
||||
self.transitions.append(transition)
|
||||
|
||||
def add_state(self, state):
|
||||
if state not in self.states:
|
||||
self.states.append(state)
|
||||
|
||||
def set_init_state(self, state):
|
||||
assert state in self.states, f"{state} not in states"
|
||||
self.init_state = state
|
||||
|
||||
def __str__(self):
|
||||
r = "context-automaton {\n"
|
||||
r += "\tstates { " + ", ".join(self.states) + " };\n"
|
||||
r += f"\tinit-state {{ {self.init_state} }};\n"
|
||||
r += "\ttransitions {\n"
|
||||
for tr in self.transitions:
|
||||
r += "\t\t" + str(tr) + "\n"
|
||||
r += "\t};\n"
|
||||
r += "};\n"
|
||||
return r
|
||||
|
||||
|
||||
class DRSGenerator:
|
||||
def __init__(self, x, y, z, aut):
|
||||
assert y >= z
|
||||
assert x >= 2 and y >= 2 and z >= 2
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
self.aut_id = aut
|
||||
self.n = self.y
|
||||
self.reactions = {}
|
||||
|
||||
self.automaton = Automaton()
|
||||
|
||||
self.generate()
|
||||
|
||||
def generate_agent_zero(self):
|
||||
rcts = Reactions()
|
||||
for i in range(1, self.y + 1):
|
||||
rcts.add(SingleReaction(["RTK"], ["h"], [f"RTK{i}"]))
|
||||
for j in range(1, self.x + 1):
|
||||
rcts.add(SingleReaction([f"EN:{j}_{i}"], ["h"], [f"ENi:{self.x}_{i}"]))
|
||||
return rcts
|
||||
|
||||
def generate_reactions_for_component(self, i):
|
||||
self.reactions.setdefault(i, Reactions())
|
||||
rcts = self.reactions[i]
|
||||
rcts.add(SingleReaction(["GF"], ["h"], ["GF"]))
|
||||
rcts.add(SingleReaction(["GF"], ["h", f"RTK{i}"], ["RTK"]))
|
||||
rcts.add(SingleReaction(["RTK"], [f"ENi:1_{i}"], [f"EN:1_{i}"]))
|
||||
for j in range(1, self.x):
|
||||
rcts.add(
|
||||
SingleReaction([f"EN:{j}_{i}"], [f"ENi:{j+1}_{i}"], [f"EN:{j+1}_{i}"])
|
||||
)
|
||||
|
||||
indices = list(range(1, self.y + 1))
|
||||
for comb in itertools.combinations(indices, self.z):
|
||||
reactants = []
|
||||
for i in comb:
|
||||
reactants.append(f"EN:{self.x}_{i}")
|
||||
rcts.add(SingleReaction(reactants, ["h"], ["TF"]))
|
||||
|
||||
def generate(self):
|
||||
|
||||
print(f"# Generated for: x = {self.x}, y = {self.y}, z = {self.z}")
|
||||
|
||||
print("options { use-context-automaton; make-progressive; };")
|
||||
print("reactions {")
|
||||
|
||||
for i in range(1, self.y + 1):
|
||||
self.generate_reactions_for_component(i)
|
||||
|
||||
rcts_0 = self.generate_agent_zero()
|
||||
|
||||
print("proc0 {")
|
||||
print(rcts_0)
|
||||
print("};")
|
||||
|
||||
for proc, reactions in self.reactions.items():
|
||||
print(f"proc{proc} {{")
|
||||
print(reactions)
|
||||
print("};")
|
||||
|
||||
print("};")
|
||||
|
||||
if self.aut_id == "a":
|
||||
self.generate_automaton_4(self.n)
|
||||
elif self.aut_id == "b":
|
||||
self.generate_automaton_5(self.n)
|
||||
else:
|
||||
raise RuntimeError(f"Unknown automaton identifier: {self.aut_id}")
|
||||
|
||||
self.generate_formula()
|
||||
|
||||
def generate_automaton_4(self, n):
|
||||
aut = self.automaton
|
||||
|
||||
aut.add_state("qI")
|
||||
aut.add_state("qS")
|
||||
for i in range(1, n + 1):
|
||||
aut.add_state(f"q{i}A")
|
||||
aut.add_state(f"q{i}B")
|
||||
aut.add_state(f"q{i}C")
|
||||
aut.add_state(f"q{i}D")
|
||||
|
||||
aut.set_init_state("qI")
|
||||
|
||||
aut.add_transition(
|
||||
Transition("qI", "qS", "", [(f"proc{i}", ["GF"]) for i in range(0, n + 1)])
|
||||
)
|
||||
|
||||
for i in range(1, n + 1):
|
||||
aut.add_transition(Transition("qS", f"q{i}A", "", [(f"proc{i}", [])]))
|
||||
aut.add_transition(
|
||||
Transition(
|
||||
f"q{i}A", f"q{i}B", "", [(f"proc{v}", []) for v in range(0, n + 1)]
|
||||
)
|
||||
)
|
||||
aut.add_transition(Transition(f"q{i}B", f"q{i}C", "", [(f"proc{i}", [])]))
|
||||
aut.add_transition(
|
||||
Transition(
|
||||
f"q{i}C", f"q{i}D", "", [(f"proc{v}", []) for v in range(0, n + 1)]
|
||||
)
|
||||
)
|
||||
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, n + 1):
|
||||
if i == j:
|
||||
continue
|
||||
aut.add_transition(
|
||||
Transition(f"q{i}B", f"q{j}A", "", [(f"proc{j}", [])])
|
||||
)
|
||||
aut.add_transition(
|
||||
Transition(f"q{i}D", f"q{j}A", "", [(f"proc{j}", [])])
|
||||
)
|
||||
|
||||
print(aut)
|
||||
|
||||
def generate_automaton_5(self, n):
|
||||
|
||||
aut = self.automaton
|
||||
|
||||
for i in range(0, (4 * n + 1)):
|
||||
aut.add_state(f"q{i}")
|
||||
|
||||
aut.set_init_state("q0")
|
||||
|
||||
aut.add_transition(
|
||||
Transition("q0", "q1", "", [(f"proc{i}", ["GF"]) for i in range(0, n + 1)])
|
||||
)
|
||||
|
||||
for i in range(0, n): # 0, ..., n-1
|
||||
aut.add_transition(
|
||||
Transition(f"q{4*i+1}", f"q{4*i+2}", "", [(f"proc{i+1}", [])])
|
||||
)
|
||||
aut.add_transition(
|
||||
Transition(
|
||||
f"q{4*i+2}",
|
||||
f"q{4*i+3}",
|
||||
"",
|
||||
[(f"proc{v}", []) for v in range(0, n + 1)],
|
||||
)
|
||||
)
|
||||
aut.add_transition(
|
||||
Transition(f"q{4*i+3}", f"q{4*i+4}", "", [(f"proc{i+1}", [])])
|
||||
)
|
||||
|
||||
for i in range(0, n - 1): # 0, ..., n-2
|
||||
aut.add_transition(
|
||||
Transition(
|
||||
f"q{4*i+4}",
|
||||
f"q{4*i+5}",
|
||||
"",
|
||||
[(f"proc{v}", []) for v in range(0, n + 1)],
|
||||
)
|
||||
)
|
||||
|
||||
aut.add_transition(
|
||||
Transition(f"q{4*n}", "q1", "", [(f"proc{i}", []) for i in range(0, n + 1)])
|
||||
)
|
||||
|
||||
print(aut)
|
||||
|
||||
def generate_formula(self):
|
||||
|
||||
disjunction = " OR ".join([f"proc{i}.TF" for i in range(1, self.y + 1)])
|
||||
conjunction = " AND ".join([f"~proc{i}.TF" for i in range(1, self.y + 1)])
|
||||
|
||||
r = (
|
||||
"rsctlk-property { f0 : AG( K[proc0]( "
|
||||
+ disjunction
|
||||
+ " ) OR K[proc0]( "
|
||||
+ conjunction
|
||||
+ " ) ) };"
|
||||
)
|
||||
|
||||
print(r)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 1 + 4:
|
||||
print(f"Usage: {sys.argv[0]} <x> <y> <z> <Aut>")
|
||||
print("\twhere x,y,z >= 2 and y >= z")
|
||||
print("\tAut: a, b")
|
||||
sys.exit(1)
|
||||
|
||||
g = DRSGenerator(
|
||||
x=int(sys.argv[1]),
|
||||
y=int(sys.argv[2]),
|
||||
z=int(sys.argv[3]),
|
||||
aut=sys.argv[4],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
4
examples/smt/chain_reaction.py
Normal file → Executable file
4
examples/smt/chain_reaction.py
Normal file → Executable file
@@ -28,7 +28,6 @@ import resource
|
||||
|
||||
|
||||
def chain_reaction(print_system=False):
|
||||
|
||||
if len(sys.argv) < 1 + 3:
|
||||
print("{source} <N> <M> <type>".format(source=sys.argv[0]))
|
||||
print()
|
||||
@@ -39,7 +38,7 @@ def chain_reaction(print_system=False):
|
||||
print()
|
||||
exit(1)
|
||||
|
||||
chainLen = int(sys.argv[1])
|
||||
chainLen = int(sys.argv[1])
|
||||
maxConc = int(sys.argv[2]) # depth (max concentration)
|
||||
|
||||
verify_rsc = bool(int(sys.argv[3]))
|
||||
@@ -115,7 +114,6 @@ def chain_reaction(print_system=False):
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
chain_reaction()
|
||||
|
||||
|
||||
|
||||
117
examples/smt/heat_shock_response.py
Normal file → Executable file
117
examples/smt/heat_shock_response.py
Normal file → Executable file
@@ -28,8 +28,7 @@ import resource
|
||||
|
||||
|
||||
def heat_shock_response(print_system=True, verify_rsc=True):
|
||||
|
||||
if len(sys.argv) < 1+1:
|
||||
if len(sys.argv) < 1 + 1:
|
||||
print("{source} <type>".format(source=sys.argv[0]))
|
||||
print("type:")
|
||||
print(" - 1 -- RSC")
|
||||
@@ -37,72 +36,80 @@ def heat_shock_response(print_system=True, verify_rsc=True):
|
||||
print()
|
||||
exit(1)
|
||||
|
||||
verify_rsc=bool(int(sys.argv[1]))
|
||||
verify_rsc = bool(int(sys.argv[1]))
|
||||
|
||||
stress_temp = 42
|
||||
max_temp = 50
|
||||
|
||||
r = ReactionSystemWithConcentrations()
|
||||
r.add_bg_set_entity(("hsp",1))
|
||||
r.add_bg_set_entity(("hsf",1))
|
||||
r.add_bg_set_entity(("hsf2",1))
|
||||
r.add_bg_set_entity(("hsf3",1))
|
||||
r.add_bg_set_entity(("hse",1))
|
||||
r.add_bg_set_entity(("mfp",1))
|
||||
r.add_bg_set_entity(("prot",1))
|
||||
r.add_bg_set_entity(("hsf3:hse",1))
|
||||
r.add_bg_set_entity(("hsp:mfp",1))
|
||||
r.add_bg_set_entity(("hsp:hsf",1))
|
||||
r.add_bg_set_entity(("temp",max_temp))
|
||||
r.add_bg_set_entity(("heat",1))
|
||||
r.add_bg_set_entity(("cool",1))
|
||||
|
||||
r.add_reaction([("hsf",1)], [("hsp",1)], [("hsf3",1)])
|
||||
r.add_reaction([("hsf",1),("hsp",1),("mfp",1)], [], [("hsf3",1)])
|
||||
r.add_reaction([("hsf3",1)], [("hse",1),("hsp",1)],[("hsf",1)])
|
||||
r.add_reaction([("hsf3",1),("hsp",1),("mfp",1)], [("hse",1)], [("hsf",1)])
|
||||
r.add_reaction([("hsf3",1),("hse",1)], [("hsp",1)], [("hsf3:hse",1)])
|
||||
r.add_reaction([("hsp",1),("hsf3",1),("mfp",1),("hse",1)],[], [("hsf3:hse",1)])
|
||||
r.add_reaction([("hse",1)], [("hsf3",1)], [("hse",1)])
|
||||
r.add_reaction([("hsp",1),("hsf3",1),("hse",1)], [("mfp",1)], [("hse",1)])
|
||||
r.add_reaction([("hsf3:hse",1)], [("hsp",1)], [("hsp",1),("hsf3:hse",1)])
|
||||
r.add_reaction([("hsp",1),("mfp",1),("hsf3:hse",1)],[], [("hsp",1),("hsf3:hse",1)])
|
||||
r.add_reaction([("hsf",1),("hsp",1)], [("mfp",1)], [("hsp:hsf",1)])
|
||||
r.add_reaction([("hsp:hsf",1),("temp",stress_temp)],[], [("hsf",1),("hsp",1)])
|
||||
r.add_reaction([("hsp:hsf",1)], [("temp",stress_temp)],[("hsp:hsf",1)])
|
||||
r.add_reaction([("hsp",1),("hsf3:hse",1)], [("mfp",1)], [("hse",1),("hsp:hsf",1)])
|
||||
r.add_reaction([("temp",stress_temp),("prot",1)], [], [("mfp",1),("prot",1)])
|
||||
r.add_reaction([("prot",1)], [("temp",stress_temp)], [("prot",1)])
|
||||
r.add_reaction([("hsp",1),("mfp",1)], [], [("hsp:mfp",1)])
|
||||
r.add_reaction([("mfp",1)], [("hsp",1)], [("mfp",1)])
|
||||
r.add_reaction([("hsp:mfp",1)], [], [("hsp",1),("prot",1)])
|
||||
|
||||
r.add_reaction_inc("temp", "heat", [("temp",1)],[("temp",max_temp)])
|
||||
r.add_reaction_dec("temp", "cool", [("temp",1)],[])
|
||||
r = ReactionSystemWithConcentrations()
|
||||
r.add_bg_set_entity(("hsp", 1))
|
||||
r.add_bg_set_entity(("hsf", 1))
|
||||
r.add_bg_set_entity(("hsf2", 1))
|
||||
r.add_bg_set_entity(("hsf3", 1))
|
||||
r.add_bg_set_entity(("hse", 1))
|
||||
r.add_bg_set_entity(("mfp", 1))
|
||||
r.add_bg_set_entity(("prot", 1))
|
||||
r.add_bg_set_entity(("hsf3:hse", 1))
|
||||
r.add_bg_set_entity(("hsp:mfp", 1))
|
||||
r.add_bg_set_entity(("hsp:hsf", 1))
|
||||
r.add_bg_set_entity(("temp", max_temp))
|
||||
r.add_bg_set_entity(("heat", 1))
|
||||
r.add_bg_set_entity(("cool", 1))
|
||||
|
||||
r.add_permanency("temp",[("heat",1),("cool",1)])
|
||||
r.add_reaction([("hsf", 1)], [("hsp", 1)], [("hsf3", 1)])
|
||||
r.add_reaction([("hsf", 1), ("hsp", 1), ("mfp", 1)], [], [("hsf3", 1)])
|
||||
r.add_reaction([("hsf3", 1)], [("hse", 1), ("hsp", 1)], [("hsf", 1)])
|
||||
r.add_reaction([("hsf3", 1), ("hsp", 1), ("mfp", 1)], [("hse", 1)], [("hsf", 1)])
|
||||
r.add_reaction([("hsf3", 1), ("hse", 1)], [("hsp", 1)], [("hsf3:hse", 1)])
|
||||
r.add_reaction(
|
||||
[("hsp", 1), ("hsf3", 1), ("mfp", 1), ("hse", 1)], [], [("hsf3:hse", 1)]
|
||||
)
|
||||
r.add_reaction([("hse", 1)], [("hsf3", 1)], [("hse", 1)])
|
||||
r.add_reaction([("hsp", 1), ("hsf3", 1), ("hse", 1)], [("mfp", 1)], [("hse", 1)])
|
||||
r.add_reaction([("hsf3:hse", 1)], [("hsp", 1)], [("hsp", 1), ("hsf3:hse", 1)])
|
||||
r.add_reaction(
|
||||
[("hsp", 1), ("mfp", 1), ("hsf3:hse", 1)], [], [("hsp", 1), ("hsf3:hse", 1)]
|
||||
)
|
||||
r.add_reaction([("hsf", 1), ("hsp", 1)], [("mfp", 1)], [("hsp:hsf", 1)])
|
||||
r.add_reaction(
|
||||
[("hsp:hsf", 1), ("temp", stress_temp)], [], [("hsf", 1), ("hsp", 1)]
|
||||
)
|
||||
r.add_reaction([("hsp:hsf", 1)], [("temp", stress_temp)], [("hsp:hsf", 1)])
|
||||
r.add_reaction(
|
||||
[("hsp", 1), ("hsf3:hse", 1)], [("mfp", 1)], [("hse", 1), ("hsp:hsf", 1)]
|
||||
)
|
||||
r.add_reaction([("temp", stress_temp), ("prot", 1)], [], [("mfp", 1), ("prot", 1)])
|
||||
r.add_reaction([("prot", 1)], [("temp", stress_temp)], [("prot", 1)])
|
||||
r.add_reaction([("hsp", 1), ("mfp", 1)], [], [("hsp:mfp", 1)])
|
||||
r.add_reaction([("mfp", 1)], [("hsp", 1)], [("mfp", 1)])
|
||||
r.add_reaction([("hsp:mfp", 1)], [], [("hsp", 1), ("prot", 1)])
|
||||
|
||||
r.add_reaction_inc("temp", "heat", [("temp", 1)], [("temp", max_temp)])
|
||||
r.add_reaction_dec("temp", "cool", [("temp", 1)], [])
|
||||
|
||||
r.add_permanency("temp", [("heat", 1), ("cool", 1)])
|
||||
|
||||
c = ContextAutomatonWithConcentrations(r)
|
||||
c.add_init_state("0")
|
||||
c.add_state("1")
|
||||
c.add_transition("0", [("hsf",1),("prot",1),("hse",1),("temp",35)], "1")
|
||||
c.add_transition("1", [("cool",1)], "1")
|
||||
c.add_transition("1", [("heat",1)], "1")
|
||||
c.add_transition("0", [("hsf", 1), ("prot", 1), ("hse", 1), ("temp", 35)], "1")
|
||||
c.add_transition("1", [("cool", 1)], "1")
|
||||
c.add_transition("1", [("heat", 1)], "1")
|
||||
c.add_transition("1", [], "1")
|
||||
|
||||
rc = ReactionSystemWithAutomaton(r,c)
|
||||
|
||||
rc = ReactionSystemWithAutomaton(r, c)
|
||||
|
||||
if print_system:
|
||||
rc.show()
|
||||
|
||||
prop_req = [ ("mfp",1) ]
|
||||
prop_block = [ ]
|
||||
prop = (prop_req,prop_block)
|
||||
rs_prop = (state_translate_rsc2rs(prop_req),state_translate_rsc2rs(prop_block))
|
||||
|
||||
|
||||
prop_req = [("mfp", 1)]
|
||||
prop_block = []
|
||||
prop = (prop_req, prop_block)
|
||||
rs_prop = (state_translate_rsc2rs(prop_req), state_translate_rsc2rs(prop_block))
|
||||
|
||||
if verify_rsc:
|
||||
smt_rsc = SmtCheckerRSC(rc)
|
||||
smt_rsc.check_reachability(prop,max_level=40)
|
||||
smt_rsc.check_reachability(prop, max_level=40)
|
||||
else:
|
||||
orc = rc.get_ordinary_reaction_system_with_automaton()
|
||||
if print_system:
|
||||
@@ -117,10 +124,10 @@ def state_translate_rsc2rs(p):
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
heat_shock_response()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
17
examples/smt/mutex_param.py
Normal file → Executable file
17
examples/smt/mutex_param.py
Normal file → Executable file
@@ -42,7 +42,7 @@ def powerset(iterable, N=None):
|
||||
def mutex_param_bench(cmd_args):
|
||||
"""
|
||||
Mutex Benchmark
|
||||
|
||||
|
||||
Parametric
|
||||
"""
|
||||
|
||||
@@ -77,7 +77,6 @@ def mutex_param_bench(cmd_args):
|
||||
Inhib = [("s", 1)]
|
||||
|
||||
for i in range(n_proc):
|
||||
|
||||
r.add_reaction([E("out", i), E("act", i)], Inhib, [E("req", i)])
|
||||
r.add_reaction([E("out", i)], [E("act", i)], [E("out", i)])
|
||||
|
||||
@@ -189,7 +188,7 @@ def mutex_param_bench(cmd_args):
|
||||
def mutex_nonparam_bench(cmd_args):
|
||||
"""
|
||||
Mutex Benchmark
|
||||
|
||||
|
||||
Parametric
|
||||
"""
|
||||
|
||||
@@ -217,7 +216,6 @@ def mutex_nonparam_bench(cmd_args):
|
||||
Inhib = [("s", 1)]
|
||||
|
||||
for i in range(n_proc):
|
||||
|
||||
r.add_reaction([E("out", i), E("act", i)], Inhib, [E("req", i)])
|
||||
r.add_reaction([E("out", i)], [E("act", i)], [E("out", i)])
|
||||
|
||||
@@ -297,7 +295,7 @@ def mutex_nonparam_bench(cmd_args):
|
||||
def mutex_nonparam_bench_oldimpl(cmd_args):
|
||||
"""
|
||||
Mutex Benchmark
|
||||
|
||||
|
||||
Parametric
|
||||
"""
|
||||
|
||||
@@ -325,7 +323,6 @@ def mutex_nonparam_bench_oldimpl(cmd_args):
|
||||
Inhib = [("s", 1)]
|
||||
|
||||
for i in range(n_proc):
|
||||
|
||||
r.add_reaction([E("out", i), E("act", i)], Inhib, [E("req", i)])
|
||||
r.add_reaction([E("out", i)], [E("act", i)], [E("out", i)])
|
||||
|
||||
@@ -407,7 +404,6 @@ def state_translate_rsc2rs(p):
|
||||
|
||||
|
||||
def mutex_bench_main(cmd_args):
|
||||
|
||||
mode = cmd_args.mode
|
||||
|
||||
if mode == "p":
|
||||
@@ -422,17 +418,16 @@ def mutex_bench_main(cmd_args):
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument(
|
||||
"scaling",
|
||||
help="scaling parameter value",
|
||||
)
|
||||
|
||||
|
||||
parser.add_argument(
|
||||
"mode",
|
||||
choices=['p', 'np-p', 'np-np'],
|
||||
choices=["p", "np-p", "np-np"],
|
||||
help="Selects the mode: p - parameter synthesis (parametric implementation), np-p - non-parametric with parametric implementation (with the parameters substituted), np-np - non-parametric with non-parametric implementation (parameters substituted)",
|
||||
)
|
||||
|
||||
@@ -447,7 +442,7 @@ def main():
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
mutex_bench_main(args)
|
||||
|
||||
|
||||
|
||||
150
examples/smt/scalable_chain.py
Normal file → Executable file
150
examples/smt/scalable_chain.py
Normal file → Executable file
@@ -31,76 +31,102 @@ from itertools import chain, combinations
|
||||
import sys
|
||||
import resource
|
||||
|
||||
|
||||
def generate_system(chainLen, maxConc):
|
||||
"""
|
||||
This function generates the reaction system with concentrations
|
||||
for the scalable chain benchmark
|
||||
|
||||
|
||||
chainLen is the length of the chain
|
||||
maxConc is the maximal concentration
|
||||
"""
|
||||
|
||||
r = ReactionSystemWithConcentrations()
|
||||
r.add_bg_set_entity(("inc",1))
|
||||
r.add_bg_set_entity(("dec",1))
|
||||
|
||||
for i in range(1,chainLen+1):
|
||||
r.add_bg_set_entity(("e_" + str(i),maxConc))
|
||||
|
||||
for i in range(1,chainLen+1):
|
||||
ent = "e_" + str(i)
|
||||
r.add_reaction_inc(ent, "inc", [(ent, 1)],[(ent,maxConc)])
|
||||
r.add_reaction_dec(ent, "dec", [(ent, 1)],[])
|
||||
if i < chainLen:
|
||||
r.add_reaction([(ent,maxConc)],[],[("e_"+str(i+1),1)])
|
||||
|
||||
r.add_reaction([("e_" + str(chainLen),maxConc)],[("dec",1)],[("e_" + str(chainLen),maxConc)])
|
||||
|
||||
r = ReactionSystemWithConcentrations()
|
||||
r.add_bg_set_entity(("inc", 1))
|
||||
r.add_bg_set_entity(("dec", 1))
|
||||
|
||||
for i in range(1, chainLen + 1):
|
||||
r.add_bg_set_entity(("e_" + str(i), maxConc))
|
||||
|
||||
for i in range(1, chainLen + 1):
|
||||
ent = "e_" + str(i)
|
||||
r.add_reaction_inc(ent, "inc", [(ent, 1)], [(ent, maxConc)])
|
||||
r.add_reaction_dec(ent, "dec", [(ent, 1)], [])
|
||||
if i < chainLen:
|
||||
r.add_reaction([(ent, maxConc)], [], [("e_" + str(i + 1), 1)])
|
||||
|
||||
r.add_reaction(
|
||||
[("e_" + str(chainLen), maxConc)],
|
||||
[("dec", 1)],
|
||||
[("e_" + str(chainLen), maxConc)],
|
||||
)
|
||||
|
||||
c = ContextAutomatonWithConcentrations(r)
|
||||
c.add_init_state("init")
|
||||
c.add_state("working")
|
||||
c.add_transition("init", [("e_1",1),("inc",1)], "working")
|
||||
c.add_transition("working", [("inc",1)], "working")
|
||||
|
||||
rc = ReactionSystemWithAutomaton(r,c)
|
||||
c.add_transition("init", [("e_1", 1), ("inc", 1)], "working")
|
||||
c.add_transition("working", [("inc", 1)], "working")
|
||||
|
||||
rc = ReactionSystemWithAutomaton(r, c)
|
||||
|
||||
return rc
|
||||
|
||||
|
||||
def generate_formula(formula_number, chainLen, maxConc):
|
||||
"""
|
||||
This function generates the rsLTL formula
|
||||
This function generates the rsLTL formula
|
||||
corresponding to the formula_number parameter
|
||||
"""
|
||||
|
||||
if formula_number == 1:
|
||||
ret = Formula_rsLTL.f_F( BagDescription.f_entity("inc") > 0, (BagDescription.f_entity('e_'+str(chainLen)) >= maxConc) )
|
||||
ret = Formula_rsLTL.f_F(
|
||||
BagDescription.f_entity("inc") > 0,
|
||||
(BagDescription.f_entity("e_" + str(chainLen)) >= maxConc),
|
||||
)
|
||||
|
||||
elif formula_number == 2:
|
||||
f_tmp = Formula_rsLTL.f_F( BagDescription.f_entity("inc") > 0, (BagDescription.f_entity('e_'+str(chainLen)) == maxConc) )
|
||||
for i in range(chainLen-1,0,-1):
|
||||
f_tmp = Formula_rsLTL.f_F( BagDescription.f_entity("inc") > 0, f_tmp & (BagDescription.f_entity('e_'+str(i)) == maxConc) )
|
||||
f_tmp = Formula_rsLTL.f_F(
|
||||
BagDescription.f_entity("inc") > 0,
|
||||
(BagDescription.f_entity("e_" + str(chainLen)) == maxConc),
|
||||
)
|
||||
for i in range(chainLen - 1, 0, -1):
|
||||
f_tmp = Formula_rsLTL.f_F(
|
||||
BagDescription.f_entity("inc") > 0,
|
||||
f_tmp & (BagDescription.f_entity("e_" + str(i)) == maxConc),
|
||||
)
|
||||
ret = f_tmp
|
||||
|
||||
|
||||
elif formula_number == 3:
|
||||
ret = Formula_rsLTL.f_G( BagDescription.f_TRUE(),
|
||||
ret = Formula_rsLTL.f_G(
|
||||
BagDescription.f_TRUE(),
|
||||
Formula_rsLTL.f_Implies(
|
||||
(BagDescription.f_entity('e_1') == 1),
|
||||
(BagDescription.f_entity("e_1") == 1),
|
||||
Formula_rsLTL.f_F(
|
||||
BagDescription.f_entity("inc") > 0,
|
||||
(BagDescription.f_entity('e_'+str(chainLen)) == maxConc)
|
||||
)
|
||||
)
|
||||
(BagDescription.f_entity("e_" + str(chainLen)) == maxConc),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
elif formula_number == 4:
|
||||
ret = Formula_rsLTL.f_F( BagDescription.f_entity("inc") > 0 , BagDescription.f_entity('e_1') == maxConc )
|
||||
|
||||
ret = Formula_rsLTL.f_F(
|
||||
BagDescription.f_entity("inc") > 0,
|
||||
BagDescription.f_entity("e_1") == maxConc,
|
||||
)
|
||||
|
||||
elif formula_number == 5:
|
||||
ret = Formula_rsLTL.f_X(BagDescription.f_TRUE(), Formula_rsLTL.f_U( BagDescription.f_entity("inc") > 0 , BagDescription.f_entity('e_1') > 0, BagDescription.f_entity('e_2') > 0 ) )
|
||||
ret = Formula_rsLTL.f_X(
|
||||
BagDescription.f_TRUE(),
|
||||
Formula_rsLTL.f_U(
|
||||
BagDescription.f_entity("inc") > 0,
|
||||
BagDescription.f_entity("e_1") > 0,
|
||||
BagDescription.f_entity("e_2") > 0,
|
||||
),
|
||||
)
|
||||
|
||||
else:
|
||||
ret = None
|
||||
|
||||
|
||||
assert ret is not None, "Unknown formula"
|
||||
|
||||
return ret
|
||||
@@ -110,64 +136,64 @@ def save_statistics(smt_rsc, formula_number, chainLen, maxConc):
|
||||
"""
|
||||
Saves the statistics fetched from smt_rsc into files
|
||||
"""
|
||||
time=0
|
||||
mem_usage=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/(1024*1024)
|
||||
filename_t="bench_rsc_F" + str(formula_number) + "_time.log"
|
||||
filename_m="bench_rsc_F" + str(formula_number) + "_mem.log"
|
||||
time=smt_rsc.get_verification_time()
|
||||
time = 0
|
||||
mem_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / (1024 * 1024)
|
||||
filename_t = "bench_rsc_F" + str(formula_number) + "_time.log"
|
||||
filename_m = "bench_rsc_F" + str(formula_number) + "_mem.log"
|
||||
time = smt_rsc.get_verification_time()
|
||||
|
||||
f=open(filename_t, 'a')
|
||||
log_str="(" + str(chainLen) + "," + str(maxConc) + "," + str(time) + ")\n"
|
||||
f = open(filename_t, "a")
|
||||
log_str = "(" + str(chainLen) + "," + str(maxConc) + "," + str(time) + ")\n"
|
||||
f.write(log_str)
|
||||
f.close()
|
||||
|
||||
f=open(filename_m, 'a')
|
||||
log_str="(" + str(chainLen) + "," + str(maxConc) + "," + str(mem_usage) + ")\n"
|
||||
|
||||
f = open(filename_m, "a")
|
||||
log_str = "(" + str(chainLen) + "," + str(maxConc) + "," + str(mem_usage) + ")\n"
|
||||
f.write(log_str)
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
def scalable_chain(print_system=False):
|
||||
"""
|
||||
This is the entry point for the benchmark
|
||||
"""
|
||||
if len(sys.argv) < 1+3:
|
||||
if len(sys.argv) < 1 + 3:
|
||||
print("arguments: <chainLen> <maxConc> <formulaNumber>")
|
||||
exit(1)
|
||||
|
||||
chainLen=int(sys.argv[1]) # chain length
|
||||
maxConc=int(sys.argv[2]) # depth (max concentration)
|
||||
formula_number=int(sys.argv[3])
|
||||
|
||||
chainLen = int(sys.argv[1]) # chain length
|
||||
maxConc = int(sys.argv[2]) # depth (max concentration)
|
||||
formula_number = int(sys.argv[3])
|
||||
|
||||
if chainLen < 1 or maxConc < 1:
|
||||
print("be reasonable")
|
||||
exit(1)
|
||||
if not formula_number in range(1,5+1):
|
||||
if not formula_number in range(1, 5 + 1):
|
||||
print("formulaNumber must be in 1..5")
|
||||
exit(1)
|
||||
|
||||
|
||||
# Generate the reaction systems with concentrations
|
||||
rc = generate_system(chainLen, maxConc)
|
||||
|
||||
|
||||
# Generate the formula
|
||||
form = generate_formula(formula_number, chainLen, maxConc)
|
||||
|
||||
|
||||
# Optional dump/print of the system
|
||||
if print_system:
|
||||
rc.show()
|
||||
|
||||
|
||||
# Create an instance of the SMT checker for RS with concentrations
|
||||
smt_rsc = SmtCheckerRSC(rc)
|
||||
|
||||
|
||||
# Start the verification process
|
||||
smt_rsc.check_rsltl(formula=form)
|
||||
|
||||
|
||||
save_statistics(smt_rsc, formula_number, chainLen, maxConc)
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
scalable_chain(print_system=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user