Parameter Studies with AI Components
CoModel's Parameter Study feature supports models containing AI components. You can sweep physics component parameters and the τ of an AI component in lag filter mode, and observe the AI component's input/output port variables. This article covers the relevant operations and constraints.
Parameters You Can Sweep
In a model with AI components, the Parameter Study panel offers these sweep targets:
| Parameter source | Sweepable | Notes |
|---|---|---|
| Physics component parameters | ✅ | Same as models without AI, e.g. resistance R, spring stiffness k |
τ of an AI component in lag filter mode |
✅ | Select the AI node in the properties panel, then specify τ |
| Internal weights of an AI component in static mode | ❌ | ONNX weights are a black box and are not exposed as tunable parameters |
| AI component input signals | Indirect | Achieved by sweeping upstream physics parameters or signal source parameters |
For example, to see how different AI output filtering strengths affect the system response, set the τ of a lag-filter AI component as the sensitivity parameter; to see how an AI surrogate's output changes under different loads, sweep the load-related physics parameters.
AI Variables Usable as Observed Variables
AI-related variables extracted from simulation results can all serve as observed variables in a parameter study:
| Variable | Mode | Type | Notes |
|---|---|---|---|
ai1.input.u |
Static / lag | observed | AI component input port signal |
ai1.output.u |
Static / lag | observed | AI component output port signal |
ai1.z |
Lag | state | Output lag filter state |
Note: Variable names follow the actual node name on the canvas. If the node is named
ai1, the variables look likeai1.output.u.
Parameter Sweep Workflow
- Open the model with AI components and finish wiring and parameter setup.
- Switch to the Parameter Study panel and choose the analysis type (parameter sweep or Sensitivity Analysis).
- Select the sweep parameters:
- Physics parameters: pick them directly from the list;
- AI component
τ: click the target AI node on the canvas first, then checkτin the parameter list.
- Choose the observed variables, e.g.
ai1.output.u. - Configure the sweep range and solver, then click Run Analysis.
Every parameter point runs its own ONNX inference calls. When the sweep finishes, results appear as 1D curves, 2D surfaces, or 3D scatter plots, consistent with regular parameter studies.
Inherited Solver Constraints
Every simulation inside a parameter study inherits the solver constraints of models with AI components:
| Your choice | Engine behavior |
|---|---|
| No solver specified | Picks Tsit5() or Rodas5P(autodiff=AutoFiniteDiff()) automatically |
| Explicit solver | Used as is |
| Implicit solver + ForwardDiff | Automatically switched to AutoFiniteDiff() |
| Implicit solver without finite-difference support | Falls back to Tsit5() with a notice |
No extra configuration is needed in the parameter study settings; the engine automatically ensures that the simulation at every parameter point respects the non-differentiable AI black-box constraint.
Performance Tips
Because every parameter point and every solver step may trigger ONNX inference, large parameter sweeps can get expensive. Recommendations:
- Set
saveatsensibly to avoid overly dense sampling; - Prefer explicit solvers to reduce black-box evaluations per step;
- For AI models with high-dimensional inputs/outputs, validate results on a small parameter range before expanding the sweep;
- If needed, convert the AI model to a lighter structure to cut inference time.
Example Analyses
Example 1: Sweeping Upstream Amplitude
Model: Sine → LinearRegressor → Scope
| Sweep parameter | Range | Observed variable |
|---|---|---|
Sine.amplitude |
[1.0, 2.0, 3.0] |
ai1.output.u |
The results show how the AI component's output varies with the input amplitude.
Example 2: Sensitivity Analysis—Effect of τ on Filtering
Model: Sine → LinearRegressorLag (lag filter mode) → Scope
| Sweep parameter | Baseline | Perturbation | Observed variable |
|---|---|---|---|
ai1.τ |
0.5 |
±10% | ai1.z |
The results show how changing τ affects how well the lag state z tracks the raw prediction.
A schematic of the sweep at the code level:
using ModelingToolkit
@named src = Sine(amplitude=2.0, frequency=1/(2π))
@named ai1 = LinearRegressorLag(τ=0.5)
@named model = System([
ai1.input ~ src.output,
], t, [], []; systems=[src, ai1])
sys = mtkcompile(model)
# Parameter sweep: vary τ
for τ in [0.01, 0.1, 0.5, 1.0]
prob = ODEProblem(sys, [], (0.0, 10.0), [ai1.τ => τ])
sol = solve(prob, Rodas5P(autodiff=AutoFiniteDiff()))
# record ai1.output.u or ai1.z
end
This code is only a schematic. The actual parameter study runs automatically in the CoModel backend; you just pick the parameters and observed variables in the panel.
Exporting Results
After a parameter study completes you can:
- Compare multiple curve sets on the canvas;
- Export the data as CSV;
- Export the charts as PNG.
AI component variables use the same export mechanism as physics variables, so you can analyze them further offline.
Common Questions
Q: An AI component in static mode has no sweepable parameters—can I still run a parameter study?
Yes. Sweep upstream physics component parameters or model-level parameters. The AI component's input signal changes accordingly, letting you observe how its output responds under different operating conditions.
Q: The parameter study fails with a solver error—what now?
Check whether the model contains an algebraic loop, or whether the AI output is fed directly back into the AI input. Prefer a feedforward structure, or manually select Tsit5() in the Simulation panel and re-validate.
Q: Why is a parameter sweep much slower than a pure physics model?
Every solver step of every parameter point triggers one ONNX inference; that overhead is normal. Speed it up with a coarser saveat, a simpler AI model structure, or a narrower sweep range.
Next Steps
- For uploading and wrapping AI components, read ONNX Upload & Component Generation.
- For the basics of using AI components in models, read Using AI Components in Models.