@@ -22,24 +22,27 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt, data = DEFA
22
22
abstol:: Union{Number, Nothing} = nothing ,
23
23
reltol:: Union{Number, Nothing} = nothing ,
24
24
progress = false ,
25
- structural_analysis = true ,
25
+ structural_analysis = false ,
26
+ manifold = nothing ,
26
27
kwargs... )
27
28
reinit_cache = OptimizationBase. ReInitCache (prob. u0, prob. p)
28
29
num_cons = prob. ucons === nothing ? 0 : length (prob. ucons)
29
30
f = OptimizationBase. instantiate_function (prob. f, reinit_cache, prob. f. adtype, num_cons)
30
31
31
- if (f. sys === nothing || f. sys isa SymbolicIndexingInterface. SymbolCache{Nothing, Nothing, Nothing}) && structural_analysis
32
+ if (f. sys === nothing ||
33
+ f. sys isa SymbolicIndexingInterface. SymbolCache{Nothing, Nothing, Nothing}) &&
34
+ structural_analysis
32
35
try
33
- vars =
34
- if prob. u0 isa Matrix
36
+ vars = if prob. u0 isa Matrix
35
37
@variables X[1 : size (prob. u0, 1 ), 1 : size (prob. u0, 2 )]
36
38
else
37
- ArrayInterface. restructure (prob. u0, [variable (:x , i) for i in eachindex (prob. u0)])
39
+ ArrayInterface. restructure (
40
+ prob. u0, [variable (:x , i) for i in eachindex (prob. u0)])
38
41
end
39
42
params = if prob. p isa SciMLBase. NullParameters
40
43
[]
41
- # elseif prob.p isa MTK.MTKParameters
42
- # [variable(:α, i) for i in eachindex(vcat(p...))]
44
+ elseif prob. p isa MTK. MTKParameters
45
+ [variable (:α , i) for i in eachindex (vcat (p... ))]
43
46
else
44
47
ArrayInterface. restructure (p, [variable (:α , i) for i in eachindex (p)])
45
48
end
@@ -87,7 +90,7 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt, data = DEFA
87
90
cons_expr = nothing
88
91
end
89
92
catch err
90
- throw (ArgumentError (" Automatic symbolic expression generation with ModelingToolkit failed with error: $err .
93
+ throw (ArgumentError (" Automatic symbolic expression generation with failed with error: $err .
91
94
Try by setting `structural_analysis = false` instead if the solver doesn't require symbolic expressions." ))
92
95
end
93
96
else
@@ -96,25 +99,28 @@ function OptimizationCache(prob::SciMLBase.OptimizationProblem, opt, data = DEFA
96
99
obj_expr = f. expr
97
100
cons_expr = f. cons_expr
98
101
end
99
- try
100
- obj_expr = obj_expr |> Symbolics. unwrap
101
- obj_expr = propagate_curvature (propagate_sign (obj_expr))
102
- @info " Objective Euclidean curvature: $(SymbolicAnalysis. getcurvature (obj_expr)) "
103
- catch
104
- @info " No euclidean atom available"
105
- end
106
102
107
- try
108
- obj_expr = SymbolicAnalysis. propagate_gcurvature (propagate_sign (obj_expr), prob. kwargs[1 ])
109
- @info " Objective Geodesic curvature: $(SymbolicAnalysis. getgcurvature (obj_expr)) "
110
- catch e
111
- @show e
103
+ if obj_expr != = nothing
104
+ try
105
+ obj_expr = obj_expr |> Symbolics. unwrap
106
+ obj_expr = propagate_curvature (propagate_sign (obj_expr))
107
+ @info " Objective Euclidean curvature: $(getcurvature (obj_expr)) "
108
+ catch
109
+ @info " No euclidean atom available"
110
+ end
111
+
112
+ try
113
+ obj_expr = propagate_gcurvature (propagate_sign (obj_expr), manifold)
114
+ @info " Objective Geodesic curvature: $(getgcurvature (obj_expr)) "
115
+ catch
116
+ @info " No geodesic atom available"
117
+ end
112
118
end
113
119
114
- if ! isnothing ( cons_expr)
120
+ if cons_expr != = nothing
115
121
cons_expr = cons_expr .| > Symbolics. unwrap
116
122
cons_expr = propagate_curvature .(propagate_sign .(cons_expr))
117
- @info " Constraints Euclidean curvature: $(SymbolicAnalysis . getcurvature .(cons_expr)) "
123
+ @info " Constraints Euclidean curvature: $(getcurvature .(cons_expr)) "
118
124
end
119
125
120
126
return OptimizationCache (f, reinit_cache, prob. lb, prob. ub, prob. lcons,
0 commit comments