Crash Upon Adding New Variable, Possible Memory Issue

Use this forum to post Vensim related questions.
Post Reply
jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Fri Mar 15, 2019 1:51 am

Hello Ventana Systems folks,

As you know, we have a mature and sophisticated Vensim model, the Energy Policy Simulator. Most of the variables in the model are subscripted in various ways. For example, some existing variables use the following three subscripts:

Code: Select all

[Industry Category, Industry Process Emissions Policy, Marginal Abatement Cost]
When I add a new variable to the model that is subscripted by these same three subscripts, and I try to run the model, Vensim crashes (unexpectedly quits). This happens every time with perfect reproducibility. It doesn't matter what data is in the new variable. The equation can simply consist of the number zero, and it will still crash.

I am worried that perhaps we are running into some limit in Vensim on how many variables or fields can be addressed in memory. But my computer's RAM isn't the issue. When I load the Energy Policy Simulator in Vensim and check Vensim's memory use in Task Manager, it is using only 5.5 MB:

VensimRunningNormally.PNG
Vensim memory usage during normal operation
VensimRunningNormally.PNG (16.13 KiB) Viewed 290 times

When Vensim has crashed, the memory use jumps to 38.6 MB, which is a lot more than before, but is still a tiny fraction of my system's available memory:

VensimCrashed.PNG
Vensim memory usage upon crash
VensimCrashed.PNG (38.41 KiB) Viewed 290 times

I've tested this in Vensim DSS v7.1 (32-bit) and Vensim DSS v7.3.5 (32-bit), and the crash happens in both cases. I don't have a 64-bit version of Vensim to test with.

If you want to test this bug yourself, simply download a copy of the Energy Policy Simulator (eps-1.4.2-us-v2) from https://us.energypolicy.solutions/eps-a ... -us-v2.zip

First, open it in Vensim DSS and click "Simulate." It should run without an error (though you may see initial value warnings).

Then, add a variable to the model like the following:

Code: Select all

Test Variable[Industry Category,Industry Process Emissions Policy,Marginal Abatement Cost]=
	0
	~	Dmnl
	~		|
Click "Simulate," and the model will crash.

Note that the model runs if the new "Test Variable" uses any two of the three subscripts above. It only causes a crash if the Test Variable uses all three subscripts.

If you want to see an example of an existing variable that uses these three subscripts, you can look at any of these:

Code: Select all

PERAC Mass CO2e Avoidable by Marginal Cost
Reduction in Process CO2e Left to Assign after this Marginal Cost
Reduction Achieved by Marginal Cost
The existence of these variables shows that Vensim can handle variables using these three subscripts in this model without crashing. It is only the addition of one more variable with these three subscripts that causes it to crash.

Do you know why we can't add another variable to the model using these subscripts without causing it to crash? What options do we have, if we want to continue adding variables to this model without causing it to crash?

tomfid
Administrator
Posts: 2543
Joined: Wed May 24, 2006 4:54 am

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by tomfid » Fri Mar 15, 2019 4:16 am

I can replicate the crash (no explanation yet).

Administrator
Super Administrator
Posts: 3238
Joined: Wed Mar 05, 2003 3:10 am

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by Administrator » Fri Mar 15, 2019 9:58 am

ok, this is actually related to the number of CSV files in use in the model. Internally, Vensim has a maximum limit of 255 CSV files, and you are hitting that limit.

I'll increase this for the next release which will stop the crash. I don't have a workaround at the moment other than combining the CSV files in some way.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Fri Mar 15, 2019 4:40 pm

When I count instances of the words "GET DIRECT" or the extension ".csv" appearing in the code for eps-1.4.2-us-v2, I find that the model is using 412 different CSV files, already far more than 255 files. It works fine when reading from 412 CSV files. The crash occurs only when I add a new variable that uses certain subscripts, even though the newly added variable doesn't read from a CSV file.

Are you sure that the number of csv files is the issue? I can't see evidence of the connection between the two on my end.

jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Fri Mar 15, 2019 4:47 pm

As a test, I removed 10 CSV files from the model (hard-coding constant values for these 10 variables inside Vensim instead of reading them from CSV files). The model still crashes when I run it, with the new variable added (as described in my intial post). So reducing the number of CSV files we're using doesn't seem to have any effect.

Administrator
Super Administrator
Posts: 3238
Joined: Wed Mar 05, 2003 3:10 am

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by Administrator » Fri Mar 15, 2019 5:07 pm

Your model has 399 csv files according to the counts I'm seeing during debugging.

Ill try and generate a test build for you over the weekend.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Fri Mar 15, 2019 6:24 pm

I did a more careful count (checking for duplicates this time), and I get 396 CSV files, which are referenced in 412 GET DIRECT statements. I've attached a spreadsheet listing all the CSV filepaths and indicating whether they are unique or not.

I will be glad to test a new build next week.
Attachments
2019-03-15 CSV files in eps-1.4.2-us-v2.xlsx
List of all CSV file references in eps-1.4.2-us-v2
(21.78 KiB) Downloaded 7 times

Administrator
Super Administrator
Posts: 3238
Joined: Wed Mar 05, 2003 3:10 am

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by Administrator » Fri Mar 15, 2019 6:32 pm

That limit of 255 been in vensim for a very long time. The code I've added today allows for unlimited number of external files so hopefully will fix the issue.

Send an email to vensim@vensim.com with your licence details and I'll let you know when I've got a build ready.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Fri Mar 15, 2019 7:21 pm

I've sent the license details as requested.

jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Tue Mar 19, 2019 9:40 pm

I've tested the copy of Vensim DSS that you sent to me by email (with version number 7.3.7), and I don't experience any crash. As far as I can tell with some brief testing, it appears to work perfectly. Thank you!

We’re looking forward to this fix being included in the publicly-released versions of Vensim Model Reader and Vensim DSS, which will be useful for our partners and our model users. Once the fix becomes part of a publicly-released version of Vensim DSS and Vensim Model Reader, we'll update the system requirements of the Energy Policy Simulator to state that it requires Vensim 7.3.7 or later (likely as part of Energy Policy Simulator release 1.4.4).

Thanks again for finding and fixing the issue! It is greatly appreciated.

tomfid
Administrator
Posts: 2543
Joined: Wed May 24, 2006 4:54 am

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by tomfid » Tue Mar 19, 2019 11:06 pm

Glad it works.

Is there some alternate structure we could implement that would make it easier to handle the multitude of .cin files?

jrissman
Senior Member
Posts: 76
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Crash Upon Adding New Variable, Possible Memory Issue

Post by jrissman » Wed Mar 20, 2019 12:23 am

You mean the multitude of .csv files (not .cin files)? We don't have a multitude of .cin files. We have many .csv files, where the model's input data are stored.

In general, we like to keep our input data in .csv files for two reasons. First, it makes it easy to swap input data between countries or regions, depending on which we want to simulate, without touching the core Vensim executable. That helps us roll out model improvements to the core Energy Policy Simulator .mdl / .vpm and have these improvements apply to all different country datasets. Second, it allows our model users to customize the model's input data using a spreadsheet program, which is familiar and comfortable for them.

The most annoying aspect of using .csv files for our input data is for time-series variables with at least two subscripts (or non-time-series variables with at least three subscripts). Each .csv file only has two dimensions (e.g. one for time and one for the first subscript), so if a time-series variable has two subscripts, each of which has 12 elements, it will require a dozen different .csv files (each read in by a different equation in Vensim) to fully populate that single input variable using .csv files. If there were a format that allowed more than two dimensions to be read from a single .csv file, that could be useful to us in reducing the number of .csv input files required. For example, suppose we have a variable "Number of Fruit" that varies over time and is subscripted by type of fruit and color of fruit. The input data would look like this:

Code: Select all

Apples
Year      2020    2021    2022
green     2       3       4
red       5       7       8
yellow    1       0       5

Pears
Year      2020    2021    2022
green     1       4       2
red       2       9       7
yellow    8       3       3

Kiwifruit
Year      2020    2021    2022
green     2       3       4
red       0       0       0
yellow    2       1       1
Right now, we would handle this with 3 different .csv files, each of which is read in by a separate equation in the "Number of Fruit" variable.

However, maybe Vensim could treat one or more data-free lines as a delimiter, and if another data block occurs after the blank line(s), then Vensim treats that data block as if it contains the data for the next element of the second subscript (in a time-series variable) or the third subscript (in a non-time-series variable). For example, the code in the box above could be the contents of a single input .csv file that populates the "Number of Fruit" variable.

Here's an example for a non-time-series variable, "Number of Dogs," that is subscripted by dog gender, color, and breed:

Code: Select all

Poodles
Gender    Male    Female
brown     2       3
white     5       7
black     1       0

Beagles
Gender    Male    Female
brown     4       2
white     3       6
black     2       2

Bulldogs
Gender    Male    Female
brown     9       4
white     2       3
black     0       2
In addition to reducing the number of .csv files, this feature would have another benefit. It would make models more flexible to changes in the number of elements in a subscript. Today, if I want to add a new element to the end of a subscript that is broken out into different .csv files (for example, to add a fourth type of fruit, or a fourth breed of dog, in the examples above), I'd need to add a fourth equation in the input variable to read from the a new, fourth .csv file. If Vensim could read multiple data blocks from the same .csv file, there would be no need for a new equation and a new .csv file when I extend a subscript by adding an extra element onto the end. I'd just need to add a new data block to the bottom of the existing .csv file.

Post Reply