[Problems] ModelingToolkitBackend, extension ModelingToolkitModels, and continuous bryson_denham (#308)
メンテナーはふだん 1 日以内に返信
@ocots がすでに取り組んでいます。
2026年11月8日 から。
評価
この issue はまだ評価されていません。
説明
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
- 主要言語
- Julia
- スター
- 13
- フォーク
- 1
- 平均マージ
- 3時間 33分
- マージ済み PR(30日)
- 55
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
control-toolbox/OptimalControlProblems.jl のほかの issue
-
[Cron/Doc] ModelingToolkit convergence cron, trajectories, and documentation (#308)対応中かも @ocots が今日担当しました。 オープンdocumentation feature
control-toolbox/OptimalControlProblems.jl#439 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Tests] Corleone solve helper and ModelingToolkit test suite (smoke, equivalence, reference solution) (#308)対応中かも @ocots が今日担当しました。 オープンfeature
control-toolbox/OptimalControlProblems.jl#438 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
cron-convergence
難易度 4/5 3〜5日 初心者へのやさしさ 32/100
control-toolbox/OptimalControlProblems.jl#436 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
[Cron] cron-failureオープンcron-failure
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
control-toolbox/OptimalControlProblems.jl#435 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
[Dev] Expose the duals of the JuMP path, boundary and box constraints, aligned with signs.md対応中かも @ocots が今日担当しました。 オープン
control-toolbox/OptimalControlProblems.jl#430 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
control-toolbox/OptimalControlProblems.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 1 日以内に返信
-
lux
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaGraphs/GraphNeuralNetworks.jl#732 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
erfinv(::Float16) and erfcinv(::Float16) are wrong for abs(x) <= 0.75 (erfinv(Float16(0)) == 0.2201)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
JuliaMath/SpecialFunctions.jl#571 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100