[Problems] ModelingToolkitBackend, extension ModelingToolkitModels, and continuous bryson_denham (#308)
Maintainer thường phản hồi trong vòng 1 ngày
@ocots đang làm issue này rồi.
Từ ngày 8/11/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Agents: read the guide for agents in #310 first (order, difficulty, how to claim an issue, working method). Read
AGENTS.mdand clone.ct-conventions(v0.11.0) and.ct-agents(v0.4.0). Specification: this description and #308.
Sub-issue of #308, part 1 of 3. Independent (all prerequisites in #310 are merged).
Goal
Introduce the ModelingToolkitBackend (:ModelingToolkit) modeling, the ModelingToolkitModels weak-dependency extension, the CTModels.Models component/dimension interface on ModelingToolkit.AbstractSystem, and our own continuous bryson_denham model in ext/ModelingToolkitModels/bryson_denham.jl (with status :draft until Part 2 adds the Corleone equivalence and reference tests), together with problem-retrieval unit tests in test/suite/ModelingToolkit/test_problem.jl.
At the end of this issue, bryson_denham(ModelingToolkitBackend()) is functional, returns a continuous Problem wrapping a ModelingToolkit.System with shared parameters and :init from metadata, and both suite/core and suite/ModelingToolkit pass.
Technical Findings (from #308 preliminary checks)
- Continuous path constraint
(a)works inModelingToolkit.System(v11):
ModelingToolkit.System(eqs, t; costs, constraints, name)accepts a symbolic path inequality depending on the independent variablet = ModelingToolkit.t_nounits:
The time horizoncstr = [x₁(tf) ~ x1_tf, x₂(tf) ~ x2_tf, x₁(t) ≲ x1_max](t0, tf)is carried by the integral cost domainSymbolics.Integral(t in (t0, tf))(0.5 * u(t)^2).
Thereforebryson_denham(ModelingToolkitBackend(); parameters=nothing, init=:default)takes no grid argument and returns a purely continuousModelingToolkit.System. (Samplingx₁(t) ≲ x1_maxontoconstraint_gridis done at solve time in Part 2.) CTModels.Modelsinterface onModelingToolkit.AbstractSystem:
Base.show(io, ::MIME"text/plain", pb::Problem)callsCTModels.Models.state_dimension(model),control_dimension(model), andvariable_dimension(model).
Inext/ModelingToolkitModels.jl, define onsys::ModelingToolkit.AbstractSystem:- States:
unknowns(sys)where!ModelingToolkit.isinput(v) - Controls:
unknowns(sys)whereModelingToolkit.isinput(v)(declared with[input = true]) - Variables:
parameters(sys)whereModelingToolkit.istunable(p, true) && !ModelingToolkit.isinput(p)
Strip the(t)suffix from symbolic names so component names are"x₁","x₂","u"(matchingOptimalControlandJuMPmodelings).
- States:
Mandatory Rules & Conventions (ct-conventions v0.11.0, #310)
- Worktree per issue (
#310rule 3a): Never edit or switch branches in the main checkout. Create a dedicated worktree (git worktree add ../OptimalControlProblems-<issue> -b feat/<issue>-mtk-backend main). - Plan before code (
AGENTS.md): Propose a plan following.ct-conventions/plan-template.mdand wait for confirmation if working locally with a human, or post the plan on the issue after claiming it (#310rule 3b). - Qualified imports only (
MOD3,MOD4): Always useusing Pkg: Pkg, sym. Never use bareusing Pkgorimport. - No top-level exports (
MOD8): OnlyModelingToolkitBackendis exported fromModelingsand re-exported byOptimalControlProblems(matchingOptimalControlBackend,OptimalControlScalarizedBackend,JuMPBackend). - 1-D is a scalar (
DIM1): A 1-D state, control, or variable is aNumber, not a 1-elementVector. - No hand-written problem lists (
test_no_handwritten_listintest/suite/core/test_consistency.jl): Never write:bryson_denhamor"bryson_denham"literals outside docstrings insrc/,test/, orext/*.jl. In tests, always iterate withMain.TestStatus.for_each_problem(..., OptimalControlProblems.ModelingToolkitBackend())orOptimalControlProblems.problems(OptimalControlProblems.ModelingToolkitBackend()). - Docstrings (
DOC1–DOC8): English only (GEN1), written once implementation is stable.
Detailed Implementation Plan
###Files to Create or Modify
| File | Action | Details |
|---|---|---|
Project.toml |
Modify | Add ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" to [weakdeps], ModelingToolkitModels = "ModelingToolkit" to [extensions], and ModelingToolkit = "11" to [compat]. |
src/Modelings/backends.jl |
Modify | Define struct ModelingToolkitBackend <: AbstractModelBackend end. Add (type=ModelingToolkitBackend, name=:ModelingToolkit, ext=:ModelingToolkitModels, pkg="ModelingToolkit") to MODELING_SPECS. Update the docstring table. |
src/Modelings/Modelings.jl |
Modify | Export ModelingToolkitBackend. |
src/OptimalControlProblems.jl |
Modify | Import and re-export ModelingToolkitBackend. |
ext/ModelingToolkitModels.jl |
Create | Module ModelingToolkitModels: include all ext/ModelingToolkitModels/*.jl files; extend CTModels.Models.{state_components,control_components,variable_components,state_dimension,control_dimension,variable_dimension} on ModelingToolkit.AbstractSystem. |
ext/ModelingToolkitModels/bryson_denham.jl |
Create | Define OptimalControlProblems.bryson_denham(::OptimalControlProblems.ModelingToolkitBackend; parameters=nothing, init=:default): merge parameters with metadata(:bryson_denham)[:parameters], parse init via Problems.parse_init, build the continuous ModelingToolkit.System (@variables x₁(t) = x1_0 [tunable = false] x₂(t) = x2_0 [tunable = false] u(t) [input = true], D(x₁) ~ x₂, D(x₂) ~ u, costs = [Symbolics.Integral(t in (t0, tf))(0.5 * u^2)], constraints = [x₁(tf) ~ x1_tf, x₂(tf) ~ x2_tf, x₁(t) ≲ x1_max]), and return Problems.Problem(:bryson_denham, meta[:title], sys, init_parsed). |
ext/MetaData/bryson_denham.jl |
Modify | Add ModelingToolkit=:draft to :status. |
docs/modelings.jl |
Modify | Add :ModelingToolkit => ModelingAdapter(...) to MODELINGS ( required by consistency/doc checks whenever a backend is added to MODELING_SPECS). |
test/suite/core/test_modelings.jl |
Modify | Add OptimalControlProblems.ModelingToolkitBackend() to BACKENDS. |
test/suite/ModelingToolkit/Project.toml |
Create | Isolated test environment with ModelingToolkit (compat = "11"), CTBase, CTModels, Test. |
test/suite/ModelingToolkit/test_problem.jl |
Create | Test Problem retrieval, model(pb) isa ModelingToolkit.AbstractSystem, CTModels dimensions and component names, equations/costs/constraints presence, parameters override, and init variants (:default, :zero, custom NamedTuple, invalid init throwing CTBase.Exceptions.IncorrectArgument) using Main.TestStatus.for_each_problem. |
Verification Commands
julia --project=. -e 'using Pkg; Pkg.test(test_args=["suite/core"])'
julia --project=. -e 'using Pkg; Pkg.test(test_args=["suite/ModelingToolkit"])'
Done when
-
ModelingToolkitBackendis registered inMODELING_SPECSand exported. -
ext/ModelingToolkitModels.jlandext/ModelingToolkitModels/bryson_denham.jlbuild a continuousModelingToolkit.Systemwith continuous path constraintx₁(t) ≲ x1_max, integral cost∫ 0.5 u(t)², our parameters, and shared:init. -
CTModels.Modelsdimension and component functions work onModelingToolkit.AbstractSystem, andBase.showdisplays theProblemsummary cleanly. -
bryson_denhamhasModelingToolkit=:draftinext/MetaData/bryson_denham.jl. -
suite/core(includingtest_no_handwritten_listandtest_modelings) andsuite/ModelingToolkit(test_problem.jl) pass with 0 failures/errors.
Refs #308, #310
- Ngôn ngữ chính
- Julia
- Star
- 13
- Fork
- 1
- Merge trung bình
- 3 giờ 33 phút
- Pull request đã merge (30 ngày)
- 55
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của control-toolbox/OptimalControlProblems.jl
-
[Cron/Doc] ModelingToolkit convergence cron, trajectories, and documentation (#308)Có thể đã có người làm @ocots đã nhận hôm nay. Đang mởdocumentation feature
control-toolbox/OptimalControlProblems.jl#439 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Tests] Corleone solve helper and ModelingToolkit test suite (smoke, equivalence, reference solution) (#308)Có thể đã có người làm @ocots đã nhận hôm nay. Đang mởfeature
control-toolbox/OptimalControlProblems.jl#438 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
cron-convergence
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 32/100
control-toolbox/OptimalControlProblems.jl#436 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Cron] cron-failureĐang mởcron-failure
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
control-toolbox/OptimalControlProblems.jl#435 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Dev] Expose the duals of the JuMP path, boundary and box constraints, aligned with signs.mdCó thể đã có người làm @ocots đã nhận hôm nay. Đang mở
control-toolbox/OptimalControlProblems.jl#430 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của control-toolbox/OptimalControlProblems.jl
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
lux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
JuliaGraphs/GraphNeuralNetworks.jl#732 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
erfinv(::Float16) and erfcinv(::Float16) are wrong for abs(x) <= 0.75 (erfinv(Float16(0)) == 0.2201)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
JuliaMath/SpecialFunctions.jl#571 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100