How to use the pypesto.petab.PetabImporter.from_yaml 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_engine.py View on Github external
def test_deepcopy_objective():
    """Test copying objectives (needed for MultiProcessEngine)."""
    petab_importer = pypesto.petab.PetabImporter.from_yaml(
        folder_base + "Zheng_PNAS2012/Zheng_PNAS2012.yaml")
    objective = petab_importer.create_objective()

    objective.amici_solver.setSensitivityMethod(
        amici.SensitivityMethod_adjoint)

    objective2 = copy.deepcopy(objective)

    # test some properties
    assert objective.amici_model.getParameterIds() \
        == objective2.amici_model.getParameterIds()
    assert objective.amici_solver.getSensitivityOrder() \
        == objective2.amici_solver.getSensitivityOrder()
    assert objective.amici_solver.getSensitivityMethod() \
        == objective2.amici_solver.getSensitivityMethod()
    assert len(objective.edatas) == len(objective2.edatas)
github ICB-DCM / pyPESTO / test / test_petab_suite.py View on Github external
solution = petabtests.load_solution(case)
    gt_chi2 = solution[petabtests.CHI2]
    gt_llh = solution[petabtests.LLH]
    gt_simulation_dfs = solution[petabtests.SIMULATION_DFS]
    tol_chi2 = solution[petabtests.TOL_CHI2]
    tol_llh = solution[petabtests.TOL_LLH]
    tol_simulations = solution[petabtests.TOL_SIMULATIONS]

    # import petab problem
    yaml_file = os.path.join(case_dir, petabtests.problem_yaml_name(case))

    # unique folder for compiled amici model
    output_folder = f'amici_models/model_{case}'

    # import and create objective function
    importer = pypesto.petab.PetabImporter.from_yaml(
        yaml_file, output_folder=output_folder)
    model = importer.create_model()
    obj = importer.create_objective(model=model)

    # the scaled parameters
    problem_parameters = importer.petab_problem.x_nominal_scaled

    # simulate
    ret = obj(problem_parameters, sensi_orders=(0,), return_dict=True)

    # extract results
    rdatas = ret['rdatas']
    chi2 = sum(rdata['chi2'] for rdata in rdatas)
    llh = - ret['fval']
    simulation_df = amici.petab_objective.rdatas_to_measurement_df(
        rdatas, model, importer.petab_problem.measurement_df)
github ICB-DCM / pyPESTO / test / test_engine.py View on Github external
def _test_petab(engine):
    petab_importer = pypesto.petab.PetabImporter.from_yaml(
        folder_base + "Zheng_PNAS2012/Zheng_PNAS2012.yaml")
    objective = petab_importer.create_objective()
    problem = petab_importer.create_problem(objective)
    optimizer = pypesto.optimize.ScipyOptimizer(options={'maxiter': 10})
    result = pypesto.optimize.minimize(
        problem=problem, n_starts=3, engine=engine, optimizer=optimizer)
    assert len(result.optimize_result.as_list()) == 3
github ICB-DCM / pyPESTO / test / test_engine.py View on Github external
def test_pickle_objective():
    """Test serializing objectives (needed for MultiThreadEngine)."""
    petab_importer = pypesto.petab.PetabImporter.from_yaml(
        folder_base + "Zheng_PNAS2012/Zheng_PNAS2012.yaml")
    objective = petab_importer.create_objective()

    objective.amici_solver.setSensitivityMethod(
        amici.SensitivityMethod_adjoint)

    objective2 = pickle.loads(pickle.dumps(objective))

    # test some properties
    assert objective.amici_model.getParameterIds() \
        == objective2.amici_model.getParameterIds()
    assert objective.amici_solver.getSensitivityOrder() \
        == objective2.amici_solver.getSensitivityOrder()
    assert objective.amici_solver.getSensitivityMethod() \
        == objective2.amici_solver.getSensitivityMethod()
    assert len(objective.edatas) == len(objective2.edatas)