Repository navigation
Description
Context and Motivation
Since #368, #369, and #370, JuMP models in ext/JuMPModels/ are no longer transcribed problem by problem:
- Each problem file (
ext/JuMPModels/<problem>.jl) only declares aProblemDatastruct (components, bounds, times, dynamics, Lagrange/Mayer costs, path and boundary constraints) and delegates model construction tobuild. - The transcription itself (
ext/JuMPModels/schemes/:data.jl,tableaux.jl,build.jl) and the solution accessors / builder (ext/JuMPModels.jl:state,control,costate,variable,time_grid,solution) are completely generic.
In #401, test/suite/comparison/test_equivalence.jl was updated to reflect this separation: it checks :trapeze on every problem (to verify that each problem's modeling matches OptimalControl), and checks all schemes on a small subset of problems selected by their features (every_scheme).
However, the rest of test/suite/JuMP/ and test/suite/comparison/ still loops over the Cartesian product all problems × all schemes (× all orderings), running hundreds of redundant JuMP model builds, CTDirect discretizations, and max_iter=0 Ipopt/MadNLP solves that test the generic transcription code over and over instead of testing problem-specific modeling.
Goals
- Unit-test the generic JuMP transcription once (
test/suite/JuMP/):- Test
ButcherTableautraits, scheme equations, convergence orders, variable/constraint orderings (:interleaved,:blocks), the model dictionary contract (:scheme,:ordering,:time_grid,:constraints, container lengths),_start!initial guess loading,JuMP.Modelargument forwarding, and error paths (IncorrectArgument,NotImplemented) on small toyProblemDatadefinitions.
- Test
- Test each problem's modeling once per problem (
test/suite/JuMP/andtest/suite/comparison/):- Verify that each problem's
ProblemData, metadata parameters, and default initial guess are well-formed and consistent on a single default build (without looping over schemes/orderings or launching a solver just to read the initial time grid). - Keep
test_smoke.jl(SMOKE_GRID,SMOKE_MAX_ITER) on every problem so every problem is shown to build and run a few solver iterations. - Verify NLP equivalence with
OptimalControl(CTDirect) on every problem using a single configuration (scheme=:trapeze,ordering=:interleaved), plus component name agreement (state_components,control_components,variable_components).
- Verify that each problem's
- Test transcription & solution integration with
OptimalControl.jlon a representative subset of problems (test/suite/comparison/):- Use feature-based selection (covering cost types, fixed/free times, scalar vs. vector state/control/variable per
DIM1, box/path/boundary constraints) to test all4 schemes × 2 orderingsagainstCTDirectand to testOCP.solution(model, pb)and its interpolations (:linearvs.:constant).
- Use feature-based selection (covering cost types, fixed/free times, scalar vs. vector state/control/variable per
- Preserve
cron/androbustness/behavior while sharing common test runners (test/common/):- Keep
test/cron/andtest/robustness/solving all problems on their default grids and emitting the exact report tables and.tsv/.tomlartifacts expected bytools/cron/report.py. - Factor out duplicated test code across
OptimalControlandOptimalControlScalarized(test_problem.jl,test_smoke.jl,test_convergence.jl) into shared helpers intest/common/, while preservingtools/ci/scope.pydependency detection (Repository.includers).
- Keep
Current State and Redundancies (for $P = 22$ problems)
1. test/suite/JuMP/
-
test_contract.jl:-
Current: Builds
$P \times 4 \text{ schemes} \times 2 \text{ orderings} = 176$ JuMP models, runs Ipopt withmax_iter=0whenevertfis free to evaluatemodel[:time_grid](), and runs$2P = 44$ error checks (scheme=:gauss_legendre_2,ordering=:random). -
Redundancy: Keys like
:scheme,:ordering,:constraints, container sizes ($N+1$ ,$N$ ,$M$ ), and unknown scheme/ordering errors are determined solely byschemes/build.jl, not by<problem>.jl.
-
Current: Builds
-
test_kwargs.jl:-
Current: Builds
$3P = 66$ JuMP models to verify thatIpopt.Optimizerandadd_bridges=trueare forwarded toJuMP.Modeland that passinginit = 2 * guessdoublesJuMP.start_value. -
Redundancy: Keyword forwarding and
_start!are generic functions inschemes/build.jl. Only checking that the problem's default metadatainitpopulates all start values is problem-specific.
-
Current: Builds
-
test_tableaux.jl,test_build.jl,test_signs.jl,test_draft.jl,test_methods.jl,test_smoke.jl:- Already targeted and non-redundant.
2. test/suite/comparison/
-
test_equivalence.jl&test/common/equivalence.jl:-
Current: Tests
:trapezeon every problem and all 4 schemes onselected = every_scheme(both, features). However,Equivalence.test_jumpstill loops over bothORDERINGS = (:interleaved, :blocks)for every problem, even though:blocksonly permutes variable/constraint creation order inschemes/build.jl.
-
Current: Tests
-
test_start.jl:-
Current: Loops over
$P \times 4 \text{ schemes} = 88$ pairs, building the JuMP model and callingOptimalControl.discretize+OptimalControl.nlp_model(..., ADNLP())to compareJuMP.start_valuewithnlp.meta.x0. -
Redundancy:
Equivalence.compareandconsistent_nlpsintest_equivalence.jlalready comparemeta.x0(:x0) on every problem for:trapezeand on the representative subset for all 4 schemes.
-
Current: Loops over
-
test_init.jl(test/common/comparison.jl):-
Current: Runs Ipopt/MadNLP with
max_iter=0onSMALL_GRID = 50for every problem acrossJuMP,OptimalControl, andOptimalControlScalarized($3P = 66$ solves) to comparenvar,ncon, component names, time grid, initial trajectories, and initial objective. -
Redundancy:
test_equivalence.jlalready checksnvar,ncon, bounds,x0, objective, constraints, gradient, Jacobian, and Hessian atx0to1e-10without invoking any solver. Only the component names (state_components,control_components,variable_components) are specific totest_init.jl, and they can be compared directly on the models without solving.
-
Current: Runs Ipopt/MadNLP with
-
test_solution.jl:-
Current: Loops over
$P \times 4 \text{ schemes} = 88$ JuMP models onSMALL_GRID = 50, running Ipopt withmax_iter=0on each to check thatOCP.solution(model, pb)andTestStatus.trajectorymatch the JuMP accessors, plus a full solve onbeamfor the 4 schemes. -
Redundancy:
OCP.solution(model, pb)and the JuMP accessors inext/JuMPModels.jlare completely generic. Testing them on a representative subset of problems (covering scalar vs. vector state/control and$0, 1, >1$ variables) across the 4 schemes is sufficient.
-
Current: Loops over
3. Duplicated files across OptimalControl and OptimalControlScalarized
test/suite/OptimalControl/test_problem.jlandtest/suite/OptimalControlScalarized/test_problem.jlare identical except for the backend constant.test/suite/OptimalControl/test_smoke.jlandtest/suite/OptimalControlScalarized/test_smoke.jlare identical except for the backend constant.test/cron/OptimalControl/test_convergence.jlandtest/cron/OptimalControlScalarized/test_convergence.jlare identical except for the backend constant.
Proposed Solutions
1. Move generic contract and _start! checks to test/suite/JuMP/test_build.jl
- In
test_build.jl:- Check the full model dictionary contract (
:scheme,:ordering,:time_grid,:constraints, component keys and container lengths$N+1$ ,$M$ ,$N$ ,$1$ ) across all4 schemes × 2 orderingsonFAKE, plus theIncorrectArgumentthrows on unknownschemeandordering. - Unit-test
_start!(constant, vector, time-dependent function, custominitoverride, free final time) andJuMP.Modelargument/keyword forwarding (Ipopt.Optimizer,add_bridges).
- Check the full model dictionary contract (
- Simplify
test_contract.jl(or mergetest_kwargs.jlinto it):- Build one model per problem (
grid_size=2, default:trapezeand:interleaved). - Check problem-specific modeling invariants: non-empty component names,
length(costate_components) == length(state_components), all variables have a finiteJuMP.start_value, and the initial time grid evaluated at the start values is sorted withT[1] < T[end](no Ipoptmax_iter=0call needed).
- Build one model per problem (
2. Streamline test/suite/comparison/
-
Shared representative problem selector:
- Extract the feature-based representative problem selection (
every_schemeintest_equivalence.jl, extended if needed to ensure scalar/vector state, control, and variable dimensions0, 1, >1are covered) into a shared helper intest/common/.
- Extract the feature-based representative problem selection (
-
test_equivalence.jl&test/common/equivalence.jl:- On every problem: test
(scheme=:trapeze, ordering=:interleaved)againstCTDirect(ADNLPandExa), which directly checks problem modeling equivalence (includingmeta.x0). - On the representative subset: test all
4 schemes × 2 orderings.
- On every problem: test
-
test_features.jl:- In addition to comparing
features(vector) == features(scalarized), check that component names (state_components,control_components,variable_components) and dimensions agree betweenJuMP,OptimalControl, andOptimalControlScalarizedfor every problem (no solver call).
- In addition to comparing
-
test_start.jlandtest_init.jl:- Remove
test_start.jl(sincemeta.x0equivalence is already checked bytest_equivalence.jlon every problem for:trapezeand on the representative subset for all 4 schemes, and_start!is unit-tested intest_build.jl). - Remove
test_init.jl(since NLP evaluation atx0is checked to1e-10bytest_equivalence.jland component names are checked bytest_features.jl). KeepComparison.within/Comparison.within_L2(used bytest_solution.jl).
- Remove
-
test_solution.jl:- Run
check_solution(problem, scheme)across the 4 schemes on the representative subset of problems (plusbeamsolved againstOptimalControl), instead of all$P \times 4$ pairs.
- Run
3. Factorize shared OptimalControl / OptimalControlScalarized runners
- Extract shared helpers in
test/common/fortest_problem,test_smoke, andtest_convergencesoOptimalControlandOptimalControlScalarizedcall a single implementation parameterized by the backend, without altering report names,TestStatus.result!payloads, ortools/ci/scope.pyscoping rules.
Activity
ocots commentedon Nov 10, 2026
Plan: rationalize the JuMP and comparison test suites (#441)
Conventions: ct-conventions v0.11.0 (commit d164eca) · ct-agents v0.4.0 (commit 61e5e5c)
Written against
mainat bc71791. Nothing is implemented yet: this comment is the plan, to be confirmed by the maintainer before any code (see "Decisions to confirm").What and why
The JuMP transcription (
ext/JuMPModels/schemes/) and the accessors are generic since #368–#370, buttest/suite/JuMP/andtest/suite/comparison/still run the product problems × schemes (× orderings), which tests the same generic code hundreds of times. This plan tests the generic code once on fakeProblemData, each problem once, and the integration with OptimalControl on a subset chosen by features. It also removes the three files duplicated betweenOptimalControlandOptimalControlScalarized.Test code only, except one optional three-line change in
ext/JuMPModels/schemes/build.jl(decision D1).Decisions to confirm (⛔ before coding)
model[:time_grid]()callsJuMP.value, which throwsOptimizeNotCalledwhen the final time is free, and the problem'stimesfunction is not reachable from the model.model[:time_grid] = (value=JuMP.value) -> …, so a test callsmodel[:time_grid](JuMP.start_value).time_grid(model)is unchanged. Alternative with no source change: keep themax_iter=0solve, on one model per problem and only when the grid is not available.ext/JuMPModels/<problem>.jlforwardsscheme,ordering,args...,initandkwargs...tobuildby hand. With one default build, a problem file that drops one of them is no longer caught (todaytest_contractandtest_kwargscatch it on every problem).grid_size=2: the default one, and one with every argument non-default. 44 tiny builds instead of 286.test_solutionmust loop over the representative subset only.TestStatus.for_each_problemhas no filter; returning early in the closure writes ano testline per skipped problem in the report.only=nothingtofor_each_problem(test/common/status.jl).status.jlis named byruntests.jl, so the PR runs every environment once.Scope
ext/JuMPModels/schemes/build.jl(D1).contract,kwargs,test_start,test_initoftest/reports/{JuMP,comparison}.mdare replaced (see below). The cron and robustness reports,.tsvand.tomlfiles are unchanged, byte for byte in their test names and columns.What changes
test/suite/JuMP/test_build.jl_start!unit tests, +JuMP.Modelforwarding, + unknown schemetest/suite/JuMP/test_contract.jltest/suite/JuMP/test_kwargs.jltest_contract.jltest/common/representative.jltest_equivalence.jland extendedtest/common/equivalence.jltest_jumpandtest_problemtake the orderingstest/suite/comparison/test_equivalence.jl:trapeze,:interleaved; subset: 4 schemes × 2 orderingstest/suite/comparison/test_features.jltest/suite/comparison/test_start.jltest/suite/comparison/test_init.jltest/common/comparison.jltest_solution.jlusestest/suite/comparison/test_solution.jlcheck_solutionon the subset × 4 schemestest/common/status.jlfor_each_problem(...; only=nothing)(D3)test/common/optimalcontrol_tests.jltest_problem,test_smoke,test_convergenceparameterized by the backendtest/suite/{OptimalControl,OptimalControlScalarized}/test_{problem,smoke}.jl,test/cron/{…}/test_convergence.jltest/common/configs.jl,test/README.md,CHANGELOG.mdNo behaviour change of the package. Test coverage of the generic code is kept (moved to fakes); per-problem coverage is kept for what is written per problem.
Step 0 — Branch and baseline
git checkout main && git pull git checkout -b test/441-rationalize-jump-comparison-testsBefore any edit, record the baseline: run
["JuMP"]and["comparison"](ct-dev-mcpget_test_command, thengenerate_report), keep both logs, and note the wall time and the number of tests of each test file. The same numbers are reported at the end, in the PR body.Phase A —
test/suite/JuMP/: generic tests on fakes, one check per problemRules:
TST1,TST3(fakes at module top-level),TST4(unit / contract / error sections),TST5,TST7,EXC5.(D1, if accepted)
ext/JuMPModels/schemes/build.jl:Check the other uses of
_valueinext/first, and thatJuMP.value(f, x)accepts both aVariableRefand an expression (a free time may be either).test_build.jl— add a second fake next toFAKE,EXACT,LINEAR, with a vector state and control, so that the 1-D and n-D cases are both covered (DIM1):test_build.jl— new functiontest_contract_generic()(moved fromtest_contract.jl), fordata in (FAKE, EXACT, VECTOR), 4 schemes × 2 orderings,N = 3:model[:scheme] === scheme,model[:ordering] === ordering,model[:time_grid] isa Function;*_componentskeys areVector{String}, each name resolves inJuMP.object_dictionary(model);N + 1, controlN + 1for:trapezeandNotherwise (written by hand, asSCHEMESin the currenttest_contract.jl), costateN, variable1;length(model[:constraints]) == JuMP.num_constraints(model; count_variable_in_set_constraints=false);EXACT)collect(model[:time_grid]()) == [0, 1/3, 2/3, 1]; free final time (FAKEwithinit=(variable=1.5,)) evaluated at the start values (D1).test_build.jl— new functiontest_start(), unit tests of_start!throughEXT.build(...; init=...)andJuMP.start_value, onFAKEandVECTOR,N = 2, for the 4 schemes:init: every start value isnothing;init=(state=t -> …, control=t -> …, variable=…), expected values written by hand ont(i) = i * tf / Nwithtfthe guess of the variable (free final time), and onMcontrols (N + 1for:trapeze,Notherwise);:blocksgives the same start value to the same variable name as:interleaved.test_build.jl— new functiontest_forwarding():EXT.build(FAKE, 2, :trapeze, :interleaved, Ipopt.Optimizer; add_bridges=false)givesJuMP.solver_name(model) == "Ipopt"andJuMP.bridge_constraints(model) == false;truewith the default. (using Ipopt: Ipopt, already intest/suite/JuMP/Project.toml.)test_build.jl— error section:Test.@test_throws CTBase.Exceptions.IncorrectArgument EXT.build(LINEAR, 2, :gauss_legendre_2, :interleaved)next to the existing unknown-ordering test.NotImplementedstays intest_tableaux.jl.test_contract.jl— rewrite as the per-problem check; remove thesolve_jump.jlinclude if D1 is accepted. Shape:The start-value comparison of
test_kwargs.jlmatches variables by name, since the two builds differ in scheme and grid: build thedoubledcomparison at the samegrid_sizeand scheme if matching by name is not straightforward (then use a third build, or compare:trapezeto:trapeze). Keep the report name"contract".Delete
test_kwargs.jl(⛔ ask before deleting).Mutation checks (README rule "every check you add must be shown to fail"): temporarily break, one at a time, and see the named test fail — drop
orderingin one problem file's call tobuild; dropinit=initin one problem file; setM = Nfor the trapezoidal rule inbuild; skip the control loop in_start!. Revert each. List them in the PR body.Checkpoint:
Phase B —
test/suite/comparison/New
test/common/representative.jl, moduleRepresentative(guarded include, as the other common files). MovePROPERTIES,coveredandevery_scheme(renamedselect) fromtest_equivalence.jl, and add the dimension cases:plus
selection()returning(problems, features, selected)forOCP.problems(OCP.JuMPBackend(), OCP.OptimalControlBackend()). No problem name is written (README rule 3,core/test_consistency.jl). The selection is made on the whole catalogue, not onproblem=, as today.test/common/equivalence.jl:test_jump(problem, scheme, ref, orderings)andtest_problem(problem, schemes, orderings);test_exaunchanged (it does not depend on the ordering). Update the header comment.test_equivalence.jl: includerepresentative.jl; keepTest.@test covered(selected, features) == covered(both, features)and the@infoline; calltest_features.jl: keep the vector vs scalarized feature check (report nametest_features); add a loop per pair (JuMP, OptimalControl) and (JuMP, OptimalControlScalarized), report nametest_components, with no solve:OCP.state_components,control_components,variable_componentsand the three*_dimensionof the JuMP model (grid_size=2) equal those ofOCP.model(pb).test/common/status.jl(D3):for_each_problem(f, test, backends...; only=nothing), which keeps the problems ofonlywhen it is given; add its case totest/suite/core/test_status.jl.test_solution.jl: includerepresentative.jl; loopfor_each_problem("test_solution", jump, oc; only=selected)over the 4 schemes; keep theerrorstestset and the solvedbeamtestset as they are.Delete
test_start.jlandtest_init.jl(⛔ ask before deleting). Before deletingtest_init.jl, confirm on the baseline log that nothing it checks is lost:nvar,ncon,x0, objective and constraints atx0are inEquivalence.compare(JuMP vs CTDirect, and scalarized vs vector bytest_scalarized); the names are in step 4.test/common/comparison.jl: removeData,vec1,from_solution, bothsolvemethods,for_each_comparison,check,compare_*,REFERENCE,OTHERSand the tolerances no longer used (GRID,CONTROL,VARIABLE); keepL2_norm,within,within_L2,OBJECTIVE,STATE,COSTATEand the two includes (test_solution.jlusesMain.SolveJuMPandMain.SolveOptimalControl). Rewrite the header comment.test/common/configs.jl: the comment ofSMALL_GRID(now the grid oftest_solutiononly).Mutation checks: change one component name in one JuMP problem file (
test_componentsfails); change a sign in the dynamics of a problem outside the subset (NLP equivalencefails on:trapeze); swap two pieces in_in_orderfor:blocks(fails on the subset and intest_build.jl). Revert each.Checkpoint:
The fixtures of
tools/ci/test/test_scope.pyandtools/cron/test/test_report.pywrite their owntest_init.jlin a temporary repository: they do not depend on the deleted file. Check it rather than assume it.Phase C — shared runners for OptimalControl and OptimalControlScalarized
New
test/common/optimalcontrol_tests.jl: guarded include ofsolve_optimalcontrol.jl, then moduleOptimalControlTestswithtest_problem(backend),test_smoke(backend),test_convergence(backend)and the helperchanged(params). The backend gives everything that differs today:Testset titles, report names (
"problem","test_smoke <label>","test_convergence <label>") and the arguments ofTestStatus.result!are copied unchanged.The six files become wrappers, still one module and one entry function each (
TST1):The file name must appear as the literal
"optimalcontrol_tests.jl":Repository.includersoftools/ci/scope.pyfinds includers by that string, transitively throughtest/common/.tools/ci/test/test_scope.py: add a case showing that a change of the shared runner is scoped toOptimalControlandOptimalControlScalarized(fixture: two suite files naming it), in the style of the existingsolve_jump.jlcase.Check that the reports are unchanged: run the cron mode on one problem before (on
main) and after, and compare the test names and the header of the files.Phase D — documentation and full run
test/README.md: "Three kinds of tests" (item 1:test_kwargsis gone, whattest_contractnow checks; item 2: every problem with one configuration, every scheme and ordering on the subset), "What is compared, and what is not" (no more zero-iteration comparison: names intest_features, NLP intest_equivalence), and a sentence on the shared runner under "Adding a test". Fix what markdownlint reports in the touched sections (GEN2).CHANGELOG.md: one entry under[Unreleased](CHG2), or the labelno changelog— the maintainer chooses.Full suite (last phase only), then the baseline comparison of Step 0:
PR body: the before/after table (wall time and number of tests per file, JuMP and comparison), the mutation checks done, the decisions D1–D4 as applied, and the versions of the conventions. Labels:
run ci github-runner;test convergencebecausetest/cron/changes (README, "When to addtest convergence").Expected order of magnitude, for 22 problems: JuMP models built by
test_contract+test_kwargs286 → 44;test_start88 discretizations → 0;test_initabout 88 zero-iteration solves → 0;test_solution88 zero-iteration solves → 4 per selected problem;:blocksequivalence on every problem → on the subset only.Human checkpoints
test_kwargs.jl,test_start.jl,test_init.jl.Out of scope
test/suite/GPU/test_smoke_{optimalcontrol,scalarized}.jl: duplicated in the same way, but opt-in and with theTST6skip; a follow-up can give the sharedtest_smokeaconfigsargument.test/robustness/(only OptimalControl and JuMP exist; nothing duplicated) andtest/cron/JuMP/.beamandglideralready written intest_solution.jl.ModelingToolkittests,tools/cron/report.py, the workflows.File summary
Added:
test/common/representative.jl,test/common/optimalcontrol_tests.jlModified:
test/suite/JuMP/test_build.jl,test/suite/JuMP/test_contract.jl,test/common/equivalence.jl,test/common/comparison.jl,test/common/status.jl,test/common/configs.jl,test/suite/comparison/test_equivalence.jl,test/suite/comparison/test_features.jl,test/suite/comparison/test_solution.jl,test/suite/core/test_status.jl,test/suite/OptimalControl/test_problem.jl,test/suite/OptimalControl/test_smoke.jl,test/suite/OptimalControlScalarized/test_problem.jl,test/suite/OptimalControlScalarized/test_smoke.jl,test/cron/OptimalControl/test_convergence.jl,test/cron/OptimalControlScalarized/test_convergence.jl,tools/ci/test/test_scope.py,test/README.md,CHANGELOG.md, andext/JuMPModels/schemes/build.jlif D1 is acceptedDeleted:
test/suite/JuMP/test_kwargs.jl,test/suite/comparison/test_start.jl,test/suite/comparison/test_init.jlocots commentedon Nov 10, 2026
Addendum to the plan: a closing summary of what is tested
D1–D4 of the plan above are confirmed by the maintainer (D1:
time_gridtakes a value function; D2: two builds per problem; D3:only=infor_each_problem; D4: one PR, one commit per phase). The GPU follow-up is #445.One more deliverable, in Phase D, written once the tests are finished so that it describes what is really tested and not what was planned:
test/README.md(replacing the description of the three kinds of tests where needed), andIt must state the philosophy in a few lines:
1e-10, on one configuration::trapeze,:interleaved) and every problem builds and runs a few iterations (test_smoke).ProblemData(suite/JuMP/test_build.jl), and against CTDirect on a small representative subset of problems chosen by their features (cost type, free/fixed times, scalar/vector state, control and variable, box/path/boundary constraints), for all 4 schemes × 2 orderings (test_equivalence,test_solution). Running problems × schemes × orderings would test the same generic code again without testing any more modeling.cron/androbustness/are unchanged.test_build.jlis an error of the generic transcription.Include in it the before/after table (wall time and number of tests per file, JuMP and comparison) measured against the baseline of Step 0.
ocots commentedon Nov 10, 2026
Revised plan (phase E) and audit of the suite
Conventions: ct-conventions v0.11.0 (commit d164eca) · ct-agents v0.4.0 (commit 61e5e5c).
Phases A–D of the first plan are done on
test/441-rationalize-jump-comparison-tests(commits 2e15e85, 14e8723, 242687b, 22476df; nothing pushed). Measuring the result showed that the comparison environment is still slow (25 min) and, more importantly, that it does not follow the intent of the maintainer, which I had misread by following the text of the issue literally. This comment states the intent, audits what the suite does, and replaces the second half of the plan.The intent (maintainer, confirmed)
initial_guess_dataof the metadata), so it needs no test of its own beyond the existing ones (test_contractfor JuMP,test_problemfor OptimalControl).Why the current comparison is slow (measured, not assumed)
Measured with
scratchpad/profile_equiv*.jlonbeamandrobot, first call of each step, compilation is 99–100 % of the time (the NLPs are tiny, grid 4):beamrobotdiscretize+ ADNLP + ExaMathOptNLPModel,compare)test_exa)test_scalarized)NLPModelsTest.consistent_nlpscosts about nothing once compiled (0.0 s onrobotafterbeam). The cost is the compilation of OptimalControl's discretization and NLP builders for each problem, andtest_scalarizedis the largest part (about three quarters onbeam). Each environment runs in its own Julia process, so this compilation is paid again incomparisonafterOptimalControl'stest_smoke(which discretizes and solves every problem with ADNLP and with Exa).Audit of the suite (final run of the branch)
Times are those of the full run on the branch. "Keep" is my judgment; the items marked ? are for the maintainer.
core (in-process, about 45 s, 24 s of it
test_discovery_cache)test_aquatest_consistencytest_discovery_cachetest_modelings,test_modules,test_parameters,test_references,test_runner,test_statusJuMP (33 s)
test_build_start!, argument forwarding, time gridtest_tableauxtest_contractbuildtest_methods,test_drafttest_signstest_smokeOptimalControl (9 min) and OptimalControlScalarized (5 min)
test_featuresfeatures(problem)agrees with the modeltest_problemProblemAPI, metadata, parameters, initial guess, display (shared since #441)test_methodstest_reference_solutiontest_smokecomparisonpays again (? a lighter PR run, for instance one modeler, belongs in a separate issue)comparison (25 min) — what changes
test_equivalence, JuMP vs CTDirect,:trapeze/:interleaved, every problemx0, objective, constraints, Jacobian, Hessiantest_equivalence, 4 schemes × 2 orderings, subsettest_equivalence, Exa vs ADNLP, every problemtest_scalarized(every problem, 29–56 s each)test_nonzerosNLPModelsJuMPquirk (nnzhcounts repeated entries) on every problemtest_featurestest_solutionOCP.solution(model, pb)and interpolations, subset × 4 schemes, plus a solvedbeamRemoved since the baseline:
test_kwargs(merged),test_start,test_init(their checks are intest_equivalence,test_featuresandtest_build).New checks to add (phase E)
E2 —
suite/comparison/test_modelings.jl: the continuous comparison, every problem, no discretization. New helpertest/common/continuous.jl(moduleContinuous), deterministic sample points, for the pair JuMP–OptimalControl and the pair OptimalControl–OptimalControlScalarized:t0,tf(JuMP:data.times(v); OptimalControl:initial_time,final_time, accounting for a free time that is a component of the variable);data.dynamics(x, u, v, t); OptimalControlCTModels.dynamics(ocp)), at several(t, x, u, v);data.lagrange,data.cost;lagrange(ocp),mayer(ocp)), noting the sense of the criterion;Equivalence.signaturesdoes (their order is not guaranteed), with their bounds(lb, f, ub);state_constraints_box,control_constraints_box,variable_constraints_boxagainstComponent.lower/upper).Scalar versus vector (
DIM1):ProblemDatafunctions take vectors, a one-dimensional state or control of OptimalControl is a scalar; the helper adapts.The scalarized model is compared with the vector one in the same way, nothing is discretized.
E1 — one line in
schemes/build.jl:model[:problem_data] = data, so the test reaches the continuous functions of a JuMP problem (they are today local to each problem file). Document the key intest_build(model dictionary).Open points the spike must settle: the exact signatures of the in-place constraints of CTModels (
f!(val, t, x, u, v)), bounds given as vectors over the nodes inComponent(compare at the nodes, or skip with a report), problems whose criterion is:max, and the domain of the functions (log, sqrt: sample around the initial guess, not at arbitrary points).Revised steps
test_jump+test_scalarized.model[:problem_data] = datainbuild; updatetest_build.test/common/continuous.jlandsuite/comparison/test_modelings.jlon every problem, vector and scalarized.test_equivalence: JuMP vs CTDirect only on the representative subset (4 schemes × 2 orderings); deletetest_scalarized; Exa vs ADNLP andtest_nonzerosas decided.test/README.md(philosophy),CHANGELOG.md, full run, before/after table, the closing summary comment on the PR.The scope rules (
tools/ci/scope.py) need nothing new:test/common/continuous.jlis found as an includer throughtest_modelings.jl. Add a case totools/ci/test/test_scope.pyas in phase C.Decisions to confirm
test_nonzeros: one problem, or drop.ocots commentedon Nov 10, 2026
Status report (bilan) and handoff — supersedes the plan and the goals above where they differ
Conventions: ct-conventions v0.11.0 · ct-agents v0.4.0. Branch
test/441-rationalize-jump-comparison-tests(4 commits, not pushed, no PR yet), based onmainat bc71791.In one paragraph. The generic JuMP transcription is now unit-tested once (fake problems), each JuMP problem file is checked on small models, and the two OptimalControl modelings share one test implementation. The comparison environment still takes 25 min because it discretizes every problem with CTDirect, which is mostly compilation. The maintainer's intent is different from the literal text of this issue: modelings are compared at the continuous level, on every problem, without discretizing; the discretization is compared with CTDirect only on a few representative problems. A spike shows this is feasible and cheap (41 comparisons in 31 s, all equal, mutations detected). What remains is to implement it, move the all-problem NLP comparison to a cron, and write the closing summary.
1. The intent (confirmed by the maintainer; this replaces goals 2 and 3 of the issue)
initial_guess_data), no dedicated test beyondtest_contract(JuMP) andtest_problem(OptimalControl).tools/ci/scope.py, [CI] Test only what a pull request changes: environments and problems; labels only add #405; labelstest <env> backend,test comparison,test all problems,test everything,test convergenceonly add), so per-problem costs do not hit every PR.2. What is done on the branch
suite/JuMP:test_build(fake problems, scalar and vector: model dictionary for 4 schemes × 2 orderings,_start!,JuMP.Modelargument forwarding, time grid, errors);test_contract(per problem, no solver, 3 small builds: components, finite default start values, initial time grid read at the start values, every argument forwarded tobuild);test_kwargsremoved.model[:time_grid]takes an optional function giving the value of a variable (model[:time_grid](JuMP.start_value)works before any solve, also with a free time).suite/comparison:common/representative.jl(fewest problems that have every property the generic code treats differently, computed from the features:balanced_field,insurance,beam,cart_pendulum,ducted_fan);test_equivalencewith trapeze/interleaved for every problem and all schemes and orderings on the subset;test_features(+ components and dimensions JuMP vs OptimalControl vs Scalarized);test_solutionon the subset (for_each_problem(...; only=));test_start,test_initremoved;comparison.jlreduced.common/optimalcontrol_tests.jl:test_problem,test_smoke,test_convergencewritten once, parameterized by the backend; the six files are thin wrappers (TST1). Test names, report lines and cron results unchanged (checked onbeam: reports identical, results identical but the time). Scope case added totools/ci/test/test_scope.py.test/README.md(philosophy),CHANGELOG.md.Uncommitted: one line in
ext/JuMPModels/schemes/build.jl,model[:problem_data] = data(see §4).Measured (full run of the branch against the baseline on
main; single runs, timings vary by machine load: the equivalence took 25 min in the full run and 35.6 min in a filtered run):test_equivalencetest_solutiontest_start+test_initAll green: full suite,
core, Python tools tests. Mutation checks done (each shown to fail, then reverted):beamignoresordering;beamdropsinit; trapezoidal rule withNcontrols;_start!skips the controls; a component renamed; a wrong sign invanderpol(outside the subset);:blocksorder reversed.3. Why the comparison is still slow: measured, and what it changes
Measured on
beamandrobot(first call of each step, tiny NLPs): 99–100 % compilation. CTDirectdiscretize+ ADNLP + Exa per problem 4.5–10.8 s; the JuMP side 2.2–21.7 s; Exa vs ADNLP 2.1–4.9 s;test_scalarized29–56 s per problem.consistent_nlpscosts nothing once compiled. Each environment runs in its own Julia process, so the compilation of OptimalControl's discretization is paid again incomparisonafterOptimalControl'stest_smoke. Conclusion: comparing NLPs on every problem is what costs; compare the continuous models instead.4. Spike E0 (done): the continuous comparison is feasible and cheap
Prototype below. For every problem and for both OptimalControl modelings it compares, with the JuMP
ProblemData(reached throughmodel[:problem_data], a one-line change inbuild): times, dynamics, Lagrange integrand, Mayer cost, path and boundary constraints, box bounds of the state, control and variable. Points come from the initial guess (domain-safe: the smoke solves start there), with small deterministic perturbations.Result: 22 problems vs OptimalControl and 19 vs OptimalControlScalarized (drafts included), all equal, 30.6 s in total (0.2–1.4 s per problem,
balanced_field4.7 s with compilation), against 30–90 s per problem for the NLP route. Mutations are detected: a sign in the dynamics ofvanderpol→dynamics; the upper bound ofx₁doubled inbeam→state_box.What the spike taught (keep in the implementation):
dynamics,lagrange,mayer,criterion,path_constraints_nl,boundary_constraints_nl,state/control/variable_constraints_box,initial_time,final_time). Dynamics and constraints are in place:D(r, t, x, u, v), pathf!(r, t, x, u, v), boundaryf!(r, x0, xf, v). A fixed time is read withinitial_time(ocp), a free one withinitial_time(ocp, v)(usehas_fixed_initial_time,has_fixed_final_time). Vectors are accepted for 1-D controls.data.cost(I, x0, xf, v), linear in the integralIof its Lagrange integrand; some problems havecost = -Ior a scale (insurance: integrand of opposite sign;ducted_fan: factor 2/3). Comparesign · lagrange_OCwithw · data.lagrange, wherew = cost(1) − cost(0)andsignfollowscriterion(:min→ 1,:max→ −1); the Mayer part iscost(0, x0, xf, v)againstsign · mayer.a == b ||:Inf - InfisNaN.Componentbound given as a vector): the helper reports it as different if one appears.(x0, xf)pair; the implementation should use several.OCP.problems(...; status=:all)includes the drafts;Main.TestStatus.for_each_problemhandles their status.Prototype (to become
test/common/continuous.jl, TST1/TST2 style, no problem name written)5. Decisions
model[:time_grid]takes an optional value function. Done.test_contractbuilds small models per problem to check what the problem file forwards (three builds instead of two). Done.TestStatus.for_each_problem(...; only=). Done.test_nonzerosremoved (guard on a quirk of NLPModelsJuMP, no use here).comparison: the NLP comparison JuMP vs OptimalControl (ADNLP), trapeze/interleaved, every problem (discretization without solver:discretize+nlp_model,MathOptNLPModel, then NLPModelsobj,grad,cons,jac,hesscompared to 1e-10; this is the existingEquivalence).To confirm: with D9 limited to JuMP vs OptimalControl, Exa vs ADNLP (a property of OptimalControl, known gap #284) and the scalarized NLP comparison are tested nowhere: the Exa modeler is still exercised by the smoke solves, and the scalarized model by the continuous comparison. Say so if either should go in the cron.
6. Remaining work (phase E), in order
model[:problem_data] = datainschemes/build.jl; add the key to the model-dictionary test intest_build.jl;CHANGELOG.mdline.test/common/continuous.jl(from the prototype: several(x0, xf)pairs for the boundary, a docstring per function, errors reported with the failing key, not a barefalse) andtest/suite/comparison/test_modelings.jl:for_each_problemfor the pairs (JuMP, OptimalControl) and (JuMP, OptimalControlScalarized), oneTest.@testper key; report nametest_modelings. Cheap (about 30 s for all).test_equivalence.jl: only the representative subset, JuMP vs ADNLP, 4 schemes × 2 orderings; removetest_exa,test_scalarized,test_nonzerosand the Exa/scalarized helpers fromcommon/equivalence.jl(keepEquivalence.test_jump,PermutedNLP,compare,reference). ⛔ ask before deleting.comparison:test/cron/comparison/test_equivalence.jlrunningEquivalenceon every problem (it runs in the environment ofsuite/comparison/); a workflow.github/workflows/CronComparison.ymlmodeled onCronJuMP.yml(cron-reusable.yml, a free weekday, for instance Friday 4 h); a scope intools/cron/report.pyand its test (test_initial_issue_body_prepopulates_all_known_scopes). Check first how the reusable workflow and the report treat a failing test: the convergence crons report and never fail, whereas this one must fail on a difference.test/README.md(rewrite "What is compared, and what is not" with the final scheme: continuous comparison for every problem, discretization on the subset, NLP comparison in the cron),CHANGELOG.md,tools/ci/test/test_scope.pycase if needed, full run, before/after table.test/README.md: what is tested, by whom, why (the four-point philosophy of §1), where a failure points (one problem → its modeling; subset ortest_build→ the transcription; cron → the NLP), and the numbers.7. Handoff notes
ct-dev-mcp(get_test_command, thengenerate_report), orjulia --project -e 'using Pkg; Pkg.test(; test_args=[...])' 2>&1 | tee /tmp/<log>. Useful scopes:["JuMP"],["comparison","features"],["core"],["OptimalControl","OptimalControlScalarized","problem=beam"], add"cron"for the cron files. Intermediate phases never run the full suite.test/suite/<env>/Project.tomlin a temporary directory; to run a script against the checkout, copy thatProject.tomlto a scratch directory,Pkg.develop(path=<repo>),Pkg.instantiate(), thenjulia --project=<scratch> script.jl.src/,test/or the extension files (core/test_consistency): select problems from the catalogue or the features.docs/was modified before this work and is in no commit.ocots commentedon Nov 10, 2026
Addendum to the status report: three clarifications from the maintainer
1. The objective is compared, not its decomposition.
insuranceandducted_fanare the same problem in both modelings, written with the same formula: OptimalControl writes-∫(U(t) * fx) → minand(1 / tf) * ∫(…) + μ tf → min; the OptimalControl parser puts the sign and the factor1/tfinside the Lagrange integrand, whereas the JuMPProblemDatakeepscost(I, x0, xf, v) = -Iand(1/v[1]) * I + μ v[1]around the integral. No problem file needs to change. The continuous check therefore compares the objective on the same sampled trajectories, with the same quadratureQ(trapezoidal rule on the sample times) on both sides, and no weightw:for several trajectories (the initial guess plus perturbations of different sizes, since the objective is not affine). This replaces the
w · lagrangecomparison of the previous comment (§4).2. What
OptimalControlProblems.jlguarantees, and what it does not. The package guarantees that the user solves the same problem with every modeling it provides (JuMP, OptimalControl, OptimalControlScalarized), and that its own JuMP discretization is CTDirect's. It does not test OptimalControl itself. So, decision D9 is revised:suite/JuMP/test_build.jl,test_tableaux.jl,common/equivalence.jl,common/representative.jlfor the schemes, the croncomparison): say so in a header comment and intest/README.md, so that the day it is released as a package these tests are deleted, not maintained.3. The cron fails on a difference. Convergence is reported and not tested because it depends on the platform (several local solutions). The NLP comparison is deterministic (no solver, no platform dependence), so a difference is a real defect, and a cron that never fails would tell nobody that the JuMP model drifted from OptimalControl's. What I verified in
tools/cron/report.pyandcron-reusable.yml: a row with outcomefailorerroris a failure finding (cron-failurelabel) and the workflow runsreport.py --tests-failedand ends with a failing job when a test failed; the summary issue of a scope is created, updated and reopened by the report. To confirm in E4 by a dry run ofreport.pyon a results directory with one failing row, before creatingCronComparison.yml.ocots commentedon Nov 11, 2026
Draft PR: #446. It implements the revised plan (phase E included); the closing summary of what is tested, and why, is in its description and in
test/README.md.Measured, no sleep, against
main: comparison environment 15704 tests / 83 min → 4615 tests / 3 min 25 s; JuMP 6280 → 1123 tests; newtest_modelings(every problem, JuMP vs OptimalControl and Scalarized, no discretization) 312 tests / 15 s; new weekly croncomparison(NLP of every problem vs CTDirect's ADNLP) 1911 tests / 3 min 31 s.One open question for the maintainer, in the PR: since the all-problem NLP comparison now costs 3.5 min and a pull request only runs the problems it changes, it could run in the pull request instead of the cron.
Merge pull request #446 from control-toolbox/test/441-rationalize-jum…
ocots commentedon Nov 11, 2026
Merged in #446 (b1e7a1d). Summary of what the test suites now do:
suite/comparison/test_modelings): the JuMP modeling against OptimalControl and OptimalControlScalarized at the continuous level (times, dynamics, objective, path and boundary constraints, bounds). 312 tests, about 15 s.suite/JuMP/test_build), and against CTDirect's ADNLP on a few representative problems computed from the features, with every scheme and ordering. All of it is marked as leaving with the JuMP discretization.comparison: the NLP of every problem against CTDirect's. It stays in the cron so that the CI time does not grow when problems are added. A difference fails the run and appears in thecron-failureissue of the scopecomparison.common/optimalcontrol_tests.jl); the initial guess is shared by construction and has no test of its own.test_nonzeros,test_start,test_init,test_kwargs.The
comparisonenvironment went from 15704 tests (83 min) to 4615 tests (about 4 min on the CI runner). CI on the PR was green, including the cron part (1911 tests).Left to do: run
CronComparison.ymlonce byworkflow_dispatchto check the workflow itself and itscron-failuresection. Sharing the GPU smoke tests is in #445.test: share the problem API, smoke and convergence tests between the …
test(mtk): compare with OptimalControl without discretizing, shared t…