Skip to content

export_python

Python reference for nagasim.build.export_python.

Return builder code for a model.

Running the code gives m, whose to_dict() is the model in naga fmt form. Every value is written as a Python literal (repr), and a distribution as its constructor when its name and keys are the registry's, so no text of the model ever becomes code.

Parameters:

Name Type Description Default
layout str or dict

A path or a layout dict.

required

Returns:

Type Description
str

Python source.

See Also

nagasim.build.Model : What the code builds.

Examples:

>>> from nagasim import build as nb
>>> m = nb.Model(time_limit=10)
>>> _ = m.create(distribution=nb.Exponential(rate=1.0)) >> m.dispose()
>>> code = nb.export_python(m.to_dict())
>>> code.splitlines()[0]
'from nagasim import build as nb'
>>> namespace = {}
>>> exec(code, namespace)
>>> namespace["m"].to_dict() == m.to_dict()
True