Skip to content

MTK Extension : Fix Constraints and Constants#51

Open
AlCap23 wants to merge 2 commits into
CJM-Layersfrom
CJM-MTK_FIX1
Open

MTK Extension : Fix Constraints and Constants#51
AlCap23 wants to merge 2 commits into
CJM-Layersfrom
CJM-MTK_FIX1

Conversation

@AlCap23

@AlCap23 AlCap23 commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

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

@AlCap23 AlCap23 marked this pull request as ready for review May 8, 2026 06:46
@AlCap23 AlCap23 requested a review from Copilot May 8, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/dynprob.jl
ucons::CB
end

_extract_timepoints(::Symbol) = []
Comment thread src/dynprob.jl
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 thread src/dynprob.jl
Comment on lines 156 to 159
end
end
@info header
getter = nothing
)

costs = ModelingToolkit.get_costs(sys)
constraints = ModelingToolkit.get_constraints(sys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants