Skip to content

Commit

Permalink
Merge pull request #249 from PEtab-dev/release_0.2.9
Browse files Browse the repository at this point in the history
Release 0.2.9
  • Loading branch information
dweindl authored Mar 6, 2024
2 parents eef0eb3 + 8d3636c commit 90379c4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## 0.2 series

### 0.2.9

* Fixed a bug in `SbmlModel.get_free_parameter_ids_with_values` that led to
potentially wrong initial values in the parameter mapping for parameters that
are targets of `initialAssignment`s (the value from their `value` was taken
instead of the initial assignment)
by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/248

### 0.2.8

* Fixed pandas `FutureWarning` in `petab/visualize/lint.py`
Expand Down
34 changes: 33 additions & 1 deletion petab/models/sbml_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Iterable, Optional, Tuple

import libsbml
import sympy as sp

from ..sbml import (
get_sbml_model,
Expand Down Expand Up @@ -103,10 +104,41 @@ def get_free_parameter_ids_with_values(
ar.getVariable() for ar in self.sbml_model.getListOfRules()
}

parser_settings = libsbml.L3ParserSettings(
self.sbml_model,
libsbml.L3P_PARSE_LOG_AS_LOG10,
libsbml.L3P_EXPAND_UNARY_MINUS,
libsbml.L3P_NO_UNITS,
libsbml.L3P_AVOGADRO_IS_CSYMBOL,
libsbml.L3P_COMPARE_BUILTINS_CASE_INSENSITIVE,
None,
libsbml.L3P_MODULO_IS_PIECEWISE,
)

def get_initial(p):
# return the initial assignment value if there is one, and it is a
# number; `None`, if there is a non-numeric initial assignment;
# otherwise, the parameter value
if ia := self.sbml_model.getInitialAssignmentBySymbol(p.getId()):
formula_str = libsbml.formulaToL3StringWithSettings(
ia.getMath(), parser_settings
)
try:
return float(formula_str)
except ValueError:
sym_expr = sp.sympify(formula_str)
return (
float(sym_expr.evalf())
if sym_expr.evalf().is_Number
else None
)
return p.getValue()

return (
(p.getId(), p.getValue())
(p.getId(), initial)
for p in self.sbml_model.getListOfParameters()
if p.getId() not in rule_targets
and (initial := get_initial(p)) is not None
)

def get_parameter_ids(self) -> Iterable[str]:
Expand Down
2 changes: 1 addition & 1 deletion petab/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""PEtab library version"""
__version__ = "0.2.8"
__version__ = "0.2.9"
1 change: 0 additions & 1 deletion tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def visu_file_Fujita_minimal():
)


@pytest.mark.filterwarnings("ignore:Visualization table is empty")
@pytest.fixture
def visu_file_Fujita_empty():
return (
Expand Down

0 comments on commit 90379c4

Please sign in to comment.