How to use the pypesto.minimize function in pypesto

To help you get started, we’ve selected a few pypesto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ICB-DCM / pyPESTO / test / test_amici_objective.py View on Github external
def test_error_leastsquares_with_ssigma():
    petab_problem = petab.Problem.from_yaml(
        folder_base + "Zheng_PNAS2012/Zheng_PNAS2012.yaml")
    petab_problem.model_name = "Zheng_PNAS2012"
    importer = pypesto.PetabImporter(petab_problem)
    obj = importer.create_objective()
    problem = importer.create_problem(obj)

    optimizer = pypesto.ScipyOptimizer('ls_trf', options={'max_nfev': 50})
    with pytest.raises(RuntimeError):
        pypesto.minimize(
            problem=problem, optimizer=optimizer, n_starts=1,
            options=pypesto.OptimizeOptions(allow_failed_starts=False)
        )
github ICB-DCM / pyPESTO / test / test_hierarchical.py View on Github external
print(ret)

    problem.objective.amici_solver.setAbsoluteTolerance(1e-8)
    problem.objective.amici_solver.setRelativeTolerance(1e-8)
    problem2.objective.amici_solver.setAbsoluteTolerance(1e-8)
    problem2.objective.amici_solver.setRelativeTolerance(1e-8)
    n_starts = 50
    startpoints = pypesto.startpoint.latin_hypercube(n_starts=n_starts, lb=problem2.lb, ub=problem2.ub)
    problem.x_guesses = startpoints[:, :-6]
    print(problem.x_guesses)
    problem2.x_guesses = startpoints

    start_time = time.time()
    problem.objective.calculator.inner_solver = NumericalInnerSolver()
    engine = pypesto.MultiProcessEngine(n_procs=8)
    result = pypesto.minimize(problem, n_starts=n_starts, engine=engine)
    print(result.optimize_result.get_for_key('fval'))
    print(time.time() - start_time)

    start_time = time.time()
    problem.objective.calculator.inner_solver = AnalyticalInnerSolver()
    engine = pypesto.MultiProcessEngine(n_procs=8)
    result = pypesto.minimize(problem, n_starts=n_starts, engine=engine)
    print(result.optimize_result.get_for_key('fval'))
    print(time.time() - start_time)
github ICB-DCM / pyPESTO / test / test_sbml_conversion.py View on Github external
optimizer.temp_file = os.path.join('test', 'tmp_{index}.csv')

    dim = len(objective.x_ids)
    lb = -2 * np.ones((1, dim))
    ub = 2 * np.ones((1, dim))
    pars = objective.amici_model.getParameters()
    problem = pypesto.Problem(objective, lb, ub,
                              x_fixed_indices=fixed_pars,
                              x_fixed_vals=[pars[idx] for idx in fixed_pars])

    optimize_options = pypesto.OptimizeOptions(
        allow_failed_starts=False,
        startpoint_resample=True,
    )

    pypesto.minimize(problem, optimizer, n_starts, options=optimize_options)
github ICB-DCM / pyPESTO / test / test_petab_import.py View on Github external
def test_3_optimize(self):
        # run optimization
        for obj_edatas, importer in \
                zip(self.obj_edatas, self.petab_importers):
            obj = obj_edatas[0]
            optimizer = pypesto.ScipyOptimizer()
            problem = importer.create_problem(obj)
            result = pypesto.minimize(
                problem=problem, optimizer=optimizer, n_starts=2)

            self.assertTrue(np.isfinite(
                result.optimize_result.get_for_key('fval')[0]))
github ICB-DCM / pyPESTO / test / test_optimize.py View on Github external
elif library == 'ipopt':
        optimizer = pypesto.IpoptOptimizer()
    elif library == 'dlib':
        optimizer = pypesto.DlibOptimizer(method=solver,
                                          options=options)
    elif library == 'pyswarm':
        optimizer = pypesto.PyswarmOptimizer(options=options)

    lb = 0 * np.ones((1, 2))
    ub = 1 * np.ones((1, 2))
    problem = pypesto.Problem(objective, lb, ub)

    optimize_options = pypesto.OptimizeOptions(
        allow_failed_starts=allow_failed_starts)

    result = pypesto.minimize(
        problem=problem,
        optimizer=optimizer,
        n_starts=1,
        startpoint_method=pypesto.startpoint.uniform,
        options=optimize_options
    )

    assert isinstance(result.optimize_result.list[0]['fval'], float)
github ICB-DCM / pyPESTO / test / test_history.py View on Github external
kwargs = {**kwargs, **{
                'x_fixed_indices': self.x_fixed_indices,
                'x_fixed_vals': self.x_fixed_indices
            }}
        self.problem = pypesto.Problem(**kwargs)

        optimize_options = pypesto.OptimizeOptions(
            allow_failed_starts=False
        )

        self.history_options.trace_save_iter = 1

        for storage_file in ['tmp/traces/conversion_example_{id}.csv', None]:
            self.history_options.storage_file = storage_file

            result = pypesto.minimize(
                problem=self.problem,
                optimizer=self.optimizer,
                n_starts=1,
                startpoint_method=pypesto.startpoint.uniform,
                options=optimize_options,
                history_options=self.history_options
            )

            for istart, start in enumerate(result.optimize_result.list):
                self.check_reconstruct_history(start, str(istart))
                self.check_load_from_file(start, str(istart))
                self.check_history_consistency(start)