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:
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