edit_structure
Modify an LSD model configuration's structure by adding, renaming, deleting, or resizing objects, parameters, variables, and functions; operations apply in order and roll back if any fail.
Instructions
Change a configuration's structure (objects, parameters, variables,
functions, instance counts) with LSD's own code. operations is a list of
objects applied in order; if any fails (the message names it) nothing is
written. Writes new_config.lsd, or replaces config.lsd (old file kept as
.bak). Names must be valid LSD labels (letter or '' first, then letters,
digits, '') and unique across the whole model, objects and elements alike.
Operations, one example each:
{"op": "add_object", "parent": "Root", "name": "Firm", "instances": 10}
{"op": "add_parameter", "object": "Firm", "name": "alpha", "value": 0.5}
{"op": "add_variable", "object": "Firm", "name": "K", "lags": 1,
"initial": 1.0, "saved": true} (initial: a number, or one per lag)
{"op": "add_function", "object": "Firm", "name": "f"}
{"op": "rename", "name": "old", "new_name": "new"} (object or element)
{"op": "delete", "name": "K"} (element; an object with elements or child
objects needs "force": true and goes with all of it)
{"op": "set_instances", "object": "Firm", "instances": 50}
{"op": "set_instance_values", "name": "alpha", "values": [0.1, 0.2],
"lag": 2} (one value per instance in file order; lag only for variables)
{"op": "describe", "name": "alpha", "text": "adjustment speed"}
Parameters and variables are added to every instance of the object, with
the value (default 0) in each. set_instances gives the object that number
under every parent instance; new instances are copies of the object's
first instance (its values and its child objects), extra ones are removed
from the end; at least 1. Equations are not touched: add or change them
with write_equations. LSD's save rewrites the file in its own layout, so
old files may change in layout (empty descriptions, the notes LSD
generates for initial values of variables with no lags are dropped), never
in values.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | ||
| config | Yes | ||
| new_config | No | ||
| operations | Yes |