Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

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

Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by jrissman »

Hello Ventana team,

I have a small but important bug to report to you today.

The SIMULATE > SETVAL command (used in Vensim command scripts, as well as passed to Vensim by external programs, like a web interface) is supposed to set the value of a constant or lookup, similar to a human moving a slider in SyntheSim mode.

For constants, SETVAL works if the default value of the constant is hard-coded into the Vensim model file. However, SETVAL silently fails if the default value of the constant is set at model runtime via GET DIRECT CONSTANTS. (In contrast, in SyntheSim mode, sliders work correctly to set constants irrespective of whether the constants' default values are hard-coded in the model file or come from GET DIRECT CONSTANTS. So the problem is specific to the SETVAL command.)

I've attached a small Vensim model and command script I made to illustrate the bug clearly. The model contains two variables. Both are set to 3 by default - one is hard-coded, and the other is read in via GET DIRECT CONSTANTS. The command script sets both variables to 6. But if you run the command script, then check the values in the variables (be selecting them and clicking the "table" button), you will find that the hard-coded one was changed to 6, but the other one still contains the value 3.

SetvalBugExample.zip
Example model package to demonstrate SETVAL bug
(1.46 KiB) Downloaded 173 times

Command script using SETVAL
Command script using SETVAL
CommandScript.PNG (6.79 KiB) Viewed 4371 times

Variable contents after running command script
Variable contents after running command script
AfterCommandScriptRun.PNG (6.64 KiB) Viewed 4371 times

This problem makes it hard to control a model (i.e. changing a slider setting) via a script or a web interface. This is hindering our ability to implement a lever that adjusts the severity of a recession, because the default setting for the recession varies by country and must be read from an input data file using GET DIRECT CONSTANTS - we cannot hard-code the recession severity level into the Vensim model file itself.

Thank you so much for looking into this bug. We really appreciate it.

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

Re: Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by Administrator »

ok, this is not a bug, it's by design.

We were not happy with how it GET_XLS_CONST was originally implemented. In my mind, if I'm reading a constant from a spreadsheet, it should not be overridden by a value in a text file (using ADDCIN) as the source of the data is different. Also, if you read constants from a spreadsheet and then used WRITECIN, the values from the spreadsheet would be written to the CIN file (again, this does not make logical sense to me, subsequent use of that CIN file would override the Excel constant).

I hope that makes sense. We wanted to keep Excel and text input files separate and make sure the user thinks about this when loading/saving constants.

There is an override though. Before trying SIMULATE>SETVAL, try
SIMULATE>OVERWRITE_GET_CONST|1

This sets an internal flag to allow Excel constants to be overridden.
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
Todd
Junior Member
Posts: 11
Joined: Tue Aug 20, 2019 7:35 am
Vensim version: DSS

Re: Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by Todd »

I verified that the OVERWRITE_GET_CONST command works as described in Vensim 8.0.9 for data read by GET DIRECT CONSTANTS. However, when I tried it in version 8.0.7, I got an error message saying that "SIMULATE>OVERWRITE_GET_CONST" was "unknown".

Does that mean that we would need a build of the Linux multicontext library to version 8.0.9 to apply this fix on servers?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by Administrator »

Yes. Drop me an email and I'll create it for you.

There is another way if replacing the Linux library is not possible, but that would involve modifying the model.
Excel const = GET XLS ....
Changable const = 12

value to use = if then else ( excel const <> Changable const , Changable const , Excel const)
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: 95
Joined: Wed Oct 16, 2013 6:04 pm
Vensim version: DSS

Re: Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by jrissman »

Hello Team,

Unfortunately, the override is not recognized as a command by Vensim. When I add it to the command script, and run the script, I get this error:

Unknown command error
Unknown command error
UnknownCommandError.PNG (6.38 KiB) Viewed 4356 times

Note that I don't have the period in the command script. I entered the command into the script exactly as you specified, so the script looks like this:

Code: Select all

SPECIAL>LOADMODEL|SetvalBugExample.mdl
SIMULATE>OVERWRITE_GET_CONST|1
SIMULATE>SETVAL|Constant Hard Coded in Model File=6
SIMULATE>SETVAL|Constant Set Via Input Data=6
MENU>RUN|O
Is it possible that you might have misremembered the syntax of the overwrite command? We would really like to get this working.

Also, note that Vensim lets you overwrite values taken in from spreadsheets when you move a constant variable's slider in SyntheSim mode. This can lead to the exact same situations that would arise if SETVAL were able to overwrite values from a spreadsheet. That is, the outcomes you view as undesirable are not being avoided by preventing SETVAL from functioning on variables containing data from spreadsheets. This functionality is normal in Vensim today and is relied upon by Vensim users, such as us. The problem is that Vensim's normal variable-setting behavior can't be scripted. SETVAL would most logically behave identically to a human setting the values of variables in SyntheSim - the command script capabilities are most powerful and intuitive if they can automate what a human could do manually.

The other important point to make is that there is a good reason for letting users change values taken in from spreadsheets. We believe that for larger and more complicated models, it is good programming practice to separate the input data and assumptions from the model structure, so the model can run with different input data sets. This is important for keeping the model maintainable - otherwise, we would have to manually recreate any improvement or change to the model structure across numerous different Vensim model files (one for each input dataset). Manually repeating an identical programming change 10 or more times would be a horrible chore that would quickly become impossible. By keeping the input data separate, we have only one Vensim model file to maintain, so we have to program our improvements or bug fixes in only one place. This is far better than manually repeating the same programming change in a dozen model files that are all identical, except for different hard-coded input data.

Therefore, 98% or more of our constants come from spreadsheets. The only ones that are hard-coded are things we expect never to change under any circumstances, such as mathematical unit conversion factors.

This is why it's so valuable to be able to change the values in constants using SETVAL, even if the values originally came from spreadsheets. SETVAL is crippled if it can't operate on 98% of the constants in our model.

Given this discrepancy (where SyntheSim users are allowed to set the value of constants using spreadsheet values, but command script users are blocked from doing so), as well as the high value of letting SETVAL work for models that separate their input data from the model structure (a straightforward programming best practice to reduce the burden of maintaining larger models), I would respectfully recommend you revisit this design decision. The SETVAL command should work for these variables by default. Command script users can simply opt not to set the values of variables taken in from input data if they don't want to, so enabling this capability doesn't force anyone to do anything - it is strictly additive to Vensim's power and flexibility.

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

Re: Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by jrissman »

Looks like Todd posted and you replied while I was writing the message above. Sounds like you figured out why the override isn't working. Getting us the 8.0.9 linux multicontext library might fix our problem. (I'm still of the opinion the default behavior should allow this to work, but simply getting the override working for us is satisfactory for our needs.)
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Bug Report: SETVAL fails to set constants populated via GET DIRECT CONSTANTS

Post by Administrator »

I'm sure another way to get around this is to tick the box titled "Overwrite GET....Constants equations" when you click Model->Simulate. Then publish the model, the setting is saved in the published model.
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
Post Reply