Skip to content
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

How to set MathML string to libcellml component? #1024

Closed
aditya-ml opened this issue Aug 23, 2022 · 8 comments · Fixed by #1026
Closed

How to set MathML string to libcellml component? #1024

aditya-ml opened this issue Aug 23, 2022 · 8 comments · Fixed by #1026

Comments

@aditya-ml
Copy link

Following on the discussion in issue #1017 I tried creating math equations using libsbml.parseL3Formula. However, my program crashes on the last line rather than set the equation to libcellml component.

Snippet:

    comp_parameters.setName("parameters")
    model.addComponent(comp_parameters)
    math_ast1: libsbml.ASTNode = libsbml.parseL3Formula( "eff / t_ave")
    var_math_ast1 = libsbml.writeMathMLToString(math_ast1)
    print(var_math_ast1)
    comp_parameters.setMath(var_math_ast1)

Output:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <apply>
    <divide/>
    <ci> eff </ci>
    <ci> t_ave </ci>
  </apply>
</math>
@matthiaskoenig
Copy link

We got this working, the issue were the correct namespaces on the MathML string.

@hsorby
Copy link
Contributor

hsorby commented Aug 24, 2022

Would you mind clarifying which line the program segfaulted on. If it segfaulted on comp_parameters.setMath(var_math_ast1) I would definitely need to look into that.

@matthiaskoenig
Copy link

This was not a segfault. @aditya-ml got this wrong. The thing which happens is that the library just does not create the model if the namespace was missing on the MathML string. I.e. everything else in the component/model was not written out if the MathML was not correct.
It would be nice if the library could be much more robust here. How libsbml is solving this is

  • by providing return types with information what went wrong. This allows to easily fix/detect issues programatically and warn the user
  • by just not setting the MathML resulting in an otherwise unchanged model (it just does not have the MathML). In libcellml it seems to affect the complete model object if one tries to set an incorrect Mathml.

I hope this makes sense.

@hsorby hsorby reopened this Aug 24, 2022
@hsorby
Copy link
Contributor

hsorby commented Aug 24, 2022

If you don't mind I will re-open this issue. I have found that I do get a segfault when printing out model using the output of libsbml.writeMathMLToString(math_ast1).

The output of this function is not what is given above in the output but the following:

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML">
  <apply>
    <divide/>
    <ci> eff </ci>
    <ci> t_ave </ci>
  </apply>
</math>

And this is definitely causing a segfault when attempting to print the model.

@hsorby
Copy link
Contributor

hsorby commented Aug 24, 2022

I don't get a crash when setting the math to a component. At that point the math is only a string and nothing happens with it. It isn't until some action on the string is required that things go South, like printing it.

@hsorby
Copy link
Contributor

hsorby commented Aug 24, 2022

libCellML has taken the point of view that we will let the user/modeller do what they want, putting as few restrictions in place as we are able. When setting something we are not returning success or failure states because it muddies the water when you are returning something that isn't a success or failure state. What we do have instead is the Validator and Analyser, the Validator will report on every violation of the CellML 2 specification in the model. The Analyser goes a bit further and has a look at the actual math that is encapsulated in the model.

@luciansmith
Copy link

I can say that return values let you find errors much much faster than a post-hoc validation/analysis step. An analysis/validation tells you that something is wrong, not how something went wrong.

@matthiaskoenig
Copy link

I agree with Lucian here.

Also it allows to directly react/log issues when using the library in the context of a larger project. I.e. I don't want to do a complete post-hoc validation after every step to check if things worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants