Skip to content

feat(models): more problems in the ModelingToolkit modeling (#308) - #451

Merged
ocots merged 7 commits into
mainfrom
feat/mtk-more-problems
Nov 19, 2026
Merged

ocots merged 7 commits into
mainfrom
feat/mtk-more-problems

Conversation

@ocots

@ocots ocots commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Refs #308. Applied conventions: ct-conventions v0.14.0, ct-agents v0.5.0 (the rules added in v0.13 and v0.14 do not concern the files of this pull request).

Writes more of the problems of the collection in the ModelingToolkit modeling, one at a time: each problem is written, tested against the OptimalControl model (continuous comparison, API, smoke solve) and committed before the next one. The decision to write more problems this way is taken in #308 (the reasons for the earlier differences are in this comment).

Method

For each problem:

  1. read the OptimalControl model and the metadata of the problem;
  2. write ext/ModelingToolkitModels/<problem>.jl, in the order of the components of the OptimalControl model (the initial guess is indexed by it), with no initial guess in the file ([Metadata] Shared initial guess in the metadata, read by every modeling #377);
  3. add ModelingToolkit=:valid to its :status (the other metadata are left as they are);
  4. Pkg.test(; test_args=["ModelingToolkit", "problem=<problem>"]) (and core for the metadata);
  5. commit.

Order: first the problems we already have, then the problems of SciML's catalogue we do not have, which will be added to the OptimalControl and JuMP modelings too, later.

Problems

Fixed final time, no variable (the ones the comparison reads today):

  • beam
  • double_oscillator (two states with a free initial value, a force that depends on the time)
  • chain (a Mayer cost)
  • electric_vehicle (states named x and v)
  • bioreactor (initial states free in a box, a light that depends on the time periodically; :valid in OptimalControl and JuMP only)

Free final time or a variable, left to a follow-up pull request, which applies the reduced-time convention tried on mountain_car in #452: balanced_field, brachistochrone, dielectrophoretic_particle, ducted_fan, glider, moonlander, mountain_car, robot, rocket, space_shuttle, steering, insurance, cart_pendulum.

Changes to the tests

  • A state with tunable = true has a free initial value in Corleone: prepare starts it from the state guess of the problem, as it does for the controls (state_start).
  • The equivalence test compares the components in order, not as sets.
  • A blind spot of the continuous comparison, found with bioreactor. The models were evaluated at 0, 25, 50, 75 and 100 % of the interval; the light of bioreactor has a period of 10 on [0, 200], so it was 0 at every point and a wrong light term passed. Two irregular fractions are added (0.137 and 0.618) to test/common/continuous.jl, which suite/comparison/test_modelings uses too. Changing the light of the ModelingToolkit model now fails the dynamics check.
  • The ModelingToolkit reader merges the one-sided rows on the same expression (l ≤ h, h ≤ u) into one two-sided row, as OptimalControl writes l ≤ h ≤ u (the box of the initial state of bioreactor).

Test plan

  • Locally (Julia 1.12): Pkg.test(; test_args=["ModelingToolkit"]): 418 passed on the nine problems (test_methods 41, test_modelings 170, test_problem 198, test_smoke 9); Pkg.test(; test_args=["comparison", "*modelings*"]): 312 passed; core passes.
  • Sensitivity: a wrong bound of the initial box fails boundary, a wrong light fails dynamics.
  • CI with the label test ModelingToolkit backend.

🤖 Generated with Claude Code

ocots and others added 3 commits November 11, 2026 17:56
A bounded state (two path constraints), boundary conditions, a Lagrange cost. Passes the
continuous comparison with OptimalControl and the smoke solve.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nts compared in order (#308)

A state with tunable = true has a free initial value in Corleone: prepare starts it from the
state guess of the problem, as it does for the controls. The initial guess is indexed in the
order of the components of the OptimalControl model, so the equivalence test now compares the
components in order, not as sets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Four states with the last two free at the initial time, a force that depends on the time,
a bounded control. Passes the continuous comparison with OptimalControl and the smoke solve.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ocots ocots added run ci github-runner Trigger the CI workflow on GitHub-hosted runners test ModelingToolkit backend Package-specific scope or cron label labels Nov 11, 2026
ocots and others added 4 commits November 11, 2026 18:11
A Mayer cost and boundary conditions on two of the three states. Passes the continuous
comparison with OptimalControl and the smoke solve.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
States named x and v, a polynomial road, a Lagrange cost. Passes the continuous comparison
with OptimalControl and the smoke solve.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ws on one expression (#308)

The comparison evaluated the models at 0, 25, 50, 75 and 100 % of the interval: for
bioreactor, whose light has a period of 10 on [0, 200], the light was 0 at every point, and a
wrong light term passed. Two irregular fractions are added (0.137, 0.618); changing the light
of the ModelingToolkit model now fails the dynamics check.

The ModelingToolkit reader merges the one-sided rows on the same expression (l <= h, h <= u)
into one two-sided row, as OptimalControl writes l <= h <= u: the box of the initial state of
bioreactor.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A free initial state in a box, a state lower bound, a bounded control, and a light that
depends on the time periodically (floor, ifelse). Passes the continuous comparison with
OptimalControl and the smoke solve; the comparison fails when the light or a bound of the
initial box is changed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ocots
ocots marked this pull request as ready for review November 19, 2026 20:30
@ocots
ocots merged commit eba3d48 into main Nov 19, 2026
15 checks passed
@ocots
ocots deleted the feat/mtk-more-problems branch November 19, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run ci github-runner Trigger the CI workflow on GitHub-hosted runners test ModelingToolkit backend Package-specific scope or cron label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant