Skip to content

A Julia package to import Vensim .xmile files as ModelingToolkit.jl models.

License

Notifications You must be signed in to change notification settings

worlddynamics/Vensim2MTK.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vensim.jl

DOI

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 Vensim2MTK

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, lotka, commitment and community corona 8. Here is a quick explanation 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 work. Usually, the .mdl works with no issue).

  • lotka is the simple Lotka-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 effectiveness 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.

Issue #33

It is necessary to make sure the model that is to be parsed does not contain special characters in it's variable name. The special characters mentioned are: ",-,(,),+,/,*,^,=,!,{,[,],} and ,.

How to cite this work

@software{emanuele_natale_vensim2mtk_2023,
  author       = {Emanuele Natale and
                  Maël Clergue},
  title        = {Vensim2MTK.jl: v0.1.0},
  month        = july,
  year         = 2023,
  publisher    = {Zenodo},
  version      = {v0.1.0},
  doi          = {10.5281/zenodo.8179079},
  url          = {https://doi.org/10.5281/zenodo.8179079}
}

About

A Julia package to import Vensim .xmile files as ModelingToolkit.jl models.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages