Vensim Translation

PySD parses a vensim ‘.mdl’ file and translates the result into python, creating a new file in the same directory as the original. For example, the Vensim file Teacup.mdl:


This allows model execution independent of the Vensim environment, which can be handy for deploying models as backends to other products, or for performing massively parallel distributed computation.

These translated model files are read by PySD, which provides methods for modifying or running the model and conveniently accessing simulation results.

Translated Functions

Ongoing development of the translator will support the full subset of Vensim functionality that has an equivalent in XMILE. The current release supports the following functionality:

Vensim Python Translation
COS np.cos
EXP np.exp
MIN min
<= <=
STEP functions.step
PULSE functions.pulse
POISSON np.random.poisson
EXPRND np.random.exponential
SIN np.sin
>= >=
IF THEN ELSE functions.if_then_else
LN np.log
PULSE TRAIN functions.pulse_train
RAMP functions.ramp
TAN np.tan
PI np.pi
= ==
< <
> >
MODULO np.mod
ARCSIN np.arcsin
ABS abs
^ **
LOGNORMAL np.random.lognormal
MAX max
SQRT np.sqrt
ARCTAN np.arctan
ARCCOS np.arccos
RANDOM NORMAL self.functions.bounded_normal
RANDOM UNIFORM np.random.rand
DELAY1 functions.Delay
DELAY3 functions.Delay
DELAY N functions.Delay
SMOOTH3I functions.Smooth
SMOOTH3 functions.Smooth
SMOOTH N functions.Smooth
SMOOTH functions.Smooth
INITIAL functions.Initial
XIDZ functions.XIDZ
ZIDZ functions.XIDZ
np corresponds to the numpy package

Additionally, identifiers are currently limited to alphanumeric characters and the dollar sign $.

Future releases will include support for:

  • subscripts
  • arrays
  • arbitrary identifiers

There are some constructs (such as tagging variables as ‘suplementary’) which are not currently parsed, and may throw an error. Future releases will handle this with more grace.