Skip to content

Commit f758e5f

Browse files
committed
Non-local petab_sciml import
1 parent b8b1abf commit f758e5f

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

petab/v2/core.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
from ..versions import parse_version
5555
from . import C, get_observable_df
5656

57+
try:
58+
from petab_sciml import (
59+
ArrayData,
60+
ArrayDataStandard,
61+
NNModel,
62+
NNModelStandard,
63+
)
64+
except ModuleNotFoundError:
65+
pass
66+
5767
if TYPE_CHECKING:
5868
from ..v2.lint import ValidationResultList, ValidationTask
5969

@@ -1408,18 +1418,18 @@ def from_yaml(
14081418
)
14091419

14101420
# sciml extension
1411-
if config.extensions and config.extensions[C.SCIML]:
1412-
try:
1413-
from petab_sciml import (
1414-
ArrayDataStandard,
1415-
NNModel,
1416-
NNModelStandard,
1417-
)
1418-
except ImportError as e:
1419-
raise ImportError(
1420-
"To generate a PEtab SciML problem, (petab_sciml) must be"
1421-
"installed."
1422-
) from e
1421+
# if config.extensions and config.extensions[C.SCIML]:
1422+
# try:
1423+
# from petab_sciml import (
1424+
# ArrayDataStandard,
1425+
# NNModel,
1426+
# NNModelStandard,
1427+
# )
1428+
# except ImportError as e:
1429+
# raise ImportError(
1430+
# "To generate a PEtab SciML problem, (petab_sciml) must"
1431+
# "be installed."
1432+
# ) from e
14231433

14241434
# Neural network classes are constructed via pytorch for now to get the
14251435
# proper inputs
@@ -2435,8 +2445,7 @@ def add_hybridization(self, target_id: str, target_value: str):
24352445

24362446
def add_neural_network_from_dict(self, model_id: str, nn_dict: dict):
24372447
"""Add a SciML neural net from a dictionary."""
2438-
from petab_sciml import NNModel
2439-
2448+
# from petab_sciml import NNModel
24402449
nn_model = NNModel.model_validate(nn_dict)
24412450
nn_model.nn_model_id = model_id
24422451
self.neural_networks.append(nn_model)
@@ -2448,8 +2457,7 @@ def add_neural_network_from_yaml(
24482457
base_path: str | Path | None = None,
24492458
):
24502459
"""Add a SciML neural net from a yaml file."""
2451-
from petab_sciml import NNModelStandard
2452-
2460+
# from petab_sciml import NNModelStandard
24532461
self.neural_networks.append(
24542462
NNModelStandard.load_data(
24552463
_generate_path(
@@ -2462,8 +2470,7 @@ def add_neural_network_from_yaml(
24622470

24632471
def add_array_data_from_dict(self, array_data: dict):
24642472
"""Add SciML array data from a dictionary."""
2465-
from petab_sciml import ArrayData
2466-
2473+
# from petab_sciml import ArrayData
24672474
self.array_data_files.append(ArrayData.model_validate(array_data))
24682475

24692476
def add_array_data_from_hdf5(
@@ -2472,8 +2479,7 @@ def add_array_data_from_hdf5(
24722479
base_path: str | Path | None = None,
24732480
):
24742481
"""Add SciML array data from an hdf5 file."""
2475-
from petab_sciml import ArrayDataStandard
2476-
2482+
# from petab_sciml import ArrayDataStandard
24772483
self.array_data_files.append(
24782484
ArrayDataStandard.load_data(_generate_path(file_path, base_path))
24792485
)

0 commit comments

Comments
 (0)