@@ -312,7 +312,6 @@ def __iadd__(self, other: T) -> BaseTable[T]:
312312# SciML extension classes — imported after BaseTable is defined to avoid
313313# circular imports (sciml.py does not import from core.py).
314314from .extensions .sciml import ( # noqa: E402
315- HybridizationTable ,
316315 SciMLConfig ,
317316 SciMLExt ,
318317)
@@ -1350,44 +1349,12 @@ def from_yaml(
13501349 else None
13511350 )
13521351
1353- extensions = ProblemExtensions ()
1354- if config .extensions and config .extensions .get (C .EXT_ID_SCIML ):
1355- from petab_sciml import ArrayDataStandard , NNModel , NNModelStandard
1356-
1357- # Neural network classes are constructed via pytorch for now to get
1358- # the proper inputs
1359- neural_networks = [
1360- NNModel .from_pytorch_module (
1361- NNModelStandard .load_data (
1362- _generate_path (
1363- file_path = nn_config .location ,
1364- base_path = base_path ,
1365- )
1366- ).to_pytorch_module (),
1367- nn_model_id = nn_id ,
1368- )
1369- for nn_id , nn_config in (
1370- config .extensions [C .EXT_ID_SCIML ].neural_networks or {}
1371- ).items ()
1372- ]
1373-
1374- hybridization_tables = [
1375- HybridizationTable .from_tsv (f , base_path )
1376- for f in config .extensions [C .EXT_ID_SCIML ].hybridization_files
1377- ]
1378-
1379- array_data_files = [
1380- ArrayDataStandard .load_data (_generate_path (f , base_path ))
1381- for f in config .extensions [C .EXT_ID_SCIML ].array_files
1382- ]
1383-
1384- extensions = ProblemExtensions (
1385- sciml = SciMLExt (
1386- neural_networks = neural_networks ,
1387- hybridization_tables = hybridization_tables ,
1388- array_data_files = array_data_files ,
1389- )
1390- )
1352+ sciml = (
1353+ SciMLExt .from_config (config , base_path )
1354+ if config .extensions and config .extensions .get (C .EXT_ID_SCIML )
1355+ else None
1356+ )
1357+ extensions = ProblemExtensions (sciml = sciml )
13911358
13921359 return Problem (
13931360 config = config ,
@@ -2647,15 +2614,9 @@ def to_yaml(self, filename: str | Path):
26472614 # The schema requires a valid id or no id field at all.
26482615 del data ["id" ]
26492616
2650- for ext_id , d_ext in data [C .EXTENSIONS ]. items ( ):
2617+ for ext_id in list ( data [C .EXTENSIONS ]):
26512618 if ext_id == C .EXT_ID_SCIML :
2652- # convert Paths to strings
2653- for key in ("array_files" , "hybridization_files" ):
2654- d_ext [key ] = list (map (str , d_ext [key ]))
2655- for nn in d_ext ["neural_networks" ]:
2656- d_ext ["neural_networks" ][nn ][C .MODEL_LOCATION ] = str (
2657- d_ext ["neural_networks" ][nn ][C .MODEL_LOCATION ]
2658- )
2619+ data [C .EXTENSIONS ][ext_id ] = self .extensions [ext_id ].to_yaml ()
26592620
26602621 write_yaml (data , filename )
26612622
0 commit comments