1616import numpy as np
1717import pandas as pd
1818import sympy as sp
19- from pydantic import AnyUrl , BaseModel , Field , field_validator
19+ from pydantic import (
20+ AnyUrl ,
21+ BaseModel ,
22+ ConfigDict ,
23+ Field ,
24+ field_validator ,
25+ )
2026
2127from ..v1 import (
2228 parameter_mapping ,
@@ -1124,9 +1130,13 @@ def model_dump(self, **kwargs) -> dict[str, Any]:
11241130class ModelFile (BaseModel ):
11251131 """A file in the PEtab problem configuration."""
11261132
1127- location : str | AnyUrl
1133+ location : AnyUrl | Path
11281134 language : str
11291135
1136+ model_config = ConfigDict (
1137+ validate_assignment = True ,
1138+ )
1139+
11301140
11311141class ExtensionConfig (BaseModel ):
11321142 """The configuration of a PEtab extension."""
@@ -1139,13 +1149,13 @@ class ProblemConfig(BaseModel):
11391149 """The PEtab problem configuration."""
11401150
11411151 #: The path to the PEtab problem configuration.
1142- filepath : str | AnyUrl | None = Field (
1152+ filepath : AnyUrl | Path | None = Field (
11431153 None ,
11441154 description = "The path to the PEtab problem configuration." ,
11451155 exclude = True ,
11461156 )
11471157 #: The base path to resolve relative paths.
1148- base_path : str | AnyUrl | None = Field (
1158+ base_path : AnyUrl | Path | None = Field (
11491159 None ,
11501160 description = "The base path to resolve relative paths." ,
11511161 exclude = True ,
@@ -1156,21 +1166,24 @@ class ProblemConfig(BaseModel):
11561166 # TODO https://github.com/PEtab-dev/PEtab/pull/641:
11571167 # rename to parameter_files in yaml for consistency with other files?
11581168 # always a list?
1159- parameter_files : list [str | AnyUrl ] = Field (
1169+ parameter_files : list [AnyUrl | Path ] = Field (
11601170 default = [], alias = PARAMETER_FILES
11611171 )
11621172
1163- # TODO: consider changing str to Path
11641173 model_files : dict [str , ModelFile ] | None = {}
1165- measurement_files : list [str | AnyUrl ] = []
1166- condition_files : list [str | AnyUrl ] = []
1167- experiment_files : list [str | AnyUrl ] = []
1168- observable_files : list [str | AnyUrl ] = []
1169- mapping_files : list [str | AnyUrl ] = []
1174+ measurement_files : list [AnyUrl | Path ] = []
1175+ condition_files : list [AnyUrl | Path ] = []
1176+ experiment_files : list [AnyUrl | Path ] = []
1177+ observable_files : list [AnyUrl | Path ] = []
1178+ mapping_files : list [AnyUrl | Path ] = []
11701179
11711180 #: Extensions used by the problem.
11721181 extensions : list [ExtensionConfig ] | dict = {}
11731182
1183+ model_config = ConfigDict (
1184+ validate_assignment = True ,
1185+ )
1186+
11741187 # convert parameter_file to list
11751188 @field_validator (
11761189 "parameter_files" ,
@@ -1194,7 +1207,24 @@ def to_yaml(self, filename: str | Path):
11941207 """
11951208 from ..v1 .yaml import write_yaml
11961209
1197- write_yaml (self .model_dump (by_alias = True ), filename )
1210+ data = self .model_dump (by_alias = True )
1211+ # convert Paths to strings for YAML serialization
1212+ for key in (
1213+ "measurement_files" ,
1214+ "condition_files" ,
1215+ "experiment_files" ,
1216+ "observable_files" ,
1217+ "mapping_files" ,
1218+ "parameter_files" ,
1219+ ):
1220+ data [key ] = list (map (str , data [key ]))
1221+
1222+ for model_id in data .get ("model_files" , {}):
1223+ data ["model_files" ][model_id ][MODEL_LOCATION ] = str (
1224+ data ["model_files" ][model_id ]["location" ]
1225+ )
1226+
1227+ write_yaml (data , filename )
11981228
11991229 @property
12001230 def format_version_tuple (self ) -> tuple [int , int , int , str ]:
0 commit comments