However, that looks like a bug because you should probably get a nicer error message. It might be because of the prod2.get. What happens if you try:
prod2_get = [prod2.get([m-1, m-1]) for m in 1:num_basis]
@NLexpression(model, [i = 1:num_buses], sum(
prod2_get[m] * (vre_coeffs[i, m]^2 + vim_coeffs[i, m]^2)
for m = 1:num_basis)
)
prod2.get is indeed the problem. I wasn’t aware scalar functions weren’t allowed in JuMP NLexpressions. In this particular case a meaningful error message is not provided since the function is stored in a struct. A minimal example is provided below:
Input
using JuMP
myfunc(t) = 1
struct MyStruct
func::Function
end
my_object = MyStruct(myfunc)
m = Model()
@variable(m, x[1:2])
@NLexpression(m, sum(my_object.func(i) * x[i] for i = 1:2))
Error Output
ERROR: LoadError: MethodError: no method matching _is_sum(::Expr)
Closest candidates are:
_is_sum(::Symbol) at [user-dir]\.julia\packages\JuMP\ibcEh\src\macros.jl:8
Stacktrace:
[1] _parse_NL_expr(::Symbol, ::Expr, ::Symbol, ::Symbol, ::Symbol) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_nlp.jl:40
[2] _parse_NL_expr(::Symbol, ::Expr, ::Symbol, ::Symbol, ::Symbol) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_nlp.jl:124
[3] (::getfield(JuMP, Symbol("##80#81")){Symbol,Symbol,Symbol})(::Expr) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_nlp.jl:34
[4] _parse_gen(::Expr, ::getfield(JuMP, Symbol("##80#81")){Symbol,Symbol,Symbol}) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_expr.jl:325
[5] _parse_gen(::Expr, ::getfield(JuMP, Symbol("##80#81")){Symbol,Symbol,Symbol}) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_expr.jl:347
[6] _parse_NL_expr(::Symbol, ::Expr, ::Symbol, ::Int64, ::Symbol) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_nlp.jl:34
[7] _process_NL_expr(::Symbol, ::Expr) at [user-dir]\.julia\packages\JuMP\ibcEh\src\parse_nlp.jl:232
[8] @NLexpression(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at [user-dir]\.julia\packages\JuMP\ibcEh\src\macros.jl:1639
in expression starting at REPL[7]:1