Skip to content

[Problems] Proof of concept: a ModelingToolkit modeling, solved with Corleone, with our own bryson_denham #308

Open
3 of 3 issues completed

Description

@ocots

Agents: read the guide for agents in #310 first (order, difficulty, how to claim an issue, working method). The specification is in this description and in the comments below.

Updated on 2026-11-06 after #360 (convergence is reported, not tested) and #375 (reference objectives). Where an older comment contradicts this description, the description wins; what changed is listed in the update comment.

Goal

A proof of concept of a new modeling, ModelingToolkit: write our own bryson_denham as a ModelingToolkit system in this package, as an extension, and show how to solve it with Corleone (SciML, direct shooting with DiffEq), with retrieval, tests and documentation. This shows that every part of the infrastructure (registry, statuses, tests, crons, results pipeline, documentation) handles a modeling whose method differs. Then decide whether to write more problems this way.

Modeling and solving are separate, as for OptimalControl (problem written with @def, method chosen in solve): the modeling is the language the problem is written in, ModelingToolkit; Corleone is one way to solve a ModelingToolkit system, as Ipopt is for JuMP. Other methods could solve the same system (ModelingToolkit's own dynamic optimization interfaces, e.g. JuMPDynamicOptProblem, CasADiDynamicOptProblem, to check).

Part of #310, step 7 (last). Depends on #303, #304, #306, #314, #307.

Work: sub-issues

Part Issue State
1. ModelingToolkitBackend, ModelingToolkitModels extension, and continuous bryson_denham (:draft) #437 done (#440)
2. Corleone solve helper and ModelingToolkit test suite (smoke, reference solution, :valid) #438 open (ready)
3. ModelingToolkit convergence cron, trajectories (#314), and documentation (#307) #439 open (depends on #438)

What it is not

Not an import of SciML's OptimalControlBenchmarks catalogue. The problem is ours, rewritten: our dynamics, parameters, cost, initial guess; only the method changes (shooting with piecewise-constant controls instead of collocation). Their catalogue is a source of inspiration (MTK and Corleone usage, prepare_benchmark, solve_with_corleone, plotting) and of problems to port later.

Problem

bryson_denham as in ext/OptimalControlModels/bryson_denham.jl: ẋ₁ = x₂, ẋ₂ = u, x(0) = (0, 1), x(1) = (0, -1), x₁(t) ≤ 1/9, cost ∫ ½ u², parameters from ext/MetaData/bryson_denham.jl. Analytic optimum (ℓ = 1/9 ≤ 1/6): J = 4/(9ℓ) = 4, recorded as the analytic objective with its source (#379). The reference_objective of #375 is the objective of the trapezoidal discretization at the default grid (4.000143…): it does not apply to a shooting solve, whose discretization differs.

Inherent to shooting with Corleone, to state on the problem page: the state constraint is imposed at the points of a constraint grid only, and controls are piecewise constant on a control grid.

The ModelingToolkit system must be continuous. In SciML's catalogue, the constructor receives the grids and samples the state constraint itself (x(tᵢ) ≲ 1/9 for tᵢ in constraint_grid). Here:

  • (a) write a continuous path constraint x₁(t) ≲ 1/9 in the system, if ModelingToolkit can represent it;
  • (b) sample it on Corleone's constraint grid when preparing the solve.

First task: check (a). If ModelingToolkit cannot represent a continuous path constraint, fall back to passing the constraint grid at retrieval, as grid_size for JuMP, and say so here.

Scope

  1. Modeling: entry ModelingToolkitBackend in the modeling table ([Dev] Per-modeling lists of problems, discovered automatically, with a status per modeling #303); extension triggered by ModelingToolkit only; file ext/ModelingToolkitModels/bryson_denham.jl; status :draft first.
  2. Retrieval: bryson_denham(ModelingToolkitBackend(); parameters=…) returns our generic Problem ([Paper] Port to OptimalControl v2 and new problem interface #283); model(pb) is the continuous ModelingToolkit system (with its time span).
  3. Solving with Corleone (not part of the extension; in tests, documentation and user code): build the control, shooting and constraint grids from a grid size (single shooting by default, multiple shooting as an option), prepare the Corleone model (as prepare_benchmark in SciML's catalogue), solve with Ipopt.
  4. Initial guess: our shared :init ([Metadata] Computed features, reference objective, shared initial guess #306) is used: evaluated on the control grid for the controls, and at the shooting nodes for the states in multiple shooting, written into the parameter vector of the prepared Corleone model (model.ps, through pack / reconstruct as in Corleone's examples). Check first that this is possible.
  5. Tests (test/ModelingToolkit environment, which also loads Corleone; label test ModelingToolkit backend; Saturday cron of [Tests] Crons per scope for the slow tests, with reports #305):
    Three kinds of tests, as for the other modelings ([Tests] Report convergence instead of testing it; keep hard checks for breakage and model equivalence #360):
    • model verification and contract (test_problem.jl): verify components, dimensions, symbolic dynamics against theoretical equations, cost functional, and constraints;
    • does not break (test_smoke.jl, every run): build the system; solve with Corleone on a small grid with a few iterations (Ipopt); no exception, finite objective;
    • reference solution (test_reference_solution.jl): solve with Corleone + Ipopt and compare the optimal objective to the analytic objective;
    • convergence report (cron, never fails, no tolerance): solve on the default grid; report the solver status and the gaps to the analytic objective and to the OptimalControl objective.
      (Note: unlike JuMP where we write our own transcription and test exact discrete NLP equivalence with CTDirect, there is no NLP/algorithmic equivalence test with Corleone, which is an external ODE-shooting solver with a different transcription).
  6. Documentation: the ModelingToolkit documentation adapter of [Doc] Rewrite the documentation: getting started, user guide, problems, developers #307 / [Doc] Results pipeline for the documentation, and a gallery of problems #314: the tab of the problem page shows how to get the system and solve it with Corleone; result in result.json; plot. Nothing else changes, which checks that the documentation handles every modeling generically.

Points to check first

  • Environments: with an extension, users who do not load ModelingToolkit install nothing; but the test/ModelingToolkit and documentation environments must resolve the OptimalControl v2 stack and the SciML stack together (shared dependencies such as ForwardDiff or Symbolics). If the documentation environment cannot, compute these results in their own job ([Doc] Results pipeline for the documentation, and a gallery of problems #314) and only read them in the documentation.
  • Compat bounds for ModelingToolkit (extension) and Corleone (test and documentation environments), which move fast.

Noted while reading OptimalControlBenchmarks (for later)

Not needed here, since we write our own problems; to report to the authors if useful:

  • robbins: the state constraint is x₃(tᵢ) ≥ 0 in a variable named grid_cons_x₁; the Robbins problem constrains x₁.
  • double_oscillator: m₁ = 200 (ours 100), and the cost integrated over (0, 1) while the horizon is [0, 2π].
  • bryson_denham: cost ∫ w² (no ½), state constraint sampled.

Done when

Activity

  1. changed the title [-][Problems] Use Corleone's OptimalControlBenchmarks: new problems and cross-check[/-] [+][Problems] Proof of concept: one Corleone problem as a third modeling[/+] on Nov 4, 2026
  2. changed the title [-][Problems] Proof of concept: one Corleone problem as a third modeling[/-] [+][Problems] Proof of concept: a Corleone modeling, with our own bryson_denham[/+] on Nov 4, 2026
  3. changed the title [-][Problems] Proof of concept: a Corleone modeling, with our own bryson_denham[/-] [+][Problems] Proof of concept: a ModelingToolkit modeling, solved with Corleone, with our own bryson_denham[/+] on Nov 4, 2026
  4. ocots commented on Nov 6, 2026

    @ocots
    MemberAuthor

    Update after #360 and #375

    Principle since #360: three kinds of tests. Does not break (every CI run, short) and model equivalence (every CI run, no solve) can fail; the convergence report (cron, or label test convergence) gives the solver status and the relative gap of the objective to the reference objective (#375), never fails, no tolerance. The description is updated:

    • Tests in the three kinds: does not break (small grid, few iterations); model equivalence = the cross-evaluation (with a tolerance derived from the grid, since the methods differ); convergence report in the cron (gaps to the analytic objective and to OptimalControl, no tolerance). This replaces "objective against the analytic value and against OptimalControl, with a tolerance".
    • Reference: J = 4 is the analytic objective of the continuous problem, recorded with its source in [Metadata] Declared fields: tags, references, Corleone, reference solution #379. The reference_objective of [Metadata] Reference objectives per scheme, computed by a script #375 is the trapezoidal one at the default grid (4.000143…); it does not apply to a shooting solve.
    • Status: :valid once the model is equivalent, not once it converges.

    🤖 Generated with Claude Code

  5. ocots commented on Nov 8, 2026

    @ocots
    MemberAuthor

    Preliminary checks & split into sub-issues (#437, #438, #439)

    All prerequisites in #310 (#303, #304, #305, #306, #307, #311, #314, #326, #409, #413) are now merged on main.

    Results of the preliminary checks

    1. Continuous path constraint (a) + (b):
      • (a) In ModelingToolkit.System (ext/ModelingToolkitModels/bryson_denham.jl): ModelingToolkit.System(eqs, t; costs, constraints, name) supports continuous symbolic path inequalities depending on t = ModelingToolkit.t_nounits (x₁(t) ≲ x1_max) alongside point constraints (x₁(tf) ~ x1_tf, x₂(tf) ~ x2_tf), with (t0, tf) encoded in the Symbolics.Integral(t in (t0, tf)) cost domain. Therefore bryson_denham(ModelingToolkitBackend()) needs no grid argument and returns a genuinely continuous Problem.
      • (b) In Corleone (test/common/solve_modelingtoolkit.jl): Corleone.CorleoneDynamicOptProblem(sys, ...) requires every signal call x(τ) in ModelingToolkit.get_constraints(sys) to have a concrete finite real number τ (time isa Real && isfinite(time)). In SolveModelingToolkit, any constraint depending on iv = ModelingToolkit.get_iv(sys) is expanded onto constraint_grid via Symbolics.substitute(c, Dict(iv => τ)) before calling CorleoneDynamicOptProblem.
    2. Shared initial guess :init ([Metadata] Computed features, reference objective, shared initial guess #306):
      • model = CorleoneDynamicOptProblem(...) stores piecewise-constant control parameters in model.ps.parameter.parameters (one .ps vector of length $N$ per control input) and shooting state parameters in model.ps.initialcondition. Evaluating init.control on the $N$ intervals of control_grid and init.state on shooting_grid (for multiple shooting) populates ps, which is passed to OptimizationProblem(model, AutoForwardDiff(); ps=ps).
    3. Cross-evaluation (test_equivalence.jl):
      • Corleone.optimization_objective(model, ps, model.st) and Corleone.optimization_constraints(model, ps, model.st) (bounded by model.lcons and model.ucons) evaluate the ODE shooting objective and constraint residuals at imposed parameters ps without solving.
    4. Environments & compat bounds:
      • Root Project.toml: weakdep ModelingToolkit (compat = "11"), extension ModelingToolkitModels = "ModelingToolkit".
      • test/suite/ModelingToolkit/Project.toml: isolated subprocess environment with ModelingToolkit = "11", Corleone = "2", OrdinaryDiffEqTsit5 = "2", Optimization = "5", OptimizationMOI = "1", Ipopt = "1", ComponentArrays = "0.15", ForwardDiff = "1", OptimalControl = "2.2", NLPModelsIpopt = "0.11".
      • docs/make.jl reads precomputed results from the results branch ([Doc] Results pipeline for the documentation, and a gallery of problems #314) and never runs Corleone at doc-build time.

    Sub-issues (each leaving main in a functional, passing state)

    1. [Problems] ModelingToolkitBackend, extension ModelingToolkitModels, and continuous bryson_denham (#308) #437 — Part 1: ModelingToolkitBackend, extension ModelingToolkitModels, and continuous bryson_denham (:draft)
      • Backend registration, ModelingToolkitModels weakdep extension, CTModels.Models component/dimension interface on ModelingToolkit.AbstractSystem, continuous bryson_denham model, docs/modelings.jl adapter, and test/suite/ModelingToolkit/test_problem.jl.
    2. [Tests] Corleone solve helper and ModelingToolkit test suite (smoke, reference solution) (#308) #438 — Part 2: Corleone solve helper and ModelingToolkit test suite (smoke, cross-evaluation, reference solution, :valid)
      • test/common/solve_modelingtoolkit.jl (SolveModelingToolkit), test_methods.jl, test_smoke.jl, test_equivalence.jl (cross-evaluation), test_reference_solution.jl, and promoting bryson_denham to :valid.
    3. [Cron/Doc] ModelingToolkit convergence cron, trajectories, and documentation (#308) #439 — Part 3: ModelingToolkit convergence cron, trajectories ([Doc] Results pipeline for the documentation, and a gallery of problems #314), and documentation ([Doc] Rewrite the documentation: getting started, user guide, problems, developers #307)
      • test/cron/ModelingToolkit/test_convergence.jl (with trajectory export for ProblemPlot.vue), enabling Saturday cron in .github/workflows/CronModelingToolkit.yml, and updating docs/make.jl, docs/api_reference.jl, ext/README.md, and test/README.md.
  6. ocots commented on Nov 9, 2026

    @ocots
    MemberAuthor

    Part 1 (#437) is merged in #440.

    • ModelingToolkitBackend is registered in MODELING_SPECS and exported.
    • ModelingToolkitModels weak-dependency extension provides CTModels.Models accessors for ModelingToolkit.AbstractSystem.
    • bryson_denham(ModelingToolkitBackend()) returns the continuous Problem with continuous path constraint x₁(t) ≲ x1_max, integral cost, default parameters, and shared :init.
    • All suite/core and suite/ModelingToolkit tests pass. Documentation builds cleanly.

    Ready for Part 2 (#438: Corleone solve helper and test suite).

  7. ocots commented on Nov 11, 2026

    @ocots
    MemberAuthor

    Written by Claude (Claude Code) at the request of ocots.

    Delivered (#440, #442, #444), and why three points differ from the specification

    The three parts are merged and the first cron run on main is launched (run 43061056587). Three points of the description were not done as written. Here is why, so that the decision asked at the end of this issue is taken knowing it.

    1. The documentation snippet stops at the model; it does not show the solve with Corleone

    The scope (item 6) asked for a tab that shows how to get the system and solve it with Corleone. The page shows how to get the system and its initial guess, and its summary says what Corleone adds.

    • What a solve needs is not in the model. The control grid, the controls piecewise constant, the path constraints imposed at the nodes (every signal in a constraint must be at a finite time for Corleone, see the preliminary checks above) and the start of the controls are choices of the method, written in test/common/solve_modelingtoolkit.jl. A snippet of a few lines cannot show them without copying them.
    • The first version of the snippet was wrong, and nothing could have caught it. It hardcoded tspan = (0.0, 1.0) (true for bryson_denham only), and passed the system as it is, without the discretization of the path constraint that the tests use: a reader who copied it solved another problem. The documentation never runs Corleone (as decided in the preliminary checks, it reads precomputed results), so a solve snippet is displayed and never executed: it drifts silently from the code the tests run.
    • What would bring it back. The preparation (time span, discretization of the path constraints, grids, start of the controls) exposed as code shared by the tests and the snippet, and the snippet run in the documentation build or in a test. Then the page can show the solve. It is not worth doing before the decision on more problems.

    The results of the cron are drawn on the page as for the other modelings, and checked_against is nothing (see 3).

    2. test_reference_solution is removed

    The description asked for a test that solves with Corleone and Ipopt and compares the objective with the analytic one. It was written in #442 (a succeeded assertion and a relative gap under 5 %), and removed in #444.

    • Convergence is reported, not tested ([Tests] Report convergence instead of testing it; keep hard checks for breakage and model equivalence #360). A test that fails when a solver does not converge, or lands 6 % from the optimum, fails on a property of the solver and of the discretization, not of the model.
    • 5 % could not detect a wrong model anyway. A wrong cost or a wrong bound can stay under it. The model is protected by the equivalence test (3), which fails on any difference of the model.
    • The information is kept where it belongs. The cron solves every problem on its default grid and records the gap to the analytic objective (reference of TestStatus.result!; a shooting solve has no reference objective of its own discretization, the reference_objective of [Metadata] Reference objectives per scheme, computed by a script #375 is the trapezoidal one), the violation of the constraints, the iterations, the time and the trajectory.
    • This agrees with the update of 2026-11-06 of this description: status :valid once the model is equivalent, not once it converges. The scope list (item 5) predates that update.

    3. The equivalence is checked at the continuous level, not by evaluating Corleone's objective

    The preliminary checks proposed to evaluate Corleone.optimization_objective and optimization_constraints at imposed parameters and compare them with OptimalControl, with a tolerance derived from the grid. What was done instead: suite/ModelingToolkit/test_modelings reads the ModelingToolkit System as the data of a JuMP problem (test/common/continuous_modelingtoolkit.jl) and compares it with the OptimalControl and the scalarized models by Continuous.compare (test/common/continuous.jl, #441, #446): the times, the dynamics, the objective, the path and boundary constraints and the bounds, at points taken on the initial guess.

    • It tests the model, not the transcription. Evaluating through Corleone mixes the formulation with the shooting discretization and needs a tolerance, which Rationalize JuMP and comparison test suites: separate generic transcription unit tests from per-problem modeling checks #441 avoided for JuMP by comparing at the continuous level. Here no solve, no grid, no tolerance beyond rounding: it runs on every pull request, for every problem (20 s for the four problems and the two OptimalControl models in CI).
    • It catches the errors. Changing one parameter on the ModelingToolkit side only, for robbins, jackson and vanderpol, fails exactly the matching check: γ the objective, x₁_l and a_u the state bounds, u_u the control bounds, k2 and ε the dynamics, x₂_t0 the boundary conditions.
    • It runs in the opt-in ModelingToolkit environment, which therefore loads OptimalControl; the comparison environment stays free of ModelingToolkit. That is why the documentation does not say that the modeling is "checked on every pull request" against OptimalControl (checked_against: nothing): it is only when the environment runs (label test ModelingToolkit backend, the weekly cron, a change of a ModelingToolkit file).
    • Limits. It does not check that Corleone transcribes the system correctly: that is left to the smoke solves and to the gap to the analytic objective in the cron. A problem with a variable (a free time) is not read yet; in SciML's catalogue a free final time is a time-scaling parameter T that multiplies every dynamics.

    Also, since the preliminary checks

    • Four problems instead of one: vanderpol (Lagrange), robbins (state bound, boundary conditions), jackson (Mayer cost, state and control bounds), besides bryson_denham.
    • The controls start from the initial guess of the problem ([Metadata] Shared initial guess in the metadata, read by every modeling #377). A guess that is a function of time is taken at t0, since the ModelingToolkit interface of Corleone takes one value per control; none of the problems read in SciML's catalogue (bryson_denham, hang_glider, goddarts_rocket) has one that varies. A test checks that the value reaches the parameters of the problem solved.
    • The path constraint is imposed at every node of the grid, the last one included; SciML's benchmarks drop it (constraint_grid[1:end-1]), the terminal conditions fixing it. The effect of dropping it was not measured here.

    Still to decide

    • The first cron results (convergence, time on the default grid, gap to the analytic objective).
    • Write more problems with ModelingToolkit, or not. About thirty problems of SciML's catalogue are candidates, of which cart_pendulum, dielectrophoretic_particle, double_oscillator, ducted_fan, mountain_car (free time, not readable yet), hang_glider and goddarts_rocket are also ours.

    🤖 Generated with Claude Code

  8. added 2 commits that reference this issue on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions