Page 1 of 1
Vensim Equation Auditing?
Posted: Wed Nov 01, 2023 6:43 pm
by RobbieOrvis
We are building out some complicated new code and have noticed significant runtime slowdown (not surprising). We are wondering if there is any existing software or capability to audit the equations in a .mdl file and identify which are using the most memory/processing, in order to try and reduce the runtime. We are contemplating building something like this ourselves but also wanted to see if something already exists.
Re: Vensim Equation Auditing?
Posted: Thu Nov 02, 2023 2:47 pm
by tomfid
There isn't (but probably should be). Here's a trick I've used for this.
Run the model, and export the run to a .tab file with time across and subscripts in their own columns. Deselecting units keeps things simple.
Open the result in Excel. You can now count the output. Anything with a value in just the first column is a constant or INITIAL and therefore probably low cost.
For the rest, make a pivot table (you'll have to name the subscript columns r1, r2, etc. first), and add the count from the second or last column.
Then you can sort descending on the value. The variables with the highest dimensionality will be at the top.
This doesn't account for expensive functions (FIND ZERO and some of the ALLOCs) but it does capture the bulk complexity of the model.
Re: Vensim Equation Auditing?
Posted: Thu Nov 02, 2023 8:25 pm
by Travis
Robbie – this might not help you given how far along you are, but SDEverywhere includes performance measurement as part of its quality control tools. One way this has been used is to compare the performance of one version of the model with another. Sometimes this helps catch performance degradation as the model is being developed and the optimizations can be made right then and there.
The approach isn't as useful if there is a large atomic change in the model that I think you've done, but it is helpful for more incremental model changes.
If you want to open up a thread in the SDE GitHub, maybe there is a way to extend the performance tools in SDE to help reverse diagnose Vensim.
Also, since you're using SDE, I do recommend trying the new model version in SDE if you haven't already. SDE does some optimizations that Vensim doesn't, depending on what portions of the model is exposed in the web app.
Re: Vensim Equation Auditing?
Posted: Fri Nov 03, 2023 2:44 pm
by RobbieOrvis
Thanks @Tom. One other question for you. We have started using LOOKUP INVERT in some variables that have high dimensionality. Do you know if this is an expensive function? If not we can replace it with some math instead based on the input table we are using.
I'm looking into the output approach you mentioned now.
Re: Vensim Equation Auditing?
Posted: Sat Nov 04, 2023 9:18 am
by Administrator
There is also this which might help.
https://metasd.com/2011/01/optimizing-vensim-models/
One of the common things I see is something like this.
proportion[company] = size[company] / sum ( size[company!] )
Much better to do something like
total company size = sum ( size[company!] )
proportion[company] = size[company] / total company size
When running the first equation, the sum is repeated for each company. The 2nd example, you calculate the sum once. If you have hundreds of companies, this can have a big impact on model speed.
Re: Vensim Equation Auditing?
Posted: Mon Nov 06, 2023 3:06 pm
by RobbieOrvis
Thanks that is helpful. We have an instance or two of that in the part of the codes that is heavily subscripted, and will edit accordingly.
Ultimately, we ended up just reducing the number of elements in a few of the main subscript ranges, which dramatically lowered the run time.