def synthesize_with_dreal(crn):
    derivatives = [{"variable": 'PThree', "order": 1, "is_variance": False, "name": "PThree_dot"}]
    flow = crn.flow(False, derivatives)

    #specification_dreal = [('', '', 'PThree > 0.4 '), ('', '', 'PThree < 0.3')]
    specification_dreal = [('','PThree_dot >= 0','and (PThree_dot < 0.01) (PThree > 0.4) '),('','PThree_dot <= 0','(PThree < 0.3)')]
    #specification_dreal = [('', 'PThree_dot >= 0', '(and (PThree > 0.3) (PThree_dot = 0))'), ('', 'PThree_dot <= 0', '(and (PThree >= 0)(PThree < 0.1))')]

    drh = iSATParser.constructdReal(crn, specification_dreal, flow, other_constraints='(PThree < 0.4)',scale_factor=1)
    with open('sixreactionnetwork.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./sixreactionnetwork.drh", dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1)

    for file_name in result_files:
            vals, all_vals = sc.getCRNValues('./sixreactionnetwork_1_0.smt2.proof')
            initial_conditions, parametrised_flow = sc.get_full_solution(crn, flow, all_vals)

            print("Initial Conditions", initial_conditions)
            print("Flow:", parametrised_flow)
            t, sol, variable_names = sc.simulate_solutions(initial_conditions, parametrised_flow,
                                                           plot_name=file_name + "-simulationdreal.png", t = linspace(0, 10, 1000))
            print("\n\n")
            print(variable_names)
            print(sol)
            savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
def synthesize_with_dreal(crn):


    derivatives = [{"variable": 'PThreeStar', "order": 1, "is_variance": False, "name": "PThreeStar_dot"}]
    flow = crn.flow(False, derivatives)


    specification_dreal = [('', '', '(inputTime > 20)'),
                           ('', '(PThreeStar_dot > 0)', '(and (PThreeStar > 0.5)(abs(PThreeStar_dot) < 0.01))'),
                           ('', 'abs(PThreeStar_dot) < 0.01', 'inputTime > 100')]

    #flow = crn.flow(False, derivatives)
    #specification_dreal = [('', '', '')]

    drh = iSATParser.constructdReal(crn, specification_dreal, flow, max_time=350, other_constraints='', scale_factor=1)
    with open('switch.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./switch.drh", dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1, max_depth=len(specification_dreal))

    for file_name in result_files:
        vals, all_vals = sc.getCRNValues('./switch_2_0.smt2.proof')
        initial_conditions, parametrised_flow = sc.get_full_solution(crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)
        t, sol, variable_names = sc.simulate_solutions(initial_conditions, parametrised_flow,
                                                       plot_name=file_name + "-simulationdreal.png",
                                                       t=linspace(0, 300, 1000))
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
Beispiel #3
0
def synthesize_with_dreal(crn):
    derivatives = []
    flow = crn.flow(False, derivatives)

    specification_dreal = [('', '', '(X < 0.1)')]
    drh = iSATParser.constructdReal(crn, specification_dreal, flow)
    with open('simple.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./simple.drh", dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0)

    for file_name in result_files:
        print("\n\n")
        # print(sc.getCRNValues(file_name))

        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(initial_conditions, parametrised_flow,
                                                       plot_name=file_name + "-simulationdreal.png")
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
Beispiel #4
0
def synthesize_with_dreal(crn):

    isLNA = False
    derivatives = []
    #specification_dreal = [('','','')]
    specification_dreal = [('', '', '(and (inputTime > 70)(cIts > 10))')]
    flow = crn.flow(False, derivatives)
    drh = iSATParser.constructdReal(crn,
                                    specification_dreal,
                                    flow,
                                    max_time=100)
    with open('toggleswitch.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./toggleswitch.drh",
                           dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1)

    for file_name in result_files:
        vals, all_vals = sc.getCRNValues('./toggleswitch_0_0.smt2.proof')
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)
        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulationdreal.png",
            t=linspace(0, 100, 200))  # mode_times=all_vals["time"])

        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
def exampleParametricCRN():

    X = Species('X')
    Y = Species('Y')
    B = Species('B')

    k1 = RateConstant('k_1', 0.1, 10)
    k2 = RateConstant('k_2', 0.1, 10)
    k3 = RateConstant('k_3', 0.1, 10)

    reaction1 = Reaction([Term(LambdaChoice([X, Y], 1), 1),
                          Term(Y, 1)], [Term(X, 1), Term(B, 1)], k1)
    reaction2 = Reaction(
        [Term(LambdaChoice([X, Y], 2), 1),
         Term(X, Choice(0, 0, 2))], [Term(Y, 1), Term(B, 1)], k2)
    reaction3 = Reaction([Term(X, 1), Term(B, 1)],
                         [Term(X, 1), Term(X, 1)], k3)
    reaction4 = Reaction([Term(X, 1), Term(B, 1)],
                         [Term(X, 1), Term(X, 1)], k3)

    crn = CRNSketch([reaction1, reaction2, reaction3], [reaction4], [])

    isLNA = False
    derivatives = []
    specification = []

    flow = crn.flow(isLNA, derivatives)
    return iSATParser.constructdReal(crn, specification, flow)
def exampleLotkaOscillator(solver='iSAT'):
    A = Species('A')
    B = Species('B')

    k1 = RateConstant('k_1', 0.01, 2)
    k2 = RateConstant('k_2', 0.01, 2)
    k3 = RateConstant('k_3', 0.01, 2)

    reaction1 = Reaction([Term(A, 1)], [Term(A, 2)], k1)
    reaction2 = Reaction([Term(A, 1), Term(B, 1)], [Term(B, 2)], k2)
    reaction3 = Reaction([Term(B, 1)], [], k3)

    crn = CRNSketch([reaction1, reaction2, reaction3], [], [])

    isLNA = False
    derivatives = [{
        "variable": 'A',
        "order": 1,
        "is_variance": False,
        "name": "A_dot"
    }, {
        "variable": 'B',
        "order": 1,
        "is_variance": False,
        "name": "B_dot"
    }]

    specification = [(0.1, 'A_dot = 0'), (0.2, 'A_dot < 0 or A_dot > 0'),
                     (0.3, 'A_dot = 0')]

    flow = crn.flow(isLNA, derivatives)
    if solver is 'iSAT':
        return iSATParser.constructISAT(crn, specification, flow)
    elif solver is 'dReal':
        return iSATParser.constructdReal(crn, specification, flow)
def getProblem(crn_sketch_string, crn_code, specification_string):

    if specification_string:
        input_species = get_input_species(specification_string)
        isLNA, requiredDerivatives, specification = construct_specification(
            specification_string)
    else:
        input_species = []
        isLNA = False
        requiredDerivatives = []
        specification = []

    crn = {}
    constraints = []
    if crn_code:
        exec(crn_code)
    else:
        crn_details = CRNbuilder(crn_sketch_string, input_species)
        crn = CRNSketch(crn_details.required_reactions,
                        crn_details.optional_reactions, input_species)
        constraints = crn_details.constraints

    flow = crn.flow(isLNA, requiredDerivatives)
    isat_problem, modes = iSATParser.constructISAT(crn, specification, flow,
                                                   constraints), specification
    dreal_problem, modes = iSATParser.constructdReal(
        crn, specification, flow, constraints), specification

    return isat_problem, dreal_problem, flow, crn
def synthesize_with_dreal(crn):
    derivatives = []
    flow = crn.flow(True, derivatives)

    specification_dreal = [('', 'varA >= A', 'A > 0.3')]
    #specification_dreal = [('','','')]
    drh = iSATParser.constructdReal(crn,
                                    specification_dreal,
                                    flow,
                                    max_time=20)
    with open('superpoisson.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./superpoisson.drh",
                           dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1)

    for file_name in result_files:
        vals, all_vals = sc.getCRNValues('./superpoisson_0_0.smt2.proof')
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)
        t, sol, variable_names = sc.simulate_solutions(initial_conditions,
                                                       parametrised_flow,
                                                       plot_name=file_name +
                                                       "-simulationdreal.png",
                                                       t=linspace(0, 20, 100),
                                                       lna=True)
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
def synthesize_with_dreal(crn):

    derivatives = [{
        "variable": 'PThreeStar',
        "order": 1,
        "is_variance": False,
        "name": "PThreeStar_dot"
    }]
    flow = crn.flow(False, derivatives)

    # specification_dreal = [('', '', 'PThree > 0.4 '), ('', '', 'PThree < 0.3')]
    # specification_dreal = [('','','(PThreeStar > 0.5) '),('','','(PThreeStar < 0.4)')]
    # specification_dreal = [('', 'PThree_dot >= 0', '(and (PThree > 0.3) (PThree_dot = 0))'), ('', 'PThree_dot <= 0', '(and (PThree >= 0)(PThree < 0.1))')]
    # specification_dreal = [('', '', '(and ((inputTime > 100)(PThreeStar < 0.75))'),
    #  ('', '', '(PThreeStar > 0.9)')]

    specification_dreal = [('', '', 'inputTime > 20'),
                           ('', 'PThreeStar_dot < 0', '(PThreeStar_dot=0)'),
                           ('', 'PThreeStar_dot > 0', '(PThreeStar_dot=0)'),
                           ('', 'PThreeStar_dot < 0', 'PThreeStar_dot = 0'),
                           ('', 'PThreeStar_dot = 0', 'inputTime > 100')]

    #flow = crn.flow(False, [])

    drh = iSATParser.constructdReal(crn,
                                    specification_dreal,
                                    flow,
                                    max_time=350,
                                    other_constraints='',
                                    scale_factor=1)
    with open('topology365.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./topology365.drh",
                           dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1)

    for file_name in result_files:
        vals, all_vals = sc.getCRNValues('./topology365_0_0.smt2.proof')
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)
        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulationdreal.png",
            t=linspace(0, 300, 1000),
            hidden_variables="POne,POneStar,PTwo,PTwoStar,PThree")
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
Beispiel #10
0
def synthesize_with_dreal(crn, name, specification_dreal, result_file):

    derivatives = [{
        "variable": 'PThreeStar',
        "order": 1,
        "is_variance": False,
        "name": "PThreeStar_dot"
    }]
    flow = crn.flow(False, derivatives)

    #flow = crn.flow(False, derivatives)
    #specification_dreal = [('', '', '')]

    drh = iSATParser.constructdReal(crn,
                                    specification_dreal,
                                    flow,
                                    max_time=350 / SF,
                                    other_constraints='',
                                    scale_factor=SF)
    with open(name, 'w') as file:
        file.write(drh)

    #sc = SolverCallerDReal(name, dreal_path="/code/dReal-3.16.06.02-linux/bin/dReach")
    sc = SolverCallerDReal(
        name, dreal_path="/code/dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1)

    for file_name in [result_file]:  # TODO: remove ths aegument

        print file_name

        # './inverted-bell_3_0.smt2.proof'
        vals, all_vals = sc.getCRNValues(file_name)
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)
        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulationdreal.png",
            t=linspace(0, 350, 1000),
            mode_times=all_vals["time"],
            hidden_variables="POne,POneStar,PTwo,PTwoStar,PThree")
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
def exampleParametricCRN_complete():
    X = Species('X', initial_max=5)
    Y = Species('Y', initial_value=12)
    B = Species('B')

    reaction1 = Reaction([(LambdaChoice([X, Y], 1), 1), (Y, 1)], [(X, 1),
                                                                  (B, 1)],
                         RateConstant('k_1', 1, 2))
    reaction2 = Reaction([(LambdaChoice([X, Y], 2), 1), (X, Choice(0, 0, 3))],
                         [(Y, 1), (B, 1)], RateConstant('k_2', 1, 2))
    reaction3 = Reaction([(X, 1), (B, 1)], [(X, 1), (X, 1)],
                         RateConstant('k_3', 1, 2))
    reaction4 = Reaction([(X, 1), (B, 1)], [(X, 1), (X, 1)],
                         RateConstant('k_4', 1, 2))

    input1 = InputSpecies(
        "Input1",
        sympify(
            "0.1*t + 54.2735055776743*exp(-(0.04*t - 2.81375654916915)**2) + 35.5555607722356/(1.04836341039216e+15*(1/t)**10.0 + 1)"
        ), 15)
    reaction5 = Reaction([Term(input1, 1)], [Term(B, 1)],
                         RateConstant('k_input', 1, 2))

    isLNA = False
    derivatives = [{
        "variable": 'X',
        "order": 1,
        "is_variance": False,
        "name": "X_dot"
    }, {
        "variable": 'X',
        "order": 2,
        "is_variance": False,
        "name": "X_dot_dot"
    }, {
        "variable": 'X',
        "order": 2,
        "is_variance": True,
        "name": "covX_dot_dot"
    }]
    #derivatives = []
    specification = [(0, 'X = 0'), (0.5, 'X = 0.5'), (1, 'X = 0')]

    crn = CRNSketch([reaction1, reaction2, reaction3, reaction5], [reaction4],
                    [input1])
    flow = crn.flow(isLNA, derivatives)
    crn.get_cost()

    return iSATParser.constructdReal(crn, specification, flow, costFunction='')
Beispiel #12
0
def synthesize_with_dreal(crn):
    derivatives = [{
        "variable": 'L3p',
        "order": 1,
        "is_variance": False,
        "name": "L3p_dot"
    }, {
        "variable": 'L3p',
        "order": 2,
        "is_variance": False,
        "name": "L3p_dot_dot"
    }]
    flow = crn.flow(False, derivatives)

    specification_dreal = [('', '(and (L3p_dot >= 0)(L3p_dot_dot >= 0))',
                            '(and (L3p_dot_dot = 0)(B > 4/SF))'),
                           ('', '(and (L3p_dot >= 0)(L3p_dot_dot <= 0))', '')]
    #specification_dreal = [('','','')]
    drh = iSATParser.constructdReal(crn,
                                    specification_dreal,
                                    flow,
                                    max_time=50 / SF,
                                    scale_factor=SF)
    with open('phosphorelay.drh', 'w') as file:
        file.write(drh)

    sc = SolverCallerDReal("./phosphorelay.drh",
                           dreal_path="../dReal-3.16.09.01-linux/bin/dReach")
    result_files = sc.single_synthesis(cost=0, precision=0.1)

    for file_name in result_files:
        vals, all_vals = sc.getCRNValues('./phosphorelay_1_0.smt2.proof')
        initial_conditions, parametrised_flow = sc.get_full_solution(
            crn, flow, all_vals, scale_factor=SF)

        print("Initial Conditions", initial_conditions)
        print("Flow:", parametrised_flow)
        t, sol, variable_names = sc.simulate_solutions(
            initial_conditions,
            parametrised_flow,
            plot_name=file_name + "-simulationdreal.png",
            t=linspace(0, 50 / SF, 100),
            mode_times=all_vals["time"],
            hidden_variables="B")
        print("\n\n")
        print(variable_names)
        print(sol)
        savetxt(file_name + "-simulationdreal.csv", sol, delimiter=",")
def exampleToggleSwitch():
    lacl = Species('lacl')
    clts = Species('clts')

    empty_1 = Species('empty_1')
    empty_2 = Species('empty_2')
    empty_3 = Species('empty_3')
    empty_4 = Species('empty_4')

    a_2 = RateConstant('a_2', 0.1, 2)
    a_4 = RateConstant('a_4', 0.1, 2)

    alpha_1 = RateConstant('alpha_1', 0.1, 5)
    alpha_2 = RateConstant('alpha_2', 0.1, 5)

    beta = RateConstant('beta', 0.1, 5)
    gamma = RateConstant('gamma', 0.1, 5)

    #a_1 = RateConstant(str(alpha_1.symbol / 1 + (clts.symbol ** beta.symbol)), 0, 5)
    # a_3 = RateConstant(str(alpha_2.symbol / 1 + (lacl.symbol ** gamma.symbol)), 0, 5)

    a_1 = RateConstant('a_1', 0, 5)
    a_3 = RateConstant('a_3', 0, 5)
    input1 = InputSpecies(
        "Input1",
        sympify(
            "0.1*t + 54.2735055776743*exp(-(0.04*t - 2.81375654916915)**2) + 35.5555607722356/(1.04836341039216e+15*(1/t)**10.0 + 1)"
        ), 15)

    reaction1 = Reaction([Term(empty_1, 1)], [Term(lacl, 1)], a_1)
    reaction2 = Reaction([Term(lacl, 1)], [Term(empty_2, 1)], a_2)
    reaction3 = Reaction([Term(empty_3, 1)], [Term(clts, 1)], a_3)
    reaction4 = Reaction([Term(clts, 1)], [Term(empty_4, 1)], a_4)

    crn = CRNSketch([reaction1, reaction2, reaction3, reaction4], [], [input1])

    isLNA = False
    derivatives = []
    specification = []

    flow = crn.flow(isLNA, derivatives)

    return iSATParser.constructdReal(crn, specification, flow)
def mixedMMExample():
    A = Species('A')
    g = Species('g')
    Ag = Species('Ag')
    Out = Species('Out')

    vAmax = RateConstant('VA_max', 0.5, 5)
    vBmax = RateConstant('VB_max', 0.5, 5)
    vConstant = RateConstant('vConstant', 0.5, 0.5)

    reaction1 = MichaelisMentenReaction([(A, 1), (g, 1)], [(Ag, 1), (A, 1)],
                                        vAmax, vConstant)
    reaction2 = MichaelisMentenReaction([(Ag, 1)], [(A, 1), (g, 1)], vBmax,
                                        vConstant)
    reaction3 = Reaction([Term(Ag, 1)], [Term(Out, 1)],
                         RateConstant('k1', 0.1, 5))
    reaction4 = Reaction([Term(Out, 1)], [], RateConstant('k2', 0.1, 5))

    isLNA = True
    derivatives = [{
        "variable": 'Out',
        "order": 1,
        "is_variance": False,
        "name": "dOut"
    }, {
        "variable": 'Out',
        "order": 2,
        "is_variance": False,
        "name": "ddOut"
    }]

    #Here specification should be when second derivative is 0 we want variance of O < certain threshold
    #specification = [(0, 'O = 0'), (0.5, 'O < 0.5'), (1, 'O > 1')]
    specification = [('', '', 'ddOut = 0'), ('', 'covAg > 10'),
                     ('', 'Out > 1')]
    crn = CRNSketch([reaction1, reaction2, reaction3, reaction4], [], [])
    flow = crn.flow(isLNA, derivatives)
    return flow, iSATParser.constructdReal(crn, specification, flow)