Integration Tolerance Bizarre Reaction:

Daniel Bending on 10 Jun 2024 (Edited on 10 Jun 2024)
Latest activity Reply by Arthur Goldsipe on 10 Jun 2024

Hi All,
I've been producing a QSP model of glucose homeostasis for a while now for my PhD project, recently I've been able to expand it to larger time series, i.e. 2 days of data rather than a singular injection or a singular meal. My problem is as follows: If I put 75g of glucose into my stomach glucose species any later than (exactly) 8.5 hours I get an integration tolerance error. Curiosly, I can put 25g of glucose in at any time up to 15.9 hours, then any later an error. I have disabled all connections to my glucose absorption chain, i.e. stomach -> duodenum -> jenenum -> ileum -> removal, to isolate the cause of this. I had initially thought it may be because I mechanistically model liver glycogen and that does deplete over time, but I've tested enough to show that that does nothing. My next test is to isolate the glucose absorption chain into a seperate model and see if the issue persists but I'm completely baffled!
These are the equations, to my eye there's no reason why there would be such a sharp glucose quantity/time dependence, they all begin at a value of 0:
d(Gs)/dt = -(kw*(1-Gd^14/(Igd^14+Gd^14))*Gs) #Stomach glucose
d(Gd)/dt = (kw*(1-Gd^14/(Igd^14+Gd^14))*Gs) - (kdj*Gd) #Duodenal Glucose
d(Gj)/dt = (kdj*Gd) - (kji*Gj) #Jejunal Glucose
d(Gi)/dt = (kji*Gj) - (kic*Gi) #Ileal Glucose
(The sigmoidicity of gastric emptying slowing term (^14) was parameterised off of paracetamol absorption data and appears to be correct!)
Thank you for your help, best regards,
Dan
Pre-Edit: I changed the run time to 30 hours and now I can't use the 75g input any later than 7.9 hours not 8.5 hours anymore!
Edit: This is how it appears at all times prior to it failing for 75g:
Daniel Bending
Daniel Bending on 10 Jun 2024
Embarrasingly I think I messed with my integration tolerance solver settings ages ago and possibly just got lucky up to now and completely forgot about it, I've lowered them all and everything seems to be working now, at least initially. I read the troubleshooting guide but I was wondering how the intergration tolerances interact with things like greatly different unit magnitudes? I.e. millimolar vs picomolar, is there any effect there?
Arthur Goldsipe
Arthur Goldsipe on 10 Jun 2024
At the end of the day, choosing tolerances is often a matter of trial and error. Sometimes I will just start with loose tolerances and then keep tightening them until the simulation results stop changing "significantly." But let me share more details that can be helpful in choosing a reasonable starting point for your tolerances.
Relative tolerance is, well, relative. So differences in units or scale should have no impact on your choice of relative tolerance.
If you turn on AbsoluteToleranceScaling, then differences in units or scale will not affect your choice of absolute tolerance either. In fact, that's the main reason we implemented AbsoluteToleranceScaling. You can read more about the feature here, but it's basically an absolute tolerance that adapts to the scale of each state.
If you don't use AbsoluteToleranceScaling, then the situation is more complicated. It also depends on some implementation details that could change in a future release. But let me describe how things work right now (as of R2024a). The same absolute tolerance applies to all states, so you will generally need to choose the tolerance based on the scale of your smallest state variable. In SimBiology, these state variables are usually species, and more specifically the amount or mass of the species. So if you're working with species in concentration, be sure to multiply by the appropriate compartment capacity when you try to determine your absolute tolerance.
In addition, if unit conversion is turned on, then the internal state variables will be in what I call "engine units." You can manually control the engine units by setting TimeUnits, AmountUnits, and MassUnits (as described here). But the <automatic> default will use the smallest units on your model. So in the specific example you describe (millimolar and picomolar), SimBiology will internally use picomole as the amount units for all states. So your absolute tolerance will essentially have units of picomole when applied to speices.
I hope that answers your question.
-Arthur