Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
assert objective.amici_model is not objective2.amici_model
assert objective.amici_solver is not objective2.amici_solver
assert objective.steadystate_guesses is not \
objective2.steadystate_guesses
def test_sth():
yaml_file = "/home/yannik/benchmark-models-petab/Benchmark-Models/Boehm_JProteomeRes2014/Boehm_JProteomeRes2014.yaml"
#yaml_file = "/home/yannik/benchmark-models-petab/Benchmark-Models/Fujita_SciSignal2010/Fujita_SciSignal2010.yaml"
importer = pypesto.PetabImporter.from_yaml(yaml_file)
objective = importer.create_objective(hierarchical=True)
problem = importer.create_problem(objective)
problem.objective.amici_solver.setSensitivityMethod(amici.SensitivityMethod_adjoint)
print(importer.petab_problem.x_nominal_free_scaled)
ret = problem.objective(importer.petab_problem.x_nominal_free_scaled[:-6])
print(ret)
objective2 = importer.create_objective(hierarchical=False)
problem2 = importer.create_problem(objective2)
problem2.objective.amici_solver.setSensitivityMethod(amici.SensitivityMethod_adjoint)
ret = problem2.objective(importer.petab_problem.x_nominal_free_scaled)
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)
def test_sth():
yaml_file = "/home/yannik/benchmark-models-petab/Benchmark-Models/Boehm_JProteomeRes2014/Boehm_JProteomeRes2014.yaml"
#yaml_file = "/home/yannik/benchmark-models-petab/Benchmark-Models/Fujita_SciSignal2010/Fujita_SciSignal2010.yaml"
importer = pypesto.PetabImporter.from_yaml(yaml_file)
objective = importer.create_objective(hierarchical=True)
problem = importer.create_problem(objective)
problem.objective.amici_solver.setSensitivityMethod(amici.SensitivityMethod_adjoint)
print(importer.petab_problem.x_nominal_free_scaled)
ret = problem.objective(importer.petab_problem.x_nominal_free_scaled[:-6])
print(ret)
objective2 = importer.create_objective(hierarchical=False)
problem2 = importer.create_problem(objective2)
problem2.objective.amici_solver.setSensitivityMethod(amici.SensitivityMethod_adjoint)
ret = problem2.objective(importer.petab_problem.x_nominal_free_scaled)
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)
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)