Skip to content

Commit 951f4e8

Browse files
dweindldilpath
andauthored
Add get_problem_yaml_path (#223)
Sometimes we want to have just the path instead of a petab.Problem. Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
1 parent f18ed73 commit 951f4e8

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/python/benchmark_models_petab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
Python tool to access the model collection.
55
"""
66

7-
from .base import get_problem
7+
from .base import get_problem, get_problem_yaml_path
88
from .C import MODEL_DIRS, MODELS, MODELS_DIR
99
from .version import __version__

src/python/benchmark_models_petab/base.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
"""Get a petab problem from the collection."""
22

3-
import os
3+
from pathlib import Path
44

55
import petab
66

77
from .C import MODELS_DIR
88

99

10+
def get_problem_yaml_path(id_: str) -> Path:
11+
"""Get the path to the PEtab problem YAML file.
12+
13+
Parameters
14+
----------
15+
id_: Problem name, as in `benchmark_models_petab.MODELS`.
16+
17+
Returns
18+
-------
19+
The path to the PEtab problem YAML file.
20+
"""
21+
yaml_path = Path(MODELS_DIR, id_, id_ + ".yaml")
22+
if not yaml_path.exists():
23+
yaml_path = Path(MODELS_DIR, id_, "problem.yaml")
24+
if not yaml_path.exists():
25+
raise ValueError(f"Could not find YAML for problem with ID `{id_}`.")
26+
return yaml_path
27+
28+
1029
def get_problem(id_: str) -> petab.Problem:
1130
"""Read PEtab problem from benchmark collection by name.
1231
@@ -18,6 +37,6 @@ def get_problem(id_: str) -> petab.Problem:
1837
-------
1938
The PEtab problem.
2039
"""
21-
yaml_file = os.path.join(MODELS_DIR, id_, id_ + ".yaml")
40+
yaml_file = get_problem_yaml_path(id_)
2241
petab_problem = petab.Problem.from_yaml(yaml_file)
2342
return petab_problem

0 commit comments

Comments
 (0)