infiniteopt / InfiniteOpt.jl

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

Test failure on Julia 1.9 #315

Closed odow closed 1 year ago

odow commented 1 year ago

Trying to debug https://github.com/jump-dev/JuMP.jl/pull/3350#issuecomment-1542915469, using my printing PR here: https://github.com/infiniteopt/InfiniteOpt.jl/pull/314.

But I'm going crazy.

I've edited the code in point_variables.jl to print what's happening:

image

When the function is called. No error is thrown. When you eval in the REPL, an error is thrown. Ideas???

julia> using Test

julia> using InfiniteOpt

julia> m1 = InfiniteModel()
An InfiniteOpt Model
Feasibility problem with:
Finite Parameters: 0
Infinite Parameters: 0
Variables: 0
Derivatives: 0
Measures: 0
Optimizer model backend information: 
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @infinite_parameter(m1, p in [0, 1])
p

julia> @variable(m1, x, Infinite(p))
x(p)

julia> v = build_variable(
           error, 
           VariableInfo(false, 0.0, false, 0.0, false, 0.0, false, 0.0, false, false), 
           Point(x, 0.5),
       )
PointVariable{GeneralVariableRef}(VariableInfo{Float64, Float64, Float64, Float64}(false, 0.0, false, 0.0, false, 0.0, false, 0.0, false, false), x(p), [0.5])

julia> m2 = InfiniteModel()
An InfiniteOpt Model
Feasibility problem with:
Finite Parameters: 0
Infinite Parameters: 0
Variables: 0
Derivatives: 0
Measures: 0
Optimizer model backend information: 
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> JuMP.add_variable(m2, v)
[ Info: Called here
[ Info: x(p)
#= /Users/oscar/.julia/dev/InfiniteOpt/src/point_variables.jl:436 =# InteractiveUtils.@which(JuMP.check_belongs_to_model(divref, model)) = check_belongs_to_model(v::AbstractVariableRef, model::AbstractModel) @ JuMP ~/.julia/packages/JuMP/jYny8/src/variables.jl:280
[ Info: Passed check
x(0.5)

julia> ivref = v.infinite_variable_ref
x(p)

julia> divref = dispatch_variable_ref(ivref)
x(p)

julia> @info divref
[ Info: x(p)

julia> @show InteractiveUtils.@which JuMP.check_belongs_to_model(divref, m2)
#= REPL[85]:1 =# InteractiveUtils.@which(JuMP.check_belongs_to_model(divref, m2)) = check_belongs_to_model(v::AbstractVariableRef, model::AbstractModel) @ JuMP ~/.julia/packages/JuMP/jYny8/src/variables.jl:280
check_belongs_to_model(v::AbstractVariableRef, model::AbstractModel)
     @ JuMP ~/.julia/packages/JuMP/jYny8/src/variables.jl:280

julia> JuMP.check_belongs_to_model(divref, m2)
ERROR: VariableNotOwned{InfiniteVariableRef}(x(p))
Stacktrace:
 [1] check_belongs_to_model(v::InfiniteVariableRef, model::InfiniteModel)
   @ JuMP ~/.julia/packages/JuMP/jYny8/src/variables.jl:282
 [2] top-level scope
   @ REPL[86]:1

(InfiniteOpt) pkg> st
Project InfiniteOpt v0.5.7
Status `~/.julia/dev/InfiniteOpt/Project.toml`
  [1520ce14] AbstractTrees v0.4.4
  [864edb3b] DataStructures v0.18.13
  [31c24e10] Distributions v0.25.90
  [442a2c76] FastGaussQuadrature v0.5.1
  [4076af6c] JuMP v1.11.0 `https://github.com/jump-dev/JuMP.jl.git#master`
  [1d6d02ad] LeftChildRightSiblingTrees v0.2.0
  [d8a4904e] MutableArithmetics v1.3.0
  [189a3867] Reexport v1.2.2
  [276daf66] SpecialFunctions v2.2.0
  [b77e0a4c] InteractiveUtils
  [37e2e46d] LinearAlgebra
odow commented 1 year ago

So I added this method:

# TODO(odow): why is this needed for v1.9?
function JuMP.check_belongs_to_model(
    v::InfiniteVariableRef,
    model::InfiniteModel,
)
    if JuMP.owner_model(v) !== model
        throw(JuMP.VariableNotOwned(v))
    end
    return
end

Which is just the method it was trying to call in JuMP:

https://github.com/jump-dev/JuMP.jl/blob/dd66846cd28b9cc65b82b8d6bb8de67162c83f8b/src/variables.jl#L280-L284

So this feels like a bug in Julia. But it looks like you're testing on nightly, so I don't understand what happened.

pulsipher commented 1 year ago

I came to the same conclusion (see https://github.com/infiniteopt/InfiniteOpt.jl/pull/314#issuecomment-1543331721). I also have no idea why this is happening. And I checked the last few nightly runs, they all ran without issue...

odow commented 1 year ago

So perhaps it was a bug that was fixed and not back ported to 1.9?

pulsipher commented 1 year ago

So perhaps it was a bug that was fixed and not back ported to 1.9?

This seems the most plausible.

Or maybe it's a bug in Julia that only shows with the new version of JuMP for some reason...