Debugging NaN/Inf right-hand-side values in SimBIology
4 views (last 30 days)
Show older comments
Abed Alnaif
on 28 Jan 2019
Commented: Abed Alnaif
on 1 Feb 2019
I’m getting an error while simulating a SimBiology model that I have NaN or Inf values on the right-hand-side, but I’m having trouble identifying the species/parameters responsible for this error. The issue occurs at the same time as an event, so I can’t just stop the simulation at a shorter timepoint to try to identify the cause of this error. Is there a simple way to identify what reaction is causing the NaN or Inf values?
When I turned on ‘dbstop if warning’, I was able to get into the ‘sbioodeflux’ right-hand side function. I can then see some Inf values, but I can’t figure out how to map those Inf values back to model elements. In particular, I see that reactionFlux(77) is Inf, but I don’t know which is the 77th reaction flux. Likewise, I don’t know what the elements of Y0 and P0 correspond to.
Is there an easy way for me to get more detailed information on the cause of NaN and Inf values in SimBiology? If not, is there a way I can figure out the mapping of the elements in the ‘sbioodeflux’ function to the model element names? This mapping must exist somewhere, but I can’t find it.
Thanks,
Abed
0 Comments
Accepted Answer
Arthur Goldsipe
on 29 Jan 2019
Hi Abed,
There's not currently any documented way to do this sort of debugging. We know that's a pain, so we're working on a debugger for a future release. But in the interim, the best bet is to contact us here at MathWorks to see if we can use any of our internal tools to help you. Because these tools depend on implementation details that could change from release to release, I can't really provide them here. It's generally easiest if you can share your model, but I recognize that this is not always possible.
I will contact you via your MATLAB Answers profile with a few more details.
-Arthur
4 Comments
Sietse Braakman
on 29 Jan 2019
Edited: Sietse Braakman
on 29 Jan 2019
Another way you can debug your model is by monitoring the instantaneous or cumulative quantities of a flux (reaction). You can do this as follows:
- Instantaneous: Create a parameter for each flux you want to monitor (e.g. Flux1). Use a repeated assignment on this parameter, where the rule equals the reaction rate equation of your flux (reaction). E.g. Flux1 = -Cl*Central.Drug_Central.
- Cumulative: Create a species for each flux you want to monitor (e.g. Flux2). Create a reaction for this species (null -> Flux2), where the reaction rate equals the reaction rate equation of your flux (reaction). Note 1: Another way you can achieve this is by adding Flux2 to the products of the reaction you want to monitor. E.g. the existing reaction is Central.Dose_Central -> Central.Drug_Central, this then becomes Central.Dose_Central -> Central.Drug_Central + Central.Flux2. Note 2: By using a species and a reaction you make use of the fact that species in SimBiology are subject of the LHS of an ODE and are thefore integrands. The integral of a reaction rate will be the cumulative amount that passed through the reaction.
You can then plot or inspect the values of these fluxes throughout your simulation. This can be useful to check whether any of your fluxes approaches infinity or becomes NaN - both of which can lead to errors in running your model.
More Answers (0)
Communities
More Answers in the SimBiology Community
See Also
Categories
Find more on Perform Sensitivity Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!