MTK Extension : Fix Constraints and Constants#51
Open
AlCap23 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes issues in the ModelingToolkit (MTK) extension and core dynamic optimization layer so that MTK-derived constraints are normalized correctly and constant (non-tunable) parameters can be referenced without errors when building optimization objectives/constraints from symbolic expressions.
Changes:
- Extend timepoint extraction and adjust expression header generation to better support parameter symbols in
DynamicOptimizationLayer. - Update MTK extension to normalize equations/inequalities and to treat non-tunable parameters as constants when generating expressions.
- Add a convenience
DynamicOptimizationLayer(sys, defaults, controls; ...)overload that pulls costs/constraints directly from an MTK system.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/dynprob.jl |
Adjusts timepoint extraction and parameter handling when generating runtime objective/constraint functions (currently includes new info-level debug logs). |
ext/CorleoneModelingToolkitExtension.jl |
Improves MTK constraint/cost extraction and parameter replacement (adds a new overload that derives expressions from MTK system costs/constraints). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ucons::CB | ||
| end | ||
|
|
||
| _extract_timepoints(::Symbol) = [] |
Comment on lines
146
to
148
| replacer = Dict([ki => find_indices(vi, timegrid) for (ki, vi) in zip(keys(collector), values(collector)) if !isempty(vi) || is_parameter(problem, ki)]) | ||
| @info replacer | ||
| new_exprs = map(expressions) do ex |
Comment on lines
156
to
159
| end | ||
| end | ||
| @info header | ||
| getter = nothing |
| ) | ||
|
|
||
| costs = ModelingToolkit.get_costs(sys) | ||
| constraints = ModelingToolkit.get_constraints(sys) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
The current MTK extension did not transform the constraints properly and produced errors.
Additionally the use of constants was not enabled properly. This should fix this