infiniteopt / InfiniteOpt.jl

An intuitive modeling interface for infinite-dimensional optimization problems.
https://infiniteopt.github.io/InfiniteOpt.jl/stable
MIT License
254 stars 17 forks source link

Inconsistent Info Updates for Derivatives #263

Closed pulsipher closed 2 years ago

pulsipher commented 2 years ago

Currently, we allow users to define derivatives via @variable even if the derivative was already made previously. The info with this addition then overrides any existing info. In relation to #148, this might not be the behavior we want. A current bug of this approach is that although the start value function can be overwritten, the is_vector_start field is not updated accordingly:

model = InfiniteModel()
@infinite_parameter(model, t in [0, 1])
@variable(model, y, Infinite(t))
deriv(y, t)
@variable(model, dy, Deriv(y, t), start = sin)
dy(0) # creating the point variable exposes the incomplete info update
ERROR: MethodError: no method matching sin(::Vector{Float64})
Closest candidates are:
  sin(::T) where T<:Union{Float32, Float64} at C:\Users\bbgui\AppData\Local\Programs\Julia-1.7.1\share\julia\base\special\trig.jl:29
  sin(::AbstractInfOptExpr) at C:\Users\bbgui\.julia\packages\InfiniteOpt\GRGsL\src\nlp.jl:934
  sin(::GenericQuadExpr) at C:\Users\bbgui\.julia\packages\JuMP\0C6kd\src\operators.jl:409
  ...
Stacktrace:
 [1] _update_point_info(info::VariableInfo{Float64, Float64, Float64, Float64}, ivref::DerivativeRef, point::Vector{Float64})
   @ InfiniteOpt ~\.julia\packages\InfiniteOpt\GRGsL\src\point_variables.jl:178
 [2] build_variable(_error::typeof(error), info::VariableInfo{Float64, Float64, Float64, Float64}, var_type::Point{GeneralVariableRef, InfiniteOpt.Collections.VectorTuple{Int64, Tuple{Nothing}}}; extra_kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ InfiniteOpt ~\.julia\packages\InfiniteOpt\GRGsL\src\point_variables.jl:254
 [3] build_variable
   @ ~\.julia\packages\InfiniteOpt\GRGsL\src\point_variables.jl:231 [inlined]
 [4] _restrict_infinite_variable(ivref::GeneralVariableRef, vt::InfiniteOpt.Collections.VectorTuple{Int64, Tuple{Nothing}})
   @ InfiniteOpt ~\.julia\packages\InfiniteOpt\GRGsL\src\infinite_variables.jl:354
 [5] _functional_reference_call(ivref::GeneralVariableRef, #unused#::Type{DerivativeIndex}, supps::Int64)
   @ InfiniteOpt ~\.julia\packages\InfiniteOpt\GRGsL\src\infinite_variables.jl:433
 [6] (::GeneralVariableRef)(args::Int64; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ InfiniteOpt ~\.julia\packages\InfiniteOpt\GRGsL\src\general_variables.jl:413
 [7] (::GeneralVariableRef)(args::Int64)
   @ InfiniteOpt ~\.julia\packages\InfiniteOpt\GRGsL\src\general_variables.jl:413
 [8] top-level scope
   @ REPL[56]:1

In the near term, we should fix this bug. For v0.6, we should determine if we should continue this support or not.

pulsipher commented 2 years ago

Closed by #264