1+ import tempfile
2+ from pathlib import Path
3+
4+ import pandas as pd
5+
6+ import petab .v2 as petab
17from petab .v2 import Problem
8+ from petab .v2 .C import (
9+ CONDITION_ID ,
10+ MEASUREMENT ,
11+ NOISE_FORMULA ,
12+ OBSERVABLE_FORMULA ,
13+ OBSERVABLE_ID ,
14+ SIMULATION_CONDITION_ID ,
15+ TIME ,
16+ )
217
318
419def test_load_remote ():
@@ -25,3 +40,68 @@ def test_auto_upgrade():
2540 problem = Problem .from_yaml (yaml_url )
2641 # TODO check something specifically different in a v2 problem
2742 assert isinstance (problem , Problem )
43+
44+
45+ def test_problem_from_yaml_multiple_files ():
46+ """Test loading PEtab version 2 yaml with multiple condition / measurement
47+ / observable files
48+ """
49+ yaml_config = """
50+ format_version: 2.0.0
51+ parameter_file:
52+ problems:
53+ - condition_files: [conditions1.tsv, conditions2.tsv]
54+ measurement_files: [measurements1.tsv, measurements2.tsv]
55+ observable_files: [observables1.tsv, observables2.tsv]
56+ model_files:
57+ """
58+
59+ with tempfile .TemporaryDirectory () as tmpdir :
60+ yaml_path = Path (tmpdir , "problem.yaml" )
61+ with open (yaml_path , "w" ) as f :
62+ f .write (yaml_config )
63+
64+ for i in (1 , 2 ):
65+ condition_df = pd .DataFrame (
66+ {
67+ CONDITION_ID : [f"condition{ i } " ],
68+ }
69+ )
70+ condition_df .set_index ([CONDITION_ID ], inplace = True )
71+ petab .write_condition_df (
72+ condition_df , Path (tmpdir , f"conditions{ i } .tsv" )
73+ )
74+
75+ measurement_df = pd .DataFrame (
76+ {
77+ SIMULATION_CONDITION_ID : [f"condition{ i } " ],
78+ OBSERVABLE_ID : [f"observable{ i } " ],
79+ TIME : [i ],
80+ MEASUREMENT : [1 ],
81+ }
82+ )
83+ petab .write_measurement_df (
84+ measurement_df , Path (tmpdir , f"measurements{ i } .tsv" )
85+ )
86+
87+ observables_df = pd .DataFrame (
88+ {
89+ OBSERVABLE_ID : [f"observable{ i } " ],
90+ OBSERVABLE_FORMULA : [1 ],
91+ NOISE_FORMULA : [1 ],
92+ }
93+ )
94+ petab .write_observable_df (
95+ observables_df , Path (tmpdir , f"observables{ i } .tsv" )
96+ )
97+
98+ petab_problem1 = petab .Problem .from_yaml (yaml_path )
99+
100+ # test that we can load the problem from a dict with a custom base path
101+ yaml_config = petab .load_yaml (yaml_path )
102+ petab_problem2 = petab .Problem .from_yaml (yaml_config , base_path = tmpdir )
103+
104+ for petab_problem in (petab_problem1 , petab_problem2 ):
105+ assert petab_problem .measurement_df .shape [0 ] == 2
106+ assert petab_problem .observable_df .shape [0 ] == 2
107+ assert petab_problem .condition_df .shape [0 ] == 2
0 commit comments