-
Notifications
You must be signed in to change notification settings - Fork 42
/
test_petab.py
56 lines (45 loc) · 1.58 KB
/
test_petab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import amici.petab_import
import petab
import pyabc.petab
import git
import os
import numpy as np
def test_import():
# download archive
benchmark_dir = "doc/examples/tmp/benchmark-models-petab"
if not os.path.exists(benchmark_dir):
git.Repo.clone_from(
"https://github.com/benchmarking-initiative"
"/benchmark-models-petab.git",
benchmark_dir, depth=1)
g = git.Git(benchmark_dir)
# update repo if online
try:
g.pull()
except git.exc.GitCommandError:
pass
# create problem
petab_problem = petab.Problem.from_yaml(os.path.join(
benchmark_dir, "Benchmark-Models",
"Boehm_JProteomeRes2014", "Boehm_JProteomeRes2014.yaml"))
# compile amici
model = amici.petab_import.import_petab_problem(petab_problem)
solver = model.getSolver()
# import to pyabc
importer = pyabc.petab.AmiciPetabImporter(petab_problem, model, solver)
# extract required objects
prior = importer.create_prior()
model = importer.create_model()
kernel = importer.create_kernel()
# call model
assert np.isclose(
model(petab_problem.x_nominal_free_scaled)['llh'], -138.221996)
# mini analysis
temperature = pyabc.Temperature(
enforce_exact_final_temperature=False,
schemes=[pyabc.AcceptanceRateScheme()])
acceptor = pyabc.StochasticAcceptor()
abc = pyabc.ABCSMC(model, prior, kernel, eps=temperature,
acceptor=acceptor, population_size=10)
abc.new(pyabc.storage.create_sqlite_db_id(), None)
abc.run(max_nr_populations=1)