You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Importing solution fails when OCP has exactly one variable #857
Describe the bug import_ocp_solution fails if isa(variable(solution), Float64), if there is zero or n >= 2 variables, then the loading works as expected.
To Reproduce
using OptimalControl
using NLPModelsIpopt
using JLD2
filename="sol"## Fine
tf =1
ocp =@defbegin
t ∈ [0, tf], time
x ∈ R, state
u ∈ R, control
x(0) ==0x(tf) ==1ẋ(t) ==u(t)
∫(0.5u(t)^2) → min
end
s =solve(ocp, grid_size=8)
export_ocp_solution(s; filename)
si =import_ocp_solution(ocp; filename)
## Workaround with dummy parameter p_
ocp =@defbegin
p = (tf, p_) ∈ R², variable
t ∈ [0, tf], time
x ∈ R, state
u ∈ R, control
p_ ==01<= tf <=2x(0) ==0x(tf) ==1ẋ(t) ==u(t)
∫(0.5u(t)^2) → min
end
s =solve(ocp, grid_size=8)
export_ocp_solution(s; filename)
si =import_ocp_solution(ocp; filename)
## Bug
ocp =@defbegin
tf ∈ R, variable
t ∈ [0, tf], time
x ∈ R, state
u ∈ R, control
1<= tf <=2x(0) ==0x(tf) ==1ẋ(t) ==u(t)
∫(0.5u(t)^2) → min
end
s =solve(ocp, grid_size=8)
export_ocp_solution(s; filename)
si =import_ocp_solution(ocp; filename)
Expected behavior variable(solution) returns a vector of length 1, or the loading code can handle Number instead of Vector
Activity
ocots commentedon Aug 16, 2026
Thanks @abavoil for this bug!
It will be fixed by control-toolbox/CTModels.jl#396.