Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# import to pyabc
importer = pyabc.petab.AmiciPetabImporter(
petab_problem, amici_model, solver)
model = importer.create_model(return_rdatas=True)
# simulate
problem_parameters = petab_problem.x_nominal_free_scaled
ret = model(problem_parameters)
llh = ret['llh']
# extract results
rdatas = ret['rdatas']
chi2 = sum(rdata['chi2'] for rdata in rdatas)
simulation_df = amici.petab_objective.rdatas_to_measurement_df(
rdatas, amici_model, importer.petab_problem.measurement_df)
petab.check_measurement_df(
simulation_df, importer.petab_problem.observable_df)
simulation_df = simulation_df.rename(
columns={petab.MEASUREMENT: petab.SIMULATION})
simulation_df[petab.TIME] = simulation_df[petab.TIME].astype(int)
# check if matches
chi2s_match = petabtests.evaluate_chi2(chi2, gt_chi2, tol_chi2)
llhs_match = petabtests.evaluate_llh(llh, gt_llh, tol_llh)
simulations_match = petabtests.evaluate_simulations(
[simulation_df], gt_simulation_dfs, tol_simulations)
# log matches
logger.log(logging.INFO if chi2s_match else logging.ERROR,
f"CHI2: simulated: {chi2}, expected: {gt_chi2},"
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)
petab.check_measurement_df(
simulation_df, importer.petab_problem.observable_df)
simulation_df = simulation_df.rename(
columns={petab.MEASUREMENT: petab.SIMULATION})
simulation_df[petab.TIME] = simulation_df[petab.TIME].astype(int)
# check if matches
chi2s_match = petabtests.evaluate_chi2(chi2, gt_chi2, tol_chi2)
llhs_match = petabtests.evaluate_llh(llh, gt_llh, tol_llh)
simulations_match = petabtests.evaluate_simulations(
[simulation_df], gt_simulation_dfs, tol_simulations)
# log matches
logger.log(logging.INFO if chi2s_match else logging.ERROR,
f"CHI2: simulated: {chi2}, expected: {gt_chi2},"