Closed Rosejoycrocker closed 2 years ago
Hi Rose, there's also solver settings to reduce/increase their tolerances as well.
Apparently the default for ode45
is an absolute tolerance of 1e-6
and a relative tolerance of 1e-3
.
Correction: seems these are the default values for all ode functions
Thanks @ConnectedSystems I'll look into that too. At the moment it seems like ode23 is quite a bit faster without too much difference in outcome to ode45 (without data for comparison I'm using ode45 as the baseline for RMSE). I've added to ADRIA() to allow the ode function as an optional string input, not sure if we want to merge this to allow this option in ADRIA proper.
I've added to ADRIA() to allow the ode function as an optional string input, not sure if we want to merge this to allow this option in ADRIA proper.
It's a good idea, I've been thinking of adding also the ability to specify a growth function so different ODEs can be applied/compared.
Yeah that could be an interesting comparison
Testing different ode solvers- ode78 and 89 included to compare with very high resolution solvers. Left image is RMSE relative to results with ode45, showing that the faster solver (ode23) does not give hugely different results to ode45. Mean (middle) and spread across simulations (right) are also pretty indistinguishable. Also tried stiff solvers but these were ineffective (seems the problem is not stiff).
Runtime for different solvers. Difference in runtime between ode45 and ode23 varies, but ode23 is about 5-6 secs faster for 50 sims (depending on parameters used). This could add up over running hundreds of scenarios.
Comparison between ode45 and ode23 using different tolerances. Time for one simulation is less for ode23 for up to Abs tol 1e-5 (Rel tol is scaled relative to abs tol). It seems the smallest tolerance for ode23 gives the greatest time advantage and resolution (=>1e-7).
Awesome work, Rose!
I take it then that we should use:
options = odeset('AbsTol',1e-7);
% ... later on ...
[~, Y] = ode23(@(t, X) growthODE4_KA(X, e_r, e_P, e_mb, rec, e_comp), tspan, Yin1, options);
By "simulation", are you referring to a set of intervention scenario and 20 DHW replicates? (e.g., 1 "simulation" = 1 intervention scenario over 20 runs?)
Just trying to estimate what the overall run time might be using the Brick case study.
Yeah seems like those settings work best :) In the table a simulation time is the average time per simulation over 50 climate simulations for one intervention scenario. Sorry didn't make that clear. I just realised I branched off main, so I'm not sure if you've done any optimisation in the Brick runs branch that would change simulation times? If so I can merge Brick runs into my branch and rerun for a better estimate.
That's alright.
If Brick runs are 20 climate scenarios, then reduction is about 1.2 seconds, which equates to about an hour and a half over the 4609 scenarios. I think. You may want to check my working there.
If true, that's massive 😄
I merged Brick into main recently. Git timeline says your branch is outdated so I suggest doing a rebase.
Be aware that Brick-modelling has a few changes - can't remember how much (if any) was performance specific to the ODE function though.
Ok cool, I'll merge and rerun things just to be sure
Updated figures:
So similar results, but this time I ran over the full time period (74 years) and the difference in simulation time was slightly bigger- 81.9495s for 50 sims for ode45 and 75.2199s for ode23. I think this is around 32.7789s and 30.088s respectively for 20 sims, which is a 2.69s difference. This is probably a best case scenario ( as I used default parameters and previously it seems that parameter changes from default decreased the difference in runtime slightly, such as when adding interventions), but still would make a difference I think.
~30 seconds compared to 32 per scenario set across 4609 scenarios (the total number used for Brick) adds up to about 2 and a half hours difference.
The workstation has a faster CPU overall compared to our laptops but even then this should shave off an hour and a half at least.
Thanks for looking into this, Rose, well done. Tag me in the PR to close this issue and I'll approve it asap.
Ok cool, thanks Takuya :) The branch I've been working on allows you to input the ode solver function and tolerances as inputs to ADRIA(). Should I add ode23 and the tolerances as default parameters with the option to alter them or just create a new branch and change the fixed ode solver and tolerances?
Should I add ode23 and the tolerances as default parameters with the option to alter them or just create a new branch and change the fixed ode solver and tolerances?
I think adding it as a parameter/option would be cool
If you do it that way, could we also add another one for the growth model (currently growthODE4_KA()
) as well so Ken doesn't have to modify coralScenario
to test out different implementations?
Yeah I think the flexibility will be cool, we could use the higher order ode for initial test runs when we're looking at a new group of sites to see how complex the dynamics are and then lower order when we're running a lot of scenarios. That's a good idea for the growth ode too :)
Closed by #141