Skip to content

Give the path and boundary duals to build_solution by label (CTModels 0.21.1) #672

Open

Description

@ocots

Part of control-toolbox/CTFlows.jl#512 (tracking of the constraint duals), workstream A.

CTModels 0.21.1 is released (it contains control-toolbox/CTModels.jl#507, #509 and #510): set the compat lower bound CTModels = "0.21.1". The current call keeps working meanwhile (deprecated, with a warning).

Problem

build_solution receives the path and boundary duals by position (path_constraints_dual=, boundary_constraints_dual=, in src/DOCP_data.jl). CTModels 0.21.1 deprecates this input (Base.depwarn), to be removed at the next breaking release: the duals are given by label, build_solution(...; duals=Dict(label => value)), and CTModels places them (CTModels.Models.constraint_rows(model, label) gives the layout). A label that is not given is unknown: dual(sol, ocp, :label) throws a PreconditionError; it is never read as 0.

With :exa, CTDirect currently passes zeros for the path and boundary duals (# +++ not yet implemented for exa), so dual(sol, ocp, :c) silently returns 0.

What to do

  • ADNLP: the NLP rows follow the stacked layout of path_constraints_nl(ocp) / boundary_constraints_nl(ocp), so the multipliers are split by label with constraint_rows: Dict(label => mult[:, rows]) for each path label (after the division by the time step), Dict(label => mult[rows]) for each boundary label (a number for a one-row label).
  • :exa: pass the multipliers by label returned by the CTParser getter (Keep the :exa constraint handles by label and return the path/boundary multipliers by label CTParser.jl#414). Until that lands, pass nothing for the path and boundary labels with :exa (unknown, dual throws), and set infos[:missing_duals] to explain why, instead of zeros.
  • Box duals are unchanged (*_constraints_lb_dual / *_constraints_ub_dual, by component).

Tests

  • ADNLP: dual(sol, ocp, :label) unchanged for every path and boundary label, and no deprecation warning;
  • :exa: the path and boundary duals agree with ADNLP once the CTParser part is in; before that, dual throws a PreconditionError instead of returning 0.

Documentation: #660.

🤖 Generated with Claude Code

Activity

  1. changed the title [-]Give the path and boundary duals to build_solution by label (CTModels 0.22)[/-] [+]Give the path and boundary duals to build_solution by label (CTModels 0.21.1)[/+] on Nov 3, 2026
  2. ocots commented on Nov 13, 2026

    @ocots
    MemberAuthor

    Scope for the next release: a first step, without waiting for CTParser#414

    With the compat bump of #677 (CTModels 0.21.1), every solve prints the deprecation warning of path_constraints_dual / boundary_constraints_dual (49 times in the test suite, once per solve). A user of OptimalControl sees it on every solve, for an internal call between two packages of the organization. So this issue is split in two:

    Step 1, now (for a quick release):

    • ADNLP: the path and boundary multipliers are given by label, duals=Dict(label => value), split with CTModels.Models.constraint_rows(ocp, label) (after the division by the time step for the path rows; a number for a one-row boundary label). dual(sol, ocp, :label) must be unchanged.
    • :exa: option (b) of the description: nothing is passed for the path and boundary labels (unknown: dual throws a PreconditionError, instead of the silent 0 of today), and infos[:missing_duals] says why (not yet returned by the :exa getter, see Keep the :exa constraint handles by label and return the path/boundary multipliers by label CTParser.jl#414). This is a user-visible change, to record in CHANGELOG.md.
    • Box duals unchanged.
    • Tests: no deprecation warning (ADNLP and :exa); dual unchanged with ADNLP for every path and boundary label; dual throws with :exa for a path and a boundary label, and its message carries the note.

    Step 2, later: the :exa duals by label, once control-toolbox/CTParser.jl#414 is in.

    Plots of an :exa solution: checked, no problem

    In CTModels 0.21.1 the plots read the duals only through has_dual / dual, never as a 0:

    • src/PlotCase/rows.jl: a path constraint is always a row, with row.dual = has_dual(sol, model, label); a box is a row only when its dual is known; boundary and variable-box labels are not plotted.
    • src/PlotCase/build.jl: the dual samples are read only when a drawn path row has a known dual. A path row whose dual is unknown gets the constraint on the left, and on the right either nothing (no dual column at all when no row has a known dual) or an empty panel annotated dual not known (when another row, e.g. a box, has one).
    • This case is tested in CTModels (test/suite/plotting/test_plot_rows.jl, the dual not known annotation).

    So an :exa solution plots its path constraints, without their duals, and the box duals as before. Worth adding to the tests of step 1: plotting an :exa solution with a path constraint and the :dual group does not throw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions