Repository navigation
Hide the generated labels of unnamed constraints in plots (#526) - #534
Conversation
A constraint written without a label gets a generated one (`##unnamed#N` from CTModels, `label##N` from CTParser), and its plot row read `u (label##288)`. `Models.is_unnamed_label` now recognises any generated label (a `gensym`, whose name contains `##`), and the plot names such a row after what is known: `box u`, `path 2`, `dual box u`, `dual path 2`. The model signature uses the same predicate, so a file of a model with unnamed constraints written by CTParser can be imported against a new instance of the model, including files written before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Verification
Design note: generic namesThe generic names come from what is known about the constraint: its kind, plus the component it bounds or its row in the stacked path constraint. They contain a space, which a label (a Julia identifier) cannot, and parentheses stay reserved for real labels. So |
…526) The messages raised when the duals given by label to `build_solution`, or their limits at the switching times, are invalid showed the generated label of an unnamed constraint (`:label##288`), and suggested `constraint_rows(model, :label##288)`, which is no valid Julia. `Models._describe_constraint` names a constraint for a message: its kind and label (`path constraint :c1`), or, for an unnamed one, what is known of it (`unnamed path constraint (rows 2:3)`, `unnamed control box on u`). The switching model, which knows no model, says `unnamed constraint dual`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Second phase: the messages of
|
| constraint | description |
|---|---|
| labelled | path constraint :c1, state box :x2_box |
| unnamed nonlinear | unnamed path constraint (rows 2:3), unnamed boundary constraint (row 1) |
| unnamed box | unnamed control box on u, unnamed variable box on v₁, v₂ |
It is used in every message of the labelled duals (_checked_timed_dual, _checked_static_dual, _ensure_dual_size, _claim_components!) and in the placement of the limits at the switching times (_place_dual_limits). The constraint_rows(model, :label) hint is kept for a real label only. SwitchingModel, built before any model is known, says unnamed constraint dual.
Example:
IncorrectArgument → _ensure_dual_size
│ dual size mismatch for the unnamed path constraint (rows 2:3)
│ Got number of columns = 1
│ Expected 2 (the number of rows of the unnamed path constraint (rows 2:3))
│ Hint Give one entry per row of the unnamed path constraint (rows 2:3).
A labelled constraint now also gets its kind in the message (dual size mismatch for the path constraint :g instead of for the constraint :g).
Tests
test/suite/models/test_unnamed_labels.jl now has a fixture with unnamed constraints of every kind (path on two rows, boundary, aliased state boxes, CTParser-style control box, variable box on two components). It tests _describe_constraint (@inferred, unknown label) and checks that every message above contains no ##.
Verification
Full suite 5407 / 5407. Docs clean on the second pass (new symbol, the usual InterLinks bootstrap). typos clean, JuliaFormatter v2 clean.
Closes #526.
Problem
A constraint written without a label in
@defgets a generated label, and the plot shows it:u (label##288). CTParser generateslabel##N, outside the##unnamedconvention of CTModels, and the plot wrote the label as is.Changes
CTModels.Models.is_unnamed_label(label): one predicate for "generated label". A generated label comes fromgensym, so its name contains##. That covers both##unnamed#N(CTModels) andlabel##N(CTParser), without waiting for a CTParser change. A label given by the user is a Julia identifier and never contains##.Plot (
PlotCase, shared by Plots and Makie): an unnamed constraint is named after what is known of it.:x2_boxx₂ (x2_box)dual x2_boxx₂box x₂dual box x₂:c1c1dual c1path 2dual path 2A generic name holds a space, so it can never be mistaken for a label; parentheses stay reserved for real labels.
Model signature:
_label_stringsuses the same predicate. A solution of a model with unnamed constraints written by CTParser could not be imported against a new evaluation of@def(the generated labels differ): it now can. The labels read from the file are normalized too, so files written before this change are accepted as well.Checked, unchanged
dual(sol, ocp, label)show the label passed by the caller.Tests
test/suite/models/test_unnamed_labels.jl(new): the predicate (generated / user labels,@inferred),_label_strings, and the signature of two instances of a model with generated labels (non-regression).test/suite/plotting/test_plot_rows.jl: the naming helpers; a figure with a labelled path constraint, a two-row unnamed path constraint, an unnamed state box and a control box labelled as CTParser does. No##in any ylabel, and the duals plotted alone are named too.test/suite/serialization/test_import_model_mismatch.jl: import validation is silent across instances with generated labels, including an old file holdinglabel##288.Follow-up
On CTParser, have an unnamed constraint take CTModels' default label, so that one convention holds. Not required for this fix.
Conventions: ct-conventions v0.14.0, ct-agents v0.5.0.
🤖 Generated with Claude Code