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

Fix crash when infering units #284

Merged

Conversation

avandecreme
Copy link
Contributor

@avandecreme avandecreme commented Nov 29, 2022

Description

When trying to infer units of the added inferUnits-4.xml file, libsbml crashes.
My change only fixes the crash but does not make libsbml able to infer the units.

The reason why libsbml crashes (or is not able to infer the units) is that the file contains a function_1 with more than 2 arguments.
UnitFormulaFormatter::inferUnitDefinition then tries to reduce the kinetic law's math node to a binary tree but fails to do that properly because of the function_1 call.
Maybe a full fix would be to fix ASTNode::reduceToBinary() to detect that there is a call to a function of more than 2 params and build a binary tree of the function first.
For now, avoiding a crash seems like a quick win.

Note that replacing <ci> function_1 </ci> by <time /> in the input file avoids the crash and let libsbml infer units correctly.

Motivation and Context

Avoid crashing when infering units.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Change in documentation

Checklist:

  • I have updated all documentation necessary.
  • I have checked spelling in (new) comments.

Testing

  • Testing is done automatically and codecov shows test coverage
  • This cannot be tested automatically

@avandecreme avandecreme marked this pull request as ready for review November 29, 2022 10:36
@eltix
Copy link
Contributor

eltix commented Nov 29, 2022

cc @fbergmann

Copy link
Member

@fbergmann fbergmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! thank you for the submission.

@fbergmann fbergmann merged commit 226c867 into sbmlteam:development Nov 30, 2022
@avandecreme avandecreme deleted the fix_infer_units_core_dump branch November 30, 2022 07:33
@avandecreme
Copy link
Contributor Author

Thanks for reviewing and merging @fbergmann!
Should I open an issue regarding making unit inference work on this case?

@fbergmann
Copy link
Member

yes please. For inference in your local work, i recommend that you'd first run the inline function definition converter on the model prior to inferring units. That workaround will make it work for you.

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 this pull request may close these issues.

None yet

3 participants