`MethodError: objects of type Nothing are not callable` when optimizing basic function with `OptimizationMOI` and Ipopt
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 839
- Forks
- 100
- Avg merge
- 20h 43m
- Merged PRs (30d)
- 38
Description
Code
Optimizing a simple function without specifying autodiff.
import Pkg
Pkg.activate(temp=true)
Pkg.add([
Pkg.PackageSpec(name="Optimization", version="3.10.0"),
Pkg.PackageSpec(name="OptimizationMOI", version="0.1.5"),
Pkg.PackageSpec(name="Ipopt", version="1.1.0")
], io=devnull)
import Random
import Optimization, Ipopt
using OptimizationMOI
objective_basic(params::AbstractVector, data::AbstractVector) =
sum(@. (params[1] * data + params[2])^2)
data = randn(Random.MersenneTwister(2), 1000);
prob = Optimization.OptimizationProblem(objective_basic, [0.2, 0.1], data)
Optimization.solve(prob, Ipopt.Optimizer())
Error message
julia> Optimization.solve(prob, Ipopt.Optimizer())
This is Ipopt version 3.14.4, running with linear solver MUMPS 5.4.1.
Number of nonzeros in equality constraint Jacobian...: 0
Number of nonzeros in inequality constraint Jacobian.: 0
Number of nonzeros in Lagrangian Hessian.............: 3
ERROR: MethodError: objects of type Nothing are not callable
Stacktrace:
[1] eval_objective_gradient(moiproblem::OptimizationMOI.MOIOptimizationProblem{Float64, OptimizationFunction{true, SciMLBase.NoAD, typeof(objective_basic), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, G::Vector{Float64}, x::Vector{Float64})
@ OptimizationMOI ~/.julia/packages/OptimizationMOI/ZoxrV/src/OptimizationMOI.jl:87
[2] eval_objective_gradient(model::Ipopt.Optimizer, grad::Vector{Float64}, x::Vector{Float64})
@ Ipopt ~/.julia/packages/Ipopt/rQctM/src/MOI_wrapper.jl:525
[3] (::Ipopt.var"#eval_grad_f_cb#2"{Ipopt.Optimizer})(x::Vector{Float64}, grad_f::Vector{Float64})
@ Ipopt ~/.julia/packages/Ipopt/rQctM/src/MOI_wrapper.jl:598
[4] _Eval_Grad_F_CB(n::Int32, x_ptr::Ptr{Float64}, #unused#::Int32, grad_f::Ptr{Float64}, user_data::Ptr{Nothing})
@ Ipopt ~/.julia/packages/Ipopt/rQctM/src/C_wrapper.jl:54
[5] IpoptSolve(prob::Ipopt.IpoptProblem)
@ Ipopt ~/.julia/packages/Ipopt/rQctM/src/C_wrapper.jl:442
[6] optimize!(model::Ipopt.Optimizer)
@ Ipopt ~/.julia/packages/Ipopt/rQctM/src/MOI_wrapper.jl:727
[7] __solve(prob::OptimizationProblem{true, OptimizationFunction{true, SciMLBase.NoAD, typeof(objective_basic), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, opt::Ipopt.Optimizer; maxiters::Nothing, maxtime::Nothing, abstol::Nothing, reltol::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ OptimizationMOI ~/.julia/packages/OptimizationMOI/ZoxrV/src/OptimizationMOI.jl:329
[8] __solve
@ ~/.julia/packages/OptimizationMOI/ZoxrV/src/OptimizationMOI.jl:276 [inlined]
[9] #solve#540
@ ~/.julia/packages/SciMLBase/QqtZA/src/solve.jl:84 [inlined]
[10] solve(::OptimizationProblem{true, OptimizationFunction{true, SciMLBase.NoAD, typeof(objective_basic), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::Ipopt.Optimizer)
@ SciMLBase ~/.julia/packages/SciMLBase/QqtZA/src/solve.jl:78
[11] top-level scope
@ REPL[22]:1
Optimizing with Optimization.AutoForwardDiff() works fine:
julia> prob2 = Optimization.OptimizationProblem(Optimization.OptimizationFunction(objective_basic, Optimization.AutoForwardDiff()), [0.2, 0.1], data)
OptimizationProblem. In-place: true
u0: 2-element Vector{Float64}:
0.2
0.1
julia> Optimization.solve(prob2, Ipopt.Optimizer())
This is Ipopt version 3.14.4, running with linear solver MUMPS 5.4.1.
...
EXIT: Optimal Solution Found.
u: 2-element Vector{Float64}:
-5.551115123125783e-17
-1.3877787807814457e-17
julia>
Versions
- Julia 1.9.0-beta2
- Optimization v3.10.0
- OptimizationMOI v0.1.5
- Ipopt v1.1.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in the issue, then inspect OptimizationMOI.jl at the eval_objective_gradient and __solve entry points named in the stack trace, along with Ipopt's MOI wrapper. Confirm the failure without autodiff and add a regression test showing that the basic objective solves successfully; the existing AutoForwardDiff case provides a comparison.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100