Code Monkey home page Code Monkey logo

vst's Introduction

VST

Vensim Script Tools for improving workflow in Vensim

This project is a collection of Python-based tools for working with Vensim software for system dynamics modelling.

Materials

VST contains the main codebase. For now, this contains usable code snippets, as well as ipynb notebooks with more extensive documentation; this will eventually be developed into an installable package.

VST Automation TEMPORARY contains a basic automation example for 15.879 use.

VST Testing contains a test package for the alpha version of vst, with an ipynb notebook showcasing a demonstration workflow based on the new syntax.

Widgets contains handy standalone tools drawing on the main codebase; these are intended to be usable even with minimal coding proficiency, as executable py files / ipynb notebooks.

Citing this code

If you use any VST code or widgets in any published work, please consider citing this repository:

Lim, T.Y. (2022) "Vensim Script Tools." https://github.com/tseyanglim/VST Accessed (DATE)

Why VST?

Vensim excels at its core competency of system dynamics modelling, and in particular, is extremely efficient at standard simulation model analyses (estimation/optimisation, sensitivity analyses).

VST leverages those advantages by providing tools that make it easier to integrate Vensim into more complex workflows and analysis pipelines, while still relying on Vensim as the core analytical / computational engine.

VST is thus different from, but complementary to, both VenPy and PySD. VenPy utilises the Vensim DLL to interface more closely with Vensim models, in more interactive ways; PySD allows development and analysis of system dynamics models in native Python, without use of Vensim. Both allow greater flexibility and interactivity - especially the ability to use other data science tools - than is possible when relying on Vensim, but without the benefit of the computing power and speed that Vensim brings. Which one to use depends on your specific task.

TODO:

  • Add citation file and Zenodo link

vst's People

Contributors

tseyanglim avatar

Stargazers

 avatar  avatar Mohammad Jalali avatar  avatar

Watchers

Tony Kennedy - Ventana Systems avatar  avatar

Forkers

annosi

vst's Issues

Nonstopping with return code 1

VST returned the following logfile:

Initialising <VST.vst.vst.Script object at 0x000001A2981842B0>
Initialising <VST.vst.vst.Script object at 0x000001A298186C50>
Initialising <VST.vst.vst.Script object at 0x000001A29845CD60>
Initialising <VST.vst.vst.Script object at 0x000001A2984633D0>
Initialising <VST.vst.vst.Script object at 0x000001A298393100>
Initialising <VST.vst.vst.Script object at 0x000001A298393400>
Initialising <VST.vst.vst.Script object at 0x000001A298392B90>
Initialising <VST.vst.vst.Script object at 0x000001A294ECA4D0>
Initialising <VST.vst.vst.Script object at 0x000001A29845D0C0>
Initialising <VST.vst.vst.Script object at 0x000001EC7D7AC130>
Initialising <VST.vst.vst.Script object at 0x000001EC7D30DF30>
Initialising <VST.vst.vst.Script object at 0x0000024B2AE44A60>
Initialising <VST.vst.vst.Script object at 0x0000023ACDC14A60>
Initialising <VST.vst.vst.Script object at 0x000002A7EF26F8E0>
Initialising <VST.vst.vst.Script object at 0x0000016CB9AFF8E0>
Initialising <VST.vst.vst.Script object at 0x000001C634BDF8E0>
Initialising Covidparam_VAMA!
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Return code is 1
Vensim! Trying again...
Initialising <VST.vst.vst.Script object at 0x000002DDC43CBF40>
Initialising Covidparam_VAMA!
Return code is 3221226525

Q1. what the meaning of code 1?
Q2. from the cmd file below, what might be causing repetitive vensim runs?
Q3. I used the default provided, but if the purpose is simply to generate with set_value parameter, might I experience speedup by excluding the last four SIMULATE?
Q4. why is there so many initialization in the log file?

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|CovidUSA-Econ-V79.mdl
SIMULATE>payoff|PayoffFlowV77-Policy.vpd
SIMULATE>sensitivity|
SIMULATE>optparm|COVID-V79-All.voc
SIMULATE>savelist|
SIMULATE>senssavelist|

SIMULATE>DATA|"CovidModelInputs - ConstantDataStates.vdf,CovidModelInputs - CRWStates.vdf,CovidModelInputs - DeathDataStates.vdf,CovidModelInputs - FlowDataStates.vdf,CovidModelInputs - FormattedDataStates.vdf,CovidModelInputs - TestDataStates.vdf"
SIMULATE>SETVAL|Variant Accuity Multiplier[Omicron]=0.5428063200000001

SIMULATE>RUNNAME|Covidparam_VAMA
SIMULATE>REPORT|1
MENU>RUN|o
MENU>VDF2TAB|!|!|||
SPECIAL>CLEARRUNS
MENU>EXIT

Calibration not stopping with return code 3221225477

Hi when I run the last block of your jupyter file, I face the following error and the calibration doesn't stop:

-----
Starting new log at Sun Sep 25 11:53:57 2022
Ready to work!
Initialising PrPr_main_opt!
-----
Starting new log at Sun Sep 25 12:12:20 2022
Ready to work!
Initialising PrPr_main_opt!
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Checking for PrPr_main_opt.log...
At Sun Sep 25 12:23:35 2022, 608.106s since last output. Calibration timed out!
Return code is None
Vensim! Trying again...
Checking for PrPr_main_opt.log...
At Sun Sep 25 12:33:40 2022, 1213.162s since last output. Calibration timed out!
Return code is None
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Checking for PrPr_main_opt.log...
At Sun Sep 25 12:46:14 2022, 608.398s since last output. Calibration timed out!
Return code is None
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
-----
Starting new log at Thu Oct  6 04:43:40 2022
Ready to work!
Initialising PrPr_main_opt!
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...
Return code is 3221225477
Vensim! Trying again...

Unclear meaning of json decoder

With this control text file,

{
	"baserunname": "Covid",
	"simsettings": {
		"model": "CovidUSA-Econ-V79.mdl",
		"data": [
			"CovidModelInputs - ConstantDataStates.vdf",
			"CovidModelInputs - CRWStates.vdf",
			"CovidModelInputs - DeathDataStates.vdf",
			"CovidModelInputs - FlowDataStates.vdf",
			"CovidModelInputs - FormattedDataStates.vdf",
			"CovidModelInputs - TestDataStates.vdf",
			], 
		"payoff": "PayoffFlowV77-Policy.vpd",
		"sensitivity": "", 
		"optparm": "COVID-V79-All.voc",
		"changes": [], 
		"savelist": "", 
		"senssavelist": ""
		},
	"venginepath": "C:/Program Files (x86)/Vengine2/Vensim - vengine.exe",
	"vensimpath": "",
	"graphs": "",
	"timelimit": 600,
	"mccores": 0
	}

I received the error

json.decoder.JSONDecodeError: Expecting value: line 12 column 4 (char 365)

but I am not sure what line 12 column 4 (char365) means. Also, from the code documentation as below could you please be more specific on "decode a JSON document from a string that may have extraneous data at the end."? Thanks.

    def raw_decode(self, s, idx=0):
        """Decode a JSON document from ``s`` (a ``str`` beginning with
        a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration as err:
            raise JSONDecodeError("Expecting value", s, err.value) from None
        return obj, end

Error code 3221226525 appears once

Another error code is discovered 3221226525. This gives me the license warning dialog only once (contrary to the previous error code in issue #1), it disappears and run calibration correctly in the second attempt. This error does not happens everytime, but around once in five runs. I am using the updated version Tom shared with the following comment.

The expiration warning no longer uses a dialog. This means it's not visible unless you look in the .err log in %appdata%.
Running XPARALLEL

@tseyanglim do you know how to 1. turn off warning dialog and 2.run XPARALLEL?

Initialising <__main__.Script object at 0x00000130250F8640>
-----
Starting new log at Thu Oct  6 13:18:04 2022
Ready to work!
Initialising <__main__.Script object at 0x0000013025106950>
Initialising PrPr_main_opt!
Return code is 3221226525
Vensim! Trying again...
Payoff for PrPr_main_opt is -878.334, calibration complete!
Optimization complete - payoff is -878.334!
More work? Okay!
Initialising <__main__.RunScript object at 0x0000013025106950>
Traceback (most recent call last):
  File "C:\Users\amoon\Dropbox\WINcode\VST\VST Automation\VST Automation Example v2.py", line 349, in <module>
    compile_script(cf, RunScript, 'main', 'run', {}, logfile, chglist=[('main', 'opt')])
  File "C:\Users\amoon\Dropbox\WINcode\VST\VST Automation\VST Automation Example v2.py", line 164, in compile_script
    return mainscript.run_script(scriptname, controlfile, subdir, logfile)
  File "C:\Users\amoon\Dropbox\WINcode\VST\VST Automation\VST Automation Example v2.py", line 116, in run_script
    return run_vensim_script(scriptname, controlfile['vensimpath'], 10, logfile)
  File "C:\Users\amoon\Dropbox\WINcode\VST\VST Automation\VST Automation Example v2.py", line 274, in run_vensim_script
    subprocess.run(f"{vensimpath} \"./{scriptname}.cmd\"", check=True)
  File "C:\Users\amoon\Miniconda3\envs\VST\lib\subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\amoon\Miniconda3\envs\VST\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\amoon\Miniconda3\envs\VST\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 87] The parameter is incorrect

Process finished with exit code 1

first contribution to widgets

Jason has coded customization function for the following which I find useful for hierarchical bayesian in general.

  • random index selection
  • create list of global variable from .mdl file
  • replace zero in .cin file to 10^-6
  • check payoff improvement and end optimization when the improvement is below constant threshold
  • plot of payoff function

Angie and Batman have/will code

  • sensitivity calculation
  • plot of payoff function

and if @tseyanglim could help (e.g. teach us or giving clear instructions) the three of us keep our codes in one place (e.g. widgets) we could reuse them.

Inconsistency with vensim script execution

Vensim seemingly at random will throw out various issues:

  1. "please backup your model and run reform and clean"
  2. unable to reference memory instruction at {memory location}
  3. the save dialog box mentioned in issue #6
  4. no obvious error but it just fails silently (no csv is generated, but the return code is 1)
    None of these issues occur if vengine is started by clicking on the executable and then running the mdl file, or even running the cmd script from within vensim.

Just as a reference the following is the cmd file:

SPECIAL>NOINTERACTION
SPECIAL>LOADMODEL|CovidUSA-Econ-V79.mdl
SIMULATE>payoff|PayoffFlowV77-Policy.vpd
SIMULATE>sensitivity|
SIMULATE>optparm|COVID-V79-All.voc
SIMULATE>savelist|
SIMULATE>senssavelist|
SIMULATE>DATA|"CovidModelInputs - ConstantDataStates.vdf,CovidModelInputs - CRWStates.vdf,CovidModelInputs - DeathDataStates.vdf,CovidModelInputs - FlowDataStates.vdf,CovidModelInputs - FormattedDataStates.vdf,CovidModelInputs - TestDataStates.vdf"
SIMULATE>SETVAL|Sensitivity to Weather=2.85234

SIMULATE>RUNNAME|Covidparam_Sensitivity
SIMULATE>REPORT|1
MENU>RUN|o
MENU>VDF2CSV|!|!|../SAVEFILE.txt||||
SPECIAL>CLEARRUNS
MENU>EXIT

Json decode error

The following is the control file I am using, and because of "data", I am facing json decoder jsondecodeerror which this search lead me to wrap the JSON objects in an array. I have little idea on this, @tseyanglim do you know how to change my control file?

{
	"basename": "Covid",
	"simcontrol": {
		"model": "CovidUSA-Econ-V79.mdl",
		"data": [
			"CovidModelInputs - ConstantDataStates.vdf",
			"CovidModelInputs - CRWStates.vdf",
			"CovidModelInputs - DeathDataStates.vdf",
			"CovidModelInputs - FlowDataStates.vdf",
			"CovidModelInputs - FormattedDataStates.vdf",
			"CovidModelInputs - TestDataStates.vdf"
			], 
		"payoff": "PayoffFlowV77-Policy.vpd",
		"sensitivity": "", 
		"optparm": "COVID-V79-All.voc",
		"changes": [], 
		"savelist": "", 
		"senssavelist": ""
		},
	"venginepath": "C:/Program Files (x86)/Vengine2/Vensim - vengine.exe",
	"vensimpath": "",
	"graphs": "",
	"timelimit": 600,
	"mccores": 0
	}

Is function for getting parameter value from outside voc file appropriate for widgets?

The need for getting the parameter values outside voc file is needed for sensitivity test. This is because, we wish to do sensitivity test on not only estimated parameter (e.g. Variant Impact on Immunity Loss Time[Vrnts], Variant Accuity Multiplier[Vrnts], Variant Transmission Multiplier[Vrnts], Immunity Loss Time[VS], Weight on Reported Probability of Infection[Rgn]), but also assumed parameter (e.g. Variant Intro Start Time3, Extra Vaccine Impact on Responsiveness[VS]).

To add this functionality (or is it already implemented?), would widget be the best place? @tseyanglim could you recommend some template I can refer to?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.