-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix SbmlModel.get_free_parameter_ids_with_values
to handle InitialA…
#248
Conversation
…ssignments So far, `SbmlModel.get_free_parameter_ids_with_values` ignored InitialAssignments, resulting in incorrect parameter values in the parameter mapping.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #248 +/- ##
===========================================
- Coverage 76.34% 76.21% -0.14%
===========================================
Files 34 34
Lines 3205 3216 +11
Branches 779 780 +1
===========================================
+ Hits 2447 2451 +4
- Misses 555 561 +6
- Partials 203 204 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does a free parameter take a value from an SBML assignment rule? Shouldn't values for free parameters come from an optimizer? I would expect that initial assignments/values for free parameters are somehow removed, is that what this method is for?
def get_initial(p): | ||
# return the initial assignment value if there is one, and it is a | ||
# number, otherwise the parameter value | ||
if ia := self.sbml_model.getInitialAssignmentBySymbol(p.getId()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ia := self.sbml_model.getInitialAssignmentBySymbol(p.getId()): | |
if ia := self.sbml_model.getInitialAssignmentBySymbol(p.getId()) is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's implied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 was just a PEP 8 recommendation
@@ -103,8 +104,31 @@ 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty unintuitive, to me it looks like this will convert log
to log10
, and I'm not sure if the libsbml docs make sense. e.g. this for L3P_PARSE_LOG_AS_ERROR
Collapse unary minuses where possible when parsing text-string formulas.
The docstring for L3P_PARSE_LOG_AS_LOG10
looks like it actually parses log
as log
, not parsing log
as log10
, but I'm not sure I trust the docs given the docstring for L3P_PARSE_LOG_AS_ERROR
. Should we instead use L3P_PARSE_LOG_AS_LN
?
I think most users would expect log
to be ln
, and that log10
is only when explicitly specified with log(10, x)
or log10(x)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are the libsbml default settings. The only relevant thing here is ignoring units.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if it actually keeps log
as log
, not log10
, then no problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is about parsing MathML, not any observableFormula or the like. In MathML log
without explicit base means log10
. In plain text formulae, log
will be interpreted as ln
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Good to know that log
means different things in PEtab and the model 😬 Then I think we could be more careful about a math spec in the next version of PEtab, I added a comment to the draft timecourse spec.
Assignment rule targets are excluded here. The method name is maybe not ideal. In the end, this method is used to collect parameters and default values that should be present in the parameter mapping. I guess it's up for discussion what should be included/excluded there. However, the original situation was clearly bad: For example, a parameter with |
Meant to say initial assignment rule there, but I see now that this is not about free parameters only
OK, sounds good to me then. Doing SymPy calls frequently sounds inefficient, but maybe JIT/ |
This is happening once during the parameter mapping. I don't think it really matters, unless the model is really huge, and even then, this is probably not the major problem. I can try |
OK, sounds reasonable to me; only initial assignments without parameter dependencies are handled. |
…2345) During PEtab import, parameters that are targets of initial assignments have so far not been turned into constant parameters, because they didn't exist in the amici model (see #2304). Now that those parameters remain in the model, they should be turned into constant parameters, unless specified otherwise. Requires PEtab-dev/libpetab-python#248, otherwise PEtab parameter mapping will provide potentially incorrect values for those parameters.
…ssignments
So far,
SbmlModel.get_free_parameter_ids_with_values
ignored InitialAssignments, resulting in incorrect parameter values in the parameter mapping.Now the correct values are used in case of initial assignments that are parameter-independent, and parameters with other initial assignments are ignored.