Skip to content

Translators

Translate system files of other tools into the source of system modules.

SystemDynamicsTranslator(path, *, name=None)

Bases: BaseConfig[None, None]

Translator of a Vensim or XMILE file into the source of a system module of the library.

The module holds one element class, whose states are the stocks and whose parameters are the constants of the file, one private function per auxiliary and lookup, the function create_system(), the function observables(system), and the constants START, UNTIL, DT, and SAVE_EVERY. A flow variable of two stocks becomes a TransferInteraction between them, a flow variable of one stock a TransferInteraction with Source() or Sink(), and what remains of the rate of a stock a RelaxationInteraction or a RateInteraction. A system whose stocks are all subscripted over one range becomes a GroupElement with one member per subscript.

Parameters:

Name Type Description Default
path str | Path

The path of a .mdl, .xmile, .xml, or .stmx file.

required
name str | None

The name of the element and the base of the name of its class, or None for the name of the file.

None

Attributes:

Name Type Description
system_

The abstract system PySD reads from the file.

source_

The Python source of the system module.

settings_

The run settings of the control section of the file.

Raises:

Type Description
ValidationError

The path names no file of a known format, or the name is not an identifier, raised by prepare. The file has constructs without a counterpart, or names that clash, all of them listed, raised by run.

Examples:

>>> import tempfile
>>> from pathlib import Path
>>> from skcomplex.core.engine.translators import SystemDynamicsTranslator
>>> text = '''
... Stock = INTEG(Inflow, 1) ~ ~ |
... Inflow = 2 * Stock ~ ~ |
... INITIAL TIME = 0 ~ ~ |
... FINAL TIME = 4 ~ ~ |
... TIME STEP = 0.25 ~ ~ |
... SAVEPER = 1 ~ ~ |
... '''
>>> with tempfile.TemporaryDirectory() as folder:
...     path = Path(folder) / 'growth.mdl'
...     _ = path.write_text(text)
...     translator = SystemDynamicsTranslator(path).prepare().run()
>>> translator.settings_.until
4.0
>>> 'class GrowthElement(Element):' in translator.source_
True
Source code in src/skcomplex/core/engine/translators/_system_dynamics.py
92
93
94
def __init__(self, path: str | Path, *, name: str | None = None) -> None:
    self.path = path
    self.name = name