diff --git a/mira/modeling/amr/regnet.py b/mira/modeling/amr/regnet.py index 2f0d7c383..a9823ae5f 100644 --- a/mira/modeling/amr/regnet.py +++ b/mira/modeling/amr/regnet.py @@ -9,7 +9,7 @@ import json import logging from copy import deepcopy -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Union import sympy from pydantic import BaseModel, Field @@ -66,9 +66,14 @@ def __init__(self, model: Model): } initial = var.data.get('expression') if initial is not None: - if isinstance(initial, float): - initial = safe_parse_expr(str(initial)) - state_data['initial'] = str(initial) + # Here, initial is a SympyExprStr, and if its + # value is a float, we export it as a float, + # otherwise we export it as a string + try: + initial_float = float(initial.args[0]) + state_data['initial'] = initial_float + except TypeError: + state_data['initial'] = str(initial) self.states.append(state_data) self._states_by_id[name] = state_data @@ -315,7 +320,7 @@ def template_model_to_regnet_json(tm: TemplateModel): class Initial(BaseModel): - expression: str + expression: Union[str, float] expression_mathml: str diff --git a/notebooks/hackathon_2024.02/scenario4/scenario4_4spec_regnet.json b/notebooks/hackathon_2024.02/scenario4/scenario4_4spec_regnet.json index 2369e2c14..f8ca03c81 100644 --- a/notebooks/hackathon_2024.02/scenario4/scenario4_4spec_regnet.json +++ b/notebooks/hackathon_2024.02/scenario4/scenario4_4spec_regnet.json @@ -17,7 +17,7 @@ "species": "1" } }, - "initial": "0.51", + "initial": 0.51, "rate_constant": "r_0", "sign": true }, @@ -30,7 +30,7 @@ "species": "2" } }, - "initial": "0.39", + "initial": 0.39, "rate_constant": "r_1", "sign": true }, @@ -43,7 +43,7 @@ "species": "3" } }, - "initial": "0.88", + "initial": 0.88, "rate_constant": "r_2", "sign": true }, @@ -56,7 +56,7 @@ "species": "4" } }, - "initial": "0.4", + "initial": 0.4, "rate_constant": "r_3", "sign": true } diff --git a/notebooks/hackathon_2024.02/scenario4/scenario4_6spec_regnet.json b/notebooks/hackathon_2024.02/scenario4/scenario4_6spec_regnet.json index 1ca7c81db..9d371e927 100644 --- a/notebooks/hackathon_2024.02/scenario4/scenario4_6spec_regnet.json +++ b/notebooks/hackathon_2024.02/scenario4/scenario4_6spec_regnet.json @@ -17,7 +17,7 @@ "species": "1" } }, - "initial": "0.51", + "initial": 0.51, "rate_constant": "r_0", "sign": true }, @@ -30,7 +30,7 @@ "species": "2" } }, - "initial": "0.39", + "initial": 0.39, "rate_constant": "r_1", "sign": true }, @@ -43,7 +43,7 @@ "species": "3" } }, - "initial": "0.88", + "initial": 0.88, "rate_constant": "r_2", "sign": true }, @@ -56,7 +56,7 @@ "species": "4" } }, - "initial": "0.4", + "initial": 0.4, "rate_constant": "r_3", "sign": true }, @@ -69,7 +69,7 @@ "species": "5" } }, - "initial": "0.2", + "initial": 0.2, "rate_constant": "r_4", "sign": true }, @@ -82,7 +82,7 @@ "species": "6" } }, - "initial": "0.8", + "initial": 0.8, "rate_constant": "r_5", "sign": true }