Repository navigation
Description
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/9in 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
- Modeling: entry
ModelingToolkitBackendin the modeling table ([Dev] Per-modeling lists of problems, discovered automatically, with a status per modeling #303); extension triggered by ModelingToolkit only; fileext/ModelingToolkitModels/bryson_denham.jl; status:draftfirst. - Retrieval:
bryson_denham(ModelingToolkitBackend(); parameters=…)returns our genericProblem([Paper] Port to OptimalControl v2 and new problem interface #283);model(pb)is the continuous ModelingToolkit system (with its time span). - 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_benchmarkin SciML's catalogue), solve with Ipopt. - 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, throughpack/reconstructas in Corleone's examples). Check first that this is possible. - Tests (
test/ModelingToolkitenvironment, which also loads Corleone; labeltest 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).
- model verification and contract (
- 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/ModelingToolkitand 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 isx₃(tᵢ) ≥ 0in a variable namedgrid_cons_x₁; the Robbins problem constrainsx₁.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
- Continuous path constraint in the ModelingToolkit system checked (a), or fallback documented.
-
ModelingToolkitBackendin the modeling table;bryson_denhamavailable in it, with our parameters ([Problems] ModelingToolkitBackend, extension ModelingToolkitModels, and continuous bryson_denham (#308) #437); solved with Corleone using our initial guess ([Tests] Corleone solve helper and ModelingToolkit test suite (smoke, reference solution) (#308) #438). - Tests pass in
test/ModelingToolkit(does not break, reference solution); the convergence report shows the gaps; status switched to:valid([Tests] Corleone solve helper and ModelingToolkit test suite (smoke, reference solution) (#308) #438, [Cron/Doc] ModelingToolkit convergence cron, trajectories, and documentation (#308) #439). - Problem page shows the ModelingToolkit tab (get, then solve with Corleone) and results without specific code in the generators ([Cron/Doc] ModelingToolkit convergence cron, trajectories, and documentation (#308) #439).
- Decision in this issue: write more problems with ModelingToolkit or not.
Activity
[-][Problems] Use Corleone's OptimalControlBenchmarks: new problems and cross-check[/-][+][Problems] Proof of concept: one Corleone problem as a third modeling[/+][-][Problems] Proof of concept: one Corleone problem as a third modeling[/-][+][Problems] Proof of concept: a Corleone modeling, with our own bryson_denham[/+][-][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[/+]ocots commentedon Nov 6, 2026
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:J = 4is the analytic objective of the continuous problem, recorded with its source in [Metadata] Declared fields: tags, references, Corleone, reference solution #379. Thereference_objectiveof [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.:validonce the model is equivalent, not once it converges.🤖 Generated with Claude Code
ocots commentedon Nov 8, 2026
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
(a)+(b):ModelingToolkit.System(ext/ModelingToolkitModels/bryson_denham.jl):ModelingToolkit.System(eqs, t; costs, constraints, name)supports continuous symbolic path inequalities depending ont = ModelingToolkit.t_nounits(x₁(t) ≲ x1_max) alongside point constraints (x₁(tf) ~ x1_tf, x₂(tf) ~ x2_tf), with(t0, tf)encoded in theSymbolics.Integral(t in (t0, tf))cost domain. Thereforebryson_denham(ModelingToolkitBackend())needs no grid argument and returns a genuinely continuousProblem.Corleone(test/common/solve_modelingtoolkit.jl):Corleone.CorleoneDynamicOptProblem(sys, ...)requires every signal callx(τ)inModelingToolkit.get_constraints(sys)to have a concrete finite real numberτ(time isa Real && isfinite(time)). InSolveModelingToolkit, any constraint depending oniv = ModelingToolkit.get_iv(sys)is expanded ontoconstraint_gridviaSymbolics.substitute(c, Dict(iv => τ))before callingCorleoneDynamicOptProblem.:init([Metadata] Computed features, reference objective, shared initial guess #306):model = CorleoneDynamicOptProblem(...)stores piecewise-constant control parameters inmodel.ps.parameter.parameters(one.psvector of lengthmodel.ps.initialcondition. Evaluatinginit.controlon thecontrol_gridandinit.stateonshooting_grid(for multiple shooting) populatesps, which is passed toOptimizationProblem(model, AutoForwardDiff(); ps=ps).test_equivalence.jl):Corleone.optimization_objective(model, ps, model.st)andCorleone.optimization_constraints(model, ps, model.st)(bounded bymodel.lconsandmodel.ucons) evaluate the ODE shooting objective and constraint residuals at imposed parameterspswithout solving.Project.toml: weakdepModelingToolkit(compat = "11"), extensionModelingToolkitModels = "ModelingToolkit".test/suite/ModelingToolkit/Project.toml: isolated subprocess environment withModelingToolkit = "11",Corleone = "2",OrdinaryDiffEqTsit5 = "2",Optimization = "5",OptimizationMOI = "1",Ipopt = "1",ComponentArrays = "0.15",ForwardDiff = "1",OptimalControl = "2.2",NLPModelsIpopt = "0.11".docs/make.jlreads precomputed results from theresultsbranch ([Doc] Results pipeline for the documentation, and a gallery of problems #314) and never runsCorleoneat doc-build time.Sub-issues (each leaving
mainin a functional, passing state)ModelingToolkitBackend, extensionModelingToolkitModels, and continuousbryson_denham(:draft)ModelingToolkitModelsweakdep extension,CTModels.Modelscomponent/dimension interface onModelingToolkit.AbstractSystem, continuousbryson_denhammodel,docs/modelings.jladapter, andtest/suite/ModelingToolkit/test_problem.jl.Corleonesolve helper andModelingToolkittest 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 promotingbryson_denhamto:valid.ModelingToolkitconvergence 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 forProblemPlot.vue), enabling Saturday cron in.github/workflows/CronModelingToolkit.yml, and updatingdocs/make.jl,docs/api_reference.jl,ext/README.md, andtest/README.md.ocots commentedon Nov 9, 2026
Part 1 (#437) is merged in #440.
ModelingToolkitBackendis registered inMODELING_SPECSand exported.ModelingToolkitModelsweak-dependency extension providesCTModels.Modelsaccessors forModelingToolkit.AbstractSystem.bryson_denham(ModelingToolkitBackend())returns the continuousProblemwith continuous path constraintx₁(t) ≲ x1_max, integral cost, default parameters, and shared:init.suite/coreandsuite/ModelingToolkittests pass. Documentation builds cleanly.Ready for Part 2 (#438: Corleone solve helper and test suite).
ocots commentedon Nov 11, 2026
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
mainis 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.
test/common/solve_modelingtoolkit.jl. A snippet of a few lines cannot show them without copying them.tspan = (0.0, 1.0)(true forbryson_denhamonly), 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.The results of the cron are drawn on the page as for the other modelings, and
checked_againstisnothing(see 3).2.
test_reference_solutionis removedThe 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
succeededassertion and a relative gap under 5 %), and removed in #444.referenceofTestStatus.result!; a shooting solve has no reference objective of its own discretization, thereference_objectiveof [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.:validonce 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_objectiveandoptimization_constraintsat imposed parameters and compare them with OptimalControl, with a tolerance derived from the grid. What was done instead:suite/ModelingToolkit/test_modelingsreads the ModelingToolkitSystemas the data of a JuMP problem (test/common/continuous_modelingtoolkit.jl) and compares it with the OptimalControl and the scalarized models byContinuous.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.robbins,jacksonandvanderpol, fails exactly the matching check:γthe objective,x₁_landa_uthe state bounds,u_uthe control bounds,k2andεthe dynamics,x₂_t0the boundary conditions.ModelingToolkitenvironment, which therefore loads OptimalControl; thecomparisonenvironment 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 (labeltest ModelingToolkit backend, the weekly cron, a change of a ModelingToolkit file).Tthat multiplies every dynamics.Also, since the preliminary checks
vanderpol(Lagrange),robbins(state bound, boundary conditions),jackson(Mayer cost, state and control bounds), besidesbryson_denham.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.constraint_grid[1:end-1]), the terminal conditions fixing it. The effect of dropping it was not measured here.Still to decide
cart_pendulum,dielectrophoretic_particle,double_oscillator,ducted_fan,mountain_car(free time, not readable yet),hang_gliderandgoddarts_rocketare also ours.🤖 Generated with Claude Code
feat(models): chain in the ModelingToolkit modeling (#308)
feat(models): electric_vehicle in the ModelingToolkit modeling (#308)
test: compare at times that are not all round, merge the one-sided ro…
feat(models): bioreactor in the ModelingToolkit modeling (#308)
Merge pull request #451 from control-toolbox/feat/mtk-more-problems
Merge pull request #452 from control-toolbox/feat/mtk-free-time