Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: type Symbol has no field head #226

Open
odow opened this issue Feb 15, 2023 · 5 comments
Open

ERROR: type Symbol has no field head #226

odow opened this issue Feb 15, 2023 · 5 comments
Labels

Comments

@odow
Copy link
Collaborator

odow commented Feb 15, 2023

#223 rises from the grave.

I don't remember if we support user-defined functions, but we should at least throw a nicer error message:

(alpine) pkg> st
      Status `/private/tmp/alpine/Project.toml`
  [07493b3f] Alpine v0.5.2 `~/.julia/dev/Alpine`
  [87dc4568] HiGHS v1.4.3
  [b6b21f68] Ipopt v1.1.0
  [4076af6c] JuMP v1.7.0
  [2ddba703] Juniper v0.9.1

julia> using JuMP, Alpine, HiGHS, Ipopt, Juniper

julia> nlp_solver = optimizer_with_attributes(Ipopt.Optimizer, MOI.Silent() => true, "sb" => "yes", "max_iter" => Int(1e4));

julia> mip_solver = JuMP.optimizer_with_attributes(HiGHS.Optimizer, "presolve" => "on", "log_to_console" => false);

julia> m = Model(
           optimizer_with_attributes(
               Alpine.Optimizer, 
               "minlp_solver" => optimizer_with_attributes(
                   Juniper.Optimizer,
                   MOI.Silent() => true, 
                   "mip_solver" => mip_solver, 
                   "nl_solver" => nlp_solver,
               ), 
               "nlp_solver" => nlp_solver, 
               "mip_solver" => mip_solver, 
           )
       )
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Alpine

julia> @variable(m, x[1:3], Bin)
3-element Vector{VariableRef}:
 x[1]
 x[2]
 x[3]

julia> f_objective(x::T...) where {T<:Real} = x[1] + x[2] + x[3]
f_objective (generic function with 1 method)

julia> register(m, :f_objective, 3, f_objective; autodiff = true)

julia> @NLobjective(m, Min, f_objective(x...))

julia> optimize!(m)
ERROR: type Symbol has no field head
Stacktrace:
  [1] getproperty(x::Symbol, f::Symbol)
    @ Base ./Base.jl:33
  [2] traverse_expr_linear_to_affine(expr::Symbol, lhscoeffs::Vector{Any}, lhsvars::Vector{Any}, rhs::Float64, bufferVal::Nothing, bufferVar::Nothing, sign::Float64, coef::Float64, level::Int64)
    @ Alpine ~/.julia/dev/Alpine/src/nlexpr.jl:356
  [3] traverse_expr_linear_to_affine(expr::Expr, lhscoeffs::Vector{Any}, lhsvars::Vector{Any}, rhs::Float64, bufferVal::Nothing, bufferVar::Nothing, sign::Float64, coef::Float64, level::Int64)
    @ Alpine ~/.julia/dev/Alpine/src/nlexpr.jl:374
  [4] traverse_expr_linear_to_affine
    @ ~/.julia/dev/Alpine/src/nlexpr.jl:332 [inlined]
  [5] expr_linear_to_affine(expr::Expr)
    @ Alpine ~/.julia/dev/Alpine/src/nlexpr.jl:299
  [6] expr_conversion(m::Alpine.Optimizer)
    @ Alpine ~/.julia/dev/Alpine/src/nlexpr.jl:89
  [7] process_expr
    @ ~/.julia/dev/Alpine/src/nlexpr.jl:10 [inlined]
  [8] load!(m::Alpine.Optimizer)
    @ Alpine ~/.julia/dev/Alpine/src/main_algorithm.jl:110
  [9] optimize!(m::Alpine.Optimizer)
    @ Alpine ~/.julia/dev/Alpine/src/main_algorithm.jl:151
 [10] optimize!
    @ ~/.julia/packages/MathOptInterface/NCblk/src/Bridges/bridge_optimizer.jl:376 [inlined]
 [11] optimize!
    @ ~/.julia/packages/MathOptInterface/NCblk/src/MathOptInterface.jl:83 [inlined]
 [12] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{Alpine.Optimizer}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/NCblk/src/Utilities/cachingoptimizer.jl:316
 [13] optimize!(model::Model; ignore_optimize_hook::Bool, _differentiation_backend::MathOptInterface.Nonlinear.SparseReverseMode, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ JuMP ~/.julia/packages/JuMP/yYfHy/src/optimizer_interface.jl:480
 [14] optimize!(model::Model)
    @ JuMP ~/.julia/packages/JuMP/yYfHy/src/optimizer_interface.jl:458
 [15] top-level scope
    @ REPL[19]:1
@odow odow added the bug label Feb 15, 2023
@odow
Copy link
Collaborator Author

odow commented May 29, 2024

@odow
Copy link
Collaborator Author

odow commented May 30, 2024

Reproducible example:

julia> using JuMP, Alpine, Juniper

julia> model = Model(Alpine.Optimizer);

julia> set_attribute(model, "minlp_solver", optimizer_with_attributes(Juniper.Optimizer))

julia> @variable(model, x, Bin)
x

julia> @NLconstraint(model, x^2 <= 1.0)
x ^ 2.0 - 1.0  0

julia> optimize!(model)
ERROR: type Symbol has no field head
Stacktrace:
  [1] getproperty
    @ ./Base.jl:37 [inlined]
  [2] traverse_expr_linear_to_affine(expr::Symbol, lhscoeffs::Vector{…}, lhsvars::Vector{…}, rhs::Float64, bufferVal::Nothing, bufferVar::Nothing, sign::Float64, coef::Float64, level::Int64)

@stumarcus314

This comment was marked as off-topic.

@stumarcus314

This comment was marked as duplicate.

@odow

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants