Skip to content

Commit 6a67cf3

Browse files
committed
GHA: Add simulation workflow
Add workflow to check that all problems can be simulated. This will run for quite some time.
1 parent 864a39b commit 6a67cf3

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.github/workflows/simulate.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Simulate
2+
on: [push, pull_request, workflow_dispatch]
3+
4+
jobs:
5+
simulate_amici:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Check out repository
9+
uses: actions/checkout@v5
10+
11+
- name: Prepare Python
12+
uses: actions/setup-python@v6
13+
with:
14+
python-version: "3.13"
15+
16+
- name: Install AMICI
17+
run: |
18+
pip install --upgrade pip
19+
# TODO: once amici 1.0 is released, replace with:
20+
# pip install amici[petab]
21+
pip install petab
22+
pip install "git+https://github.com/dweindl/amici.git@6a85422ad233fc268fb71272bba39f5b82db387a#egg=amici&subdirectory=python/sdist"
23+
24+
- name: Simulate with nominal parameters
25+
run: |
26+
for problem in `ls -1 Benchmark-Models/`; do
27+
python src/python/simulate.py "$problem" -j
28+
echo
29+
done

src/python/simulate.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to simulate a model using AMICI.
4+
5+
Basic usage: simulate.py <problem_id>
6+
See --help for more options.
7+
"""
8+
9+
import os
10+
import argparse
11+
import benchmark_models_petab
12+
import amici.sim.sundials as ass
13+
from amici.importers.petab.v1 import (
14+
import_petab_problem,
15+
simulate_petab,
16+
LLH,
17+
RDATAS,
18+
)
19+
20+
21+
def parse_cli_args():
22+
"""Parse command line arguments."""
23+
parser = argparse.ArgumentParser(
24+
description="Simulate a model using AMICI."
25+
)
26+
parser.add_argument(
27+
"problem_id",
28+
type=str,
29+
help="Identifier for the problem/model to simulate.",
30+
)
31+
parser.add_argument(
32+
"-j",
33+
dest="num_threads",
34+
nargs="?",
35+
default=None,
36+
const="all",
37+
help=(
38+
"Number of cores to use. "
39+
"`-j` (no value) uses all available cores. "
40+
"If omitted, threading is left unchanged."
41+
),
42+
)
43+
args = parser.parse_args()
44+
45+
args.num_threads = (
46+
os.cpu_count()
47+
if args.num_threads == "all"
48+
else 1
49+
if args.num_threads is None
50+
else max(1, int(args.num_threads))
51+
)
52+
53+
return args
54+
55+
56+
def main():
57+
"""Simulate a PEtab problem with AMICI using nominal parameter values."""
58+
args = parse_cli_args()
59+
60+
# Import and simulate
61+
print(args.problem_id)
62+
print("-" * len(args.problem_id))
63+
64+
problem = benchmark_models_petab.get_problem(args.problem_id)
65+
66+
model = import_petab_problem(problem, generate_sensitivity_code=False)
67+
solver = model.create_solver()
68+
solver.set_return_data_reporting_mode(
69+
ass.RDataReporting.observables_likelihood
70+
)
71+
res = simulate_petab(
72+
problem, model, solver=solver, num_threads=args.num_threads
73+
)
74+
75+
for rdata in res[RDATAS]:
76+
print(
77+
f"{rdata.id}: llh = {rdata.llh}, chi2 = {rdata.chi2}, status = {rdata.status}"
78+
)
79+
80+
print()
81+
print("Total log-likelihood:", res[LLH])
82+
print()
83+
84+
85+
if __name__ == "__main__":
86+
main()

0 commit comments

Comments
 (0)