diff --git a/petab/v2/core.py b/petab/v2/core.py index 79d57729..a7e54e52 100644 --- a/petab/v2/core.py +++ b/petab/v2/core.py @@ -316,8 +316,8 @@ def __iadd__(self, other: T) -> BaseTable[T]: class ProblemExtensions: """Runtime extension state attached to a :class:`Problem`.""" - def __init__(self, sciml: SciMLExt = None): - self.sciml: SciMLExt = sciml or SciMLExt() + def __init__(self, sciml: SciMLExt | None = None): + self.sciml: SciMLExt | None = sciml class Observable(BaseModel): diff --git a/tests/v2/test_sciml.py b/tests/v2/test_sciml.py index 65157e41..f6cedc28 100644 --- a/tests/v2/test_sciml.py +++ b/tests/v2/test_sciml.py @@ -4,11 +4,12 @@ from pydantic import ConfigDict from petab.v2.core import * -from petab.v2.core import ModelFile +from petab.v2.core import ModelFile, ProblemExtensions from petab.v2.extensions.sciml import ( Hybridization, NeuralNetConfig, SciMLConfig, + SciMLExt, ) from petab.v2.extensions.sciml_lint import ( CheckArrayDataFiles, @@ -46,7 +47,8 @@ def _get_test_problem(): }, ) }, - ) + ), + extensions=ProblemExtensions(sciml=SciMLExt()), ) problem.model = SbmlModel.from_antimony(""" model lv @@ -152,6 +154,15 @@ def _get_test_problem(): return problem +def test_extensions_sciml_none_by_default(): + """`Problem.extensions.sciml` is `None` unless the sciml extension is + actually used.""" + assert Problem().extensions.sciml is None + + problem = _get_test_problem() + assert problem.extensions.sciml is not None + + def test_lint(): problem = _get_test_problem() assert problem.validate() == []