SDXorg / pysd

System Dynamics Modeling in Python
http://pysd.readthedocs.org/
MIT License
376 stars 88 forks source link

Parse Vensim Models formatted as Tables #140

Closed JamesPHoughton closed 2 years ago

JamesPHoughton commented 7 years ago

The visual front end of Vensim is not helpful to individuals with impaired sight. More helpful would be to be able to construct models in a tabular format, that let the individual focus on text and equations. It would be pretty easy to map a vensim model file into a table, so why not do the reverse:

Start with:

Variable Equation Units Min Max Comment
Characteristic Time 10 Minutes 0 inf How long will it take the teacup to cool 1/e of the way to equilibrium?
Heat Loss to Room (Teacup Temperature - Room Temperature) / Characteristic Time Degrees Fahrenheit/Minute -inf inf This is the rate at which heat flows from the cup into the room.
Room Temperature 70 Degrees Fahrenheit -459.67 inf The room temperature cannot go below absolute zero.
Teacup Temperature INTEG (-Heat Loss to Room, 180) Degrees Fahrenheit 32 212 The model is only valid for the liquid phase of tea. While the tea could theoretically freeze or boil off, we would want an error to be thrown in these cases so that the modeler can identify the issue and decide whether to expand the model. Of course, this refers to standard sea-level conditions...
FINAL TIME 30 Minute     The final time for the simulation.
INITIAL TIME 0 Minute     The initial time for the simulation.
SAVEPER TIME STEP Minute 0 inf The frequency with which output is stored.
TIME STEP 0.125 Minute 0 inf The time step for the simulation.

and end up with:

haracteristic Time = 
     10 
    ~    Minutes [0.0, inf] 
    ~    How long will it take the teacup to cool 1/e of the way to equilibrium? 
    |

Heat Loss to Room = 
     (Teacup Temperature - Room Temperature) / Characteristic Time 
    ~    Degrees Fahrenheit/Minute [-inf, inf] 
    ~    This is the rate at which heat flows from the cup into the room. 
    |

Room Temperature = 
     70 
    ~    Degrees Fahrenheit [-459.67, inf] 
    ~    The room temperature cannot go below absolute zero. 
    |

Teacup Temperature = 
     INTEG (-Heat Loss to Room, 180) 
    ~    Degrees Fahrenheit [32.0, 212.0] 
    ~    The model is only valid for the liquid phase of tea. While the tea could theoretically freeze or boil off, we would want an error to be thrown in these cases so that the modeler can identify the issue and decide whether to expand the model. Of course, this refers to standard sea-level conditions... 
    |

FINAL TIME = 
     30 
    ~    Minute [nan, nan] 
    ~    The final time for the simulation. 
    |

INITIAL TIME = 
     0 
    ~    Minute [nan, nan] 
    ~    The initial time for the simulation. 
    |

SAVEPER = 
     TIME STEP 
    ~    Minute [0.0, inf] 
    ~    The frequency with which output is stored. 
    |

TIME STEP = 
     0.125 
    ~    Minute [0.0, inf] 
    ~    The time step for the simulation. 
    |

\\\---/// Sketch information - this is where sketch stuff would go.
JamesPHoughton commented 7 years ago

A prototype in branch: https://github.com/JamesPHoughton/pysd/tree/tabular_models

JamesPHoughton commented 7 years ago

Use like normal PySD, but use read_tabular and pass in the name of the file where the model is defined.

import pysd
model = pysd.read_tabular('test-models/samples/teacup/teacup_mdl.tab')
result = model.run()