MDL
Edit models as text, discover sections and block arguments with suggestions, and apply changes to the diagram.
inputs:
setpoint: float64
feedback: float64
outputs:
command: float64
parameters:
Kp: float64 = 1.2
Ki: float64 = 0.4
Kd: float64 = 0.05
diagram:
error = setpoint - feedback
p = Kp * error
i = Ki * Integral(error)
d = Kd * Derivative(error)
command = p + i + dMDL is Modeloop’s textual modeling language. It represents a model’s interfaces, calculations, state, and nested diagrams. Expressions describe the same operations and signal dependencies that appear as blocks and connections on the canvas.
Use MDL to inspect a model, change several parameter values, write expressions, or organize nested behavior. Text edits are checked before they can be applied to the diagram.
Edit a model as text
- Open a model in Edit mode.
- Select Edit as text (MDL) in the main toolbar.
- Edit the source, using Suggest or Ctrl+Space to discover available sections, blocks, and arguments.
- Pause typing to let validation finish. Review any reported errors.
- When the changes are valid, select Apply or press Ctrl+Enter on Windows and Linux, or Cmd+Enter on macOS.
The editor shows the whole model, including when opened from a nested diagram. The section corresponding to the current diagram is highlighted while the text is unchanged. The model name appears in the card header; the source begins directly with its sections.
For example, this model limits an input to the range from zero to one:
inputs:
demand: float64
outputs:
command: float64
diagram:
command = Saturation(demand, lower=0.0, upper=1.0)demand and command define the model’s public interfaces. The call to Saturation defines the calculation between them. An input of -0.5 produces zero, an input of 0.5 produces 0.5, and an input of 1.5 produces one.
Change upper=1.0 to upper=0.8 and select Apply to update the block’s limit. Applying changes updates the open model. Save the model to preserve the working project, and use Version Control to record a commit.
Discover the syntax
Suggestions depend on the cursor position. Select an item to read its description and inspect the syntax it will insert.
| Cursor position | Suggestions |
|---|---|
| At the start of a top-level line | Sections that the model does not already contain |
After a declaration’s : |
Available data types |
| In a diagram expression | Document symbols, block calls, and language constructs |
After ( or , in a block call |
Named arguments that have not already been supplied before the cursor, followed by symbols and block calls |
After type= |
Available data types |
For example, inside Saturation(demand, , the editor offers the argument names lower and upper. Signature help shows the call’s parameters and emphasizes the current argument. Block arguments come from the available block library; use these suggestions to check their spelling.
Section and block snippets contain editable fields. After inserting a snippet, replace the selected field and press Tab to move to the next one. Suggestions stay closed inside comments and quoted strings.
Keyboard controls
| Control | Action |
|---|---|
| Suggest or Ctrl+Space | Open suggestions at the cursor |
| Up / Down, then Enter or Tab | Choose and accept a suggestion |
| Tab in a snippet | Move to the next field |
| Tab in ordinary text | Indent by four spaces |
| Escape with suggestions open | Dismiss suggestions |
| Ctrl+Enter / Cmd+Enter | Apply valid changes |
Use the fold control beside a section or nested diagram to collapse its body. Folding changes the view without changing the source or the model.
Sections and declarations
Sections begin at the left margin. Indent their contents by four spaces, and use the same indentation for statements in the same body. Lines beginning with # are comments.
| Section | Contents |
|---|---|
inputs: |
Input names and their declared types |
outputs: |
Output names and their declared types |
parameters: |
Model parameter names, types, initial values, and optional calibration storage |
datatypes: |
User-defined types, including enumerations |
diagram: |
Expressions, block calls, and nested behavior |
Include the sections needed by the model. Write a declaration as name: type. A scalar uses a type such as float64, int32, or bool. Dimensions follow the type: float64[3] is a vector, and float64[2, 3] is a matrix. See Signals for type and shape rules.
An assignment such as error = target - measured creates a calculation and names its result. Reusing error supplies that signal to another calculation. Assign a declared output to expose a result at the model boundary. Use intermediate names for values that will be read by other expressions; public output declarations are destinations.
Expressions and state
Expressions establish data dependencies. Their line order does not define a procedural execution sequence. Modeloop derives execution order from those dependencies, as described in Model Execution.
+ and - express addition and subtraction. * expresses scalar scaling or matrix multiplication, while .* expresses elementwise multiplication. / is elementwise division. Operand types and shapes must satisfy the operation’s rules.
State is explicit through memory blocks. This filter uses its previous filtered value and an initial value of zero:
inputs:
noisy: float64
outputs:
clean: float64
diagram:
previous = UnitDelay(filtered, initial=0.0)
filtered = 0.9 * previous + 0.1 * noisy
clean = filteredThe delay expresses the feedback timing. See Unit Delay for its behavior and initial conditions.
An unconnected input may appear as ?. This represents an unwired connection. Supply the intended signal before executing a model that requires that input.
Parameters and data types
Declare model parameters in parameters: and refer to them by name in expressions. Prefix a declaration with calibration when its value is intended for calibration storage. Enumeration members use qualified names such as Mode.ON.
datatypes:
Mode = Enum(members={"OFF": 0, "ON": 10})
parameters:
calibration gain: float64 = 2.5
inputs:
u: float64
outputs:
y: float64
mode: Mode
diagram:
y = gain * u
mode = Mode.ONThese declarations use the same model data as the Data Manager. Applying a data-only change updates that data along with the model’s history. See Parameters & Data for scope, references, and calibration behavior.
Nested diagrams
An inline container declares a nested diagram. Its arguments supply the local inputs; output publishes the result to the assignment in the parent diagram.
inputs:
u: float64
outputs:
y: float64
diagram:
y = container Scale(sample=u):
scaled = 2.0 * sample
output scaledFor several outputs, write a matching list of targets in the parent and names after output in the body. See Model Hierarchy for choosing between models, containers, and callbacks.
Callbacks and timing
A callback defines a separate executable diagram with periodic or event activation. This callback publishes a limited command every 10 milliseconds:
inputs:
demand: float64
outputs:
command: float64
diagram:
command = callback Control(demand) every 10ms:
limited = Saturation(demand, lower=0.0, upper=1.0)
output limitedAn event callback uses on event with a scalar Boolean activation signal. Callback activation belongs to the model; tasks and execution order belong to the build configuration. See Callback and Model Execution.
Conditional behavior
A conditional selects a branch from its predicate. Each branch assigns values to the conditional’s output names. An else branch supplies the alternative behavior.
inputs:
u: float64
outputs:
y: float64
diagram:
y = conditional Nonnegative(u):
branch Positive [u >= 0]:
y = u
branch Negative else:
y = 0.0See Conditional for branch selection and interfaces. State machines use fsm bodies with states, actions, and transitions; see State Charts for those concepts.
Record internal signals
Use observe to select an internal signal for measurement while keeping it inside the model:
inputs:
target: float64
measured: float64
outputs:
command: float64
diagram:
observe error = target - measured
command = Saturation(error, lower=0.0, upper=1.0)Apply the text, then inspect the model’s measurements and run a scenario to record the signal. Observations can also be declared inside nested diagrams. See Signals for measurement settings and result inspection.
Apply, discard, and history
Typing changes the text buffer. Editing… means the buffer has pending edits, Checking… means validation is running, and Ready to apply means the validated changes can be applied. Reported errors leave the diagram unchanged. Select a diagnostic to reveal and focus its source line.
Apply updates the diagram and model data in one undoable operation. Matched elements retain their identities and layout; new elements receive positions. Applying from a nested diagram retains that navigation when the edited hierarchy still contains it.
Discard reloads the current diagram’s text. Closing with unapplied work offers Discard and close so that the decision is explicit. If the diagram changes while the text is dirty, copy any work you need to retain or discard the buffer to load the updated diagram.
Text edits have their own undo history. To reverse an applied model change, close the text editor and use the model’s Undo or Redo controls. Formatting-only changes that preserve the model create no model-history entry.
Text editing is available in Edit mode. Return from Testing to Edit before opening the editor or applying changes. If an open editor becomes read only, its source can still be selected and copied.
Complete MDL documents
The in-app editor already knows the model name from the open model. A standalone .mdl document includes a component declaration and indents the body one level further:
component Limiter:
inputs:
demand: float64
outputs:
command: float64
diagram:
command = Saturation(demand, lower=0.0, upper=1.0)Use this complete form for standalone MDL files and command-line parsing or formatting. Use the section-only form when editing the body in the application. Both forms describe the same model behavior.