Skip to content

Commit

Permalink
Merge pull request #295 from gyorilab/regnet_initial
Browse files Browse the repository at this point in the history
Allow floats in regnet initials
  • Loading branch information
bgyori authored Feb 27, 2024
2 parents 34f6383 + f3441bc commit 516ce1c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
15 changes: 10 additions & 5 deletions mira/modeling/amr/regnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -315,7 +320,7 @@ def template_model_to_regnet_json(tm: TemplateModel):


class Initial(BaseModel):
expression: str
expression: Union[str, float]
expression_mathml: str


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"species": "1"
}
},
"initial": "0.51",
"initial": 0.51,
"rate_constant": "r_0",
"sign": true
},
Expand All @@ -30,7 +30,7 @@
"species": "2"
}
},
"initial": "0.39",
"initial": 0.39,
"rate_constant": "r_1",
"sign": true
},
Expand All @@ -43,7 +43,7 @@
"species": "3"
}
},
"initial": "0.88",
"initial": 0.88,
"rate_constant": "r_2",
"sign": true
},
Expand All @@ -56,7 +56,7 @@
"species": "4"
}
},
"initial": "0.4",
"initial": 0.4,
"rate_constant": "r_3",
"sign": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"species": "1"
}
},
"initial": "0.51",
"initial": 0.51,
"rate_constant": "r_0",
"sign": true
},
Expand All @@ -30,7 +30,7 @@
"species": "2"
}
},
"initial": "0.39",
"initial": 0.39,
"rate_constant": "r_1",
"sign": true
},
Expand All @@ -43,7 +43,7 @@
"species": "3"
}
},
"initial": "0.88",
"initial": 0.88,
"rate_constant": "r_2",
"sign": true
},
Expand All @@ -56,7 +56,7 @@
"species": "4"
}
},
"initial": "0.4",
"initial": 0.4,
"rate_constant": "r_3",
"sign": true
},
Expand All @@ -69,7 +69,7 @@
"species": "5"
}
},
"initial": "0.2",
"initial": 0.2,
"rate_constant": "r_4",
"sign": true
},
Expand All @@ -82,7 +82,7 @@
"species": "6"
}
},
"initial": "0.8",
"initial": 0.8,
"rate_constant": "r_5",
"sign": true
}
Expand Down

0 comments on commit 516ce1c

Please sign in to comment.