Vensim.jl

This package provides a function Vensim2MTK that can produce a Julia file of a model using ModelingToolkit from an exported Vensim model.

Usage of the function: The function takes 3 arguments:

  • filepath: the path to the vensim file that one wants to translate. Default to ./examples/Dice.xmile.
  • filename: the name of the output file. Default to the name of the input file with the extension .jl replacing .xmile.
  • overwrite: boolean argument that indicate in the case of the file already existing, if the function aborts or overwrite it(true to overwrite).

Example of use:

using Vensim

filepath="path/to/a/vensim/model/model.xmile"
filename="MTKmodel.jl"
overwrite = false
Vensim2MTK(filepath, filename, overwrite)

This code will write in the file MTKmodel.jl an implementation in ModelingToolkit of the model exported in model.xmile from the Vensim app.

Examples of models used

There are currently 4 models used as examples for the parser: DICE, lokta, commitment and community corona 8. Here is a quick explenation of each as well as where we found them:

  • Dice is William Nordhaus’ Dice model; the implementation of it was found here and is the DICE-heur-7-PLE.mdl version (as Vensim has some issues with exporting some models as xmile files, some version of the models used may not works. Usually, the .mdl works with no issue).

  • lokta is the simple lokta-voltera predation model, found here.

  • commitment is a model that is based on an Arxiv paper. The model was published on this blog post.

  • community corona 8 is a model representing the evolution of the coronavirus in a community, and the effectivness of some method. See this blog post.

List of Vensim functions currently implemented

  • if_then_else
  • EXP
  • LOG
  • GAME (will not cause an error but not implemented, as there is no interactive mode yet)
  • SMOOTH
  • SMOOTHi
  • STEP
  • MAX
  • MIN
  • LN
  • ABS
  • COS
  • ARCCOS
  • SIN
  • ARCSIN
  • TAN
  • ARCTAN
  • GAMMA_LN
  • MODULO
  • SMOOTH3
  • PULSE
  • RAMP
  • SMOOTH3i
  • DELAY1
  • DELAY1I

Issue #12

If some variables need to be initialised by other variables that are not directly initialised, the program automatically initialises them with a default value (42). It is necessary to replace these with values that are at least not too far away from the real ones; just so that the model runs correctly without failing. It is then possible to obtain the true initial value and replace these arbitrary values with those calculated by ModelingToolkit; then re-run the model, obtaining from now on the real values for the whole model.