def dReal_process(filename):
    problem_string = exampleParametricCRN()
    print problem_string
    with open("./" + filename, "w") as f:
        f.write(problem_string)

    sc = SolverCallerDReal(model_path="./" + filename)
    result_file = sc.single_synthesis(precision=0.1)
    param_values = sc.getCRNValues(result_file[0])
    print param_values
    quit()
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=",")
Ejemplo n.º 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=",")
Ejemplo n.º 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 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=",")
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=",")
Ejemplo n.º 7
0
def process_solver_output(project_id):
    """Solve problem."""
    current_project = Project.query.filter_by(id=project_id).first()

    if current_project.user != current_user:
        flash('Not your project!', 'danger')
        return redirect('.')

    # TODO: check status
    if not current_project.status:
        flash('Input files fo iSAT/dReach not yet generated!', 'danger')
        return redirect(url_for('project.project', project_id=project_id))

    # construct CRN object and input files for solvers
    directory = os.path.join(current_app.config.get("UPLOAD_FOLDER"),
                             str(project_id))

    isat_problem, dreal_problem, flow, crn = getProblem(
        current_project.crn_sketch, current_project.spec)

    solver = request.form.get("solver")
    if solver == "iSAT":
        sc = SolverCallerISAT("./iSAT.hys",
                              isat_path=current_app.config.get("ISAT_PATH"))
    elif solver == "dReach":
        sc = SolverCallerDReal("./dReach.drh",
                               dreal_path=current_app.config.get("DREAL_PATH"))

    # pass as string isntead of file
    file_name = os.path.join(directory, "results")
    with open(file_name) as f:
        f.write(request.form.get("result"))

    vals, all_vals = sc.getCRNValues(file_name)

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

    with open(file_name + "-parameters.txt", "w") as f:
        f.write("Initial Conditions: %s\n" % initial_conditions)
        f.write("Flow: %\n" % parametrised_flow)

    t, sol, variable_names = sc.simulate_solutions(initial_conditions,
                                                   parametrised_flow,
                                                   plot_name=file_name +
                                                   "-simulation.png")
    savetxt(file_name + "-simulation.csv",
            sol,
            delimiter=",",
            header=",".join(variable_names))

    return redirect(url_for('project.project', project_id=project_id))
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=",")
Ejemplo n.º 9
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=",")
Ejemplo n.º 10
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=",")
Ejemplo n.º 11
0
def solve_project(project_id):
    """Solve problem."""
    current_project = Project.query.filter_by(id=project_id).first()

    if current_project.user != current_user:
        flash('Not your project!', 'danger')
        return redirect('.')

    # save form details
    current_project.crn_semantics = request.form.get("semantics")
    current_project.solver = request.form.get("solver")
    current_project.save()

    # Construct CRN object
    print current_project.crn_sketch

    # Make directory for project
    directory = os.path.join(current_app.config.get("UPLOAD_FOLDER"),
                             str(project_id))
    if not os.path.exists(directory):
        os.makedirs(directory)
    open(os.path.join(directory, 'results.txt'), 'a').close()

    # construct CRN object and input files for solvers

    isat_problem, dreal_problem, flow, crn = getProblem(
        current_project.crn_sketch, current_project.crn_code,
        current_project.spec)
    with open(os.path.join(directory, 'iSAT.hys'), 'w') as fp:
        fp.write(isat_problem)
    with open(os.path.join(directory, 'dReach.drh'), 'w') as fp:
        fp.write(dreal_problem)

    if request.form.get("solver") == "None":
        current_project.status = "Config file generated"
        current_project.save()
        return redirect(url_for('project.project', project_id=project_id))

    if not current_app.config.get("SOLVERS_ENABLED"):
        flash('SAT-ODE Solvers not enabled!', 'danger')
        return redirect(url_for('project.project', project_id=project_id))

    # Run solvers if requested
    current_project.status = "Running"
    current_project.save()

    if request.form.get("solver") == "iSAT":
        sc = SolverCallerISAT("./iSAT.hys",
                              isat_path=current_app.config.get("ISAT_PATH"))
    elif request.form.get("solver") == "dReach":
        sc = SolverCallerDReal("./dReach.drh",
                               dreal_path=current_app.config.get("DREAL_PATH"))

    result_files = sc.single_synthesis(cost=0)
    for file_name in result_files:
        vals, all_vals = sc.getCRNValues(file_name)

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

        with open(file_name + "-parameters.txt", "w") as f:
            f.write("Initial Conditions: %s\n" % initial_conditions)
            f.write("Flow: %\n" % parametrised_flow)

        t, sol, variable_names = sc.simulate_solutions(initial_conditions,
                                                       parametrised_flow,
                                                       plot_name=file_name +
                                                       "-simulation.png")
        savetxt(file_name + "-simulation.csv",
                sol,
                delimiter=",",
                header=",".join(variable_names))

    current_project.status = "Complete"
    current_project.save()

    return redirect(url_for('project.project', project_id=project_id))