Inspect and Visualize Models

Inspection should come before editing configuration or selecting output. Cropbox provides complementary views of a model type, an instance, and simulation data.

List parameters

using Cropbox

@system InspectDemo(Controller) begin
    rate: growth_rate => 2 ~ preserve(parameter, u"g/hr")
    mass(rate)             ~ accumulate(u"g")
end

parameters(InspectDemo)

Config for 1 system:

InspectDemo
rate=2 g hr^-1

Useful options are:

  • alias = true: show aliases rather than short names;
  • recursive = true: include parameters in nested systems;
  • exclude = (...): omit infrastructure or already visited systems;
  • scope = module: choose where defaults are evaluated when inspecting a type.

For an instance, parameters(s) reports current values rather than declaration defaults.

Inspect declarations and values

look(InspectDemo)
look(InspectDemo, :mass)
[doc]

[system]
InspectDemo
  context
  config
  rate (growth_rate)
  mass[doc]

[code]
  mass(rate) ~ accumulate(u"g")

On an instance, look also displays the current value.

s = instance(InspectDemo)
look(s, :mass)
[doc]

[code]
  mass(rate) ~ accumulate(u"g")

[value]
0.0 g

The macro form avoids quoting a variable name:

@look InspectDemo.mass
[doc]

[code]
  mass(rate) ~ accumulate(u"g")

@look s.f(x) has another meaning: it evaluates a function-like Cropbox variable. Use the function form look(s, :f) when the goal is declaration inspection.

Inspect dependency relationships

look shows declarations; visualize shows their relationships without running a simulation:

d = visualize(InspectDemo)
h = visualize(InspectDemo; kind = :hierarchy)

The default kind = :dependency follows variables and generated update stages; kind = :hierarchy follows mixins and child systems, omitting nested Context infrastructure. Dashed hierarchy edges denote mixins. Cropbox uses its bundled Graphviz executable to render either graph as SVG on supported platforms. A static copy can be written for documentation:

Cropbox.writeimage("dependency", d; format = :svg)
Cropbox.writeimage("hierarchy", h; format = :svg)

Download the generated dependency graph or hierarchy graph.

The text representation remains available without invoking Graphviz.

To inspect just the inputs to mass, select its upstream neighborhood:

visualize(InspectDemo, :mass; direction = :up)

See Model structure for shape and arrow meanings, system grouping, and the difference between selecting neighborhoods and paths. These are static declaration graphs, not runtime traces. Explain the scientific relationships alongside the graph rather than inferring them from node shape.

To follow a local process from top to bottom, use the computation flow diagram:

visualize(InspectDemo, :rate => :mass; kind = :flow)
Example block output

It separates the accumulated value update from rate caching for a later update, with expressions alongside the rows. The same variable selectors work here. Prefer a selection for larger models: the full view keeps a lane for every variable, so it is not a compact overview. In a terminal the same result shows variable lanes when they fit, otherwise each numbered row lists its inputs. Read the flow guide for boundary inputs, cross-update rails, and SVG/PDF/PNG export.

For worked model examples, compare the accumulating state in Logistic Growth, the grouped input-to-state path in Weather-driven Phenology, and a local process in SimpleCrop.

dive(s) opens a terminal menu for walking through nested systems and values. It is not interactive in Jupyter; there it falls back to a simpler display. Use look, property access, or explicit output paths in notebooks.

Read values in Julia code

s.rate'
value(s.mass)
0.0 g

Postfix ' is concise for interactive work. value(...) is clearer in helper functions. Do not assume a system field is a bare number.

Visualize an existing result

For a side-by-side guide to argument combinations and their resulting plots, see Choose a plotting call. That reference contains the full examples for both Makie and UnicodePlots.

visualize works directly with vectors, and visualize! adds another series to the same result:

x = collect(1:5)
p = visualize(x, 2 .* x; kind = :line, name = "2x", ylim = (0, 15))
visualize!(p, x, 3 .* x; kind = :line, name = "3x")
Example block output

The explicit range reserves space for both curves, including on a fixed-size terminal canvas.

This form is useful for calculated curves that do not require a simulation. For model output, retain the DataFrame and name its columns explicitly.

r = simulate(InspectDemo; stop = 4u"hr", target = :mass)
visualize(r, :time, :mass; kind = :line)
Example block output

To simulate and plot in one call, pass the system type instead of a DataFrame, as in the Quick Start. The Visualization API compares both call forms.

Interactively explore parameters

In JupyterLab or Notebook with jupyter-server-proxy, manipulate adds widgets that update a visualization as parameter values change.

manipulate(InspectDemo, :time, :mass;
    parameters = InspectDemo => (
        rate = 0:0.5:3,
    ),
    stop = 4u"hr",
    kind = :line,
)

Use interaction to explore sensitivity and plausible ranges. For reproducible analysis, record explicit configurations and run them with simulate; an interactive widget is not a substitute for a saved experiment design.

Plot a parameter response

For a model with a configurable input, create one configuration per input value and compare one time point from each run. Here snap keeps only the state at two hours.

configs = @config !(InspectDemo => :rate => 0:0.5:3)
responses = simulate(InspectDemo;
    configs,
    stop = 2u"hr",
    snap = s -> s.context.clock.time' == 2u"hr",
    target = [:rate, :mass],
)

visualize(responses, :rate, :mass;
    kind = :line,
    xlab = "Growth rate",
    ylab = "Biomass after two hours",
    legend = false,
)
Example block output

There is one point per growth rate, with biomass equal to the rate multiplied by two hours. Without selecting a time point, this dynamic model contributes every saved snapshot at each rate; joining those rows creates a sawtooth rather than the intended response curve.

Keep responses for later analysis. The Visualization API also shows the xstep shorthand for direct response plots, group for separate series, and two input ranges for a heatmap.

Compare observations and estimates

visualize(obs, Model, ...) overlays observations and model output, while visualize(obs, Model, target; index = ...) can produce an observation-versus- estimate plot. See Evaluate and Calibrate Models for a complete workflow.