Skip to content

Commit 90379c4

Browse files
authored
Merge pull request #249 from PEtab-dev/release_0.2.9
Release 0.2.9
2 parents eef0eb3 + 8d3636c commit 90379c4

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## 0.2 series
44

5+
### 0.2.9
6+
7+
* Fixed a bug in `SbmlModel.get_free_parameter_ids_with_values` that led to
8+
potentially wrong initial values in the parameter mapping for parameters that
9+
are targets of `initialAssignment`s (the value from their `value` was taken
10+
instead of the initial assignment)
11+
by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/248
12+
513
### 0.2.8
614

715
* Fixed pandas `FutureWarning` in `petab/visualize/lint.py`

petab/models/sbml_model.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Iterable, Optional, Tuple
66

77
import libsbml
8+
import sympy as sp
89

910
from ..sbml import (
1011
get_sbml_model,
@@ -103,10 +104,41 @@ def get_free_parameter_ids_with_values(
103104
ar.getVariable() for ar in self.sbml_model.getListOfRules()
104105
}
105106

107+
parser_settings = libsbml.L3ParserSettings(
108+
self.sbml_model,
109+
libsbml.L3P_PARSE_LOG_AS_LOG10,
110+
libsbml.L3P_EXPAND_UNARY_MINUS,
111+
libsbml.L3P_NO_UNITS,
112+
libsbml.L3P_AVOGADRO_IS_CSYMBOL,
113+
libsbml.L3P_COMPARE_BUILTINS_CASE_INSENSITIVE,
114+
None,
115+
libsbml.L3P_MODULO_IS_PIECEWISE,
116+
)
117+
118+
def get_initial(p):
119+
# return the initial assignment value if there is one, and it is a
120+
# number; `None`, if there is a non-numeric initial assignment;
121+
# otherwise, the parameter value
122+
if ia := self.sbml_model.getInitialAssignmentBySymbol(p.getId()):
123+
formula_str = libsbml.formulaToL3StringWithSettings(
124+
ia.getMath(), parser_settings
125+
)
126+
try:
127+
return float(formula_str)
128+
except ValueError:
129+
sym_expr = sp.sympify(formula_str)
130+
return (
131+
float(sym_expr.evalf())
132+
if sym_expr.evalf().is_Number
133+
else None
134+
)
135+
return p.getValue()
136+
106137
return (
107-
(p.getId(), p.getValue())
138+
(p.getId(), initial)
108139
for p in self.sbml_model.getListOfParameters()
109140
if p.getId() not in rule_targets
141+
and (initial := get_initial(p)) is not None
110142
)
111143

112144
def get_parameter_ids(self) -> Iterable[str]:

petab/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""PEtab library version"""
2-
__version__ = "0.2.8"
2+
__version__ = "0.2.9"

tests/test_visualization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def visu_file_Fujita_minimal():
107107
)
108108

109109

110-
@pytest.mark.filterwarnings("ignore:Visualization table is empty")
111110
@pytest.fixture
112111
def visu_file_Fujita_empty():
113112
return (

0 commit comments

Comments
 (0)