Skip to content

Commit be3a5eb

Browse files
authored
Make model id optional for PySBModel (#318)
If no ID is given, use `pysb.Model.name` as fallback. As is already the case for SbmlModel and its `id` attribute.
1 parent 20f77f4 commit be3a5eb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

petab/v1/models/pysb_model.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import pysb
1111

12+
from .. import is_valid_identifier
1213
from . import MODEL_TYPE_PYSB
1314
from .model import Model
1415

@@ -53,14 +54,21 @@ class PySBModel(Model):
5354

5455
type_id = MODEL_TYPE_PYSB
5556

56-
def __init__(self, model: pysb.Model, model_id: str):
57+
def __init__(self, model: pysb.Model, model_id: str = None):
5758
super().__init__()
5859

5960
self.model = model
60-
self._model_id = model_id
61+
self._model_id = model_id or self.model.name
62+
63+
if not is_valid_identifier(self._model_id):
64+
raise ValueError(
65+
f"Model ID '{self._model_id}' is not a valid identifier. "
66+
"Either provide a valid identifier or change the model name "
67+
"to a valid PEtab model identifier."
68+
)
6169

6270
@staticmethod
63-
def from_file(filepath_or_buffer, model_id: str):
71+
def from_file(filepath_or_buffer, model_id: str = None):
6472
return PySBModel(
6573
model=_pysb_model_from_path(filepath_or_buffer), model_id=model_id
6674
)

0 commit comments

Comments
 (0)