You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to register erf as a work around for issue #1803 and ran into the following behavior. If I try to register the function using :erf with the below script then I receive an error.
using SpecialFunctions
using JuMP
model = Model()
@variable(model, x)
JuMP.register(model, :erf, 1, x -> erf(x), autodiff = true)
@NLconstraint(model, c1, erf(x) <= 0.0)
d = NLPEvaluator(model)
MOI.initialize(d, Symbol[:Grad])
out = zeros(1)
values = Float64[2.0]
MOI.eval_constraint(d, out, values)
Namely, this error:
ERROR: LoadError: UndefVarError: erf not defined
Stacktrace:
[1] eval_univariate at C:\Users\wilhe\.julia\packages\JuMP\e0Uc2\src\_Derivatives\forward.jl:411 [inlined]
[2] forward_eval(::Array{Float64,1}, ::Array{Float64,1}, ::Array{JuMP._Derivatives.NodeData,1}, ::SparseArrays.SparseMatrixCSC{Bool,Int64}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1},
::Array{Float64,1}, ::Array{Float64,1}, ::JuMP._Derivatives.UserOperatorRegistry) at C:\Users\wilhe\.julia\packages\JuMP\e0Uc2\src\_Derivatives\forward.jl:188
[3] _forward_eval_all(::NLPEvaluator, ::Array{Float64,1}) at C:\Users\wilhe\.julia\packages\JuMP\e0Uc2\src\nlp.jl:503
[4] macro expansion at C:\Users\wilhe\.julia\packages\JuMP\e0Uc2\src\nlp.jl:571 [inlined]
[5] macro expansion at .\timing.jl:233 [inlined]
[6] eval_constraint(::NLPEvaluator, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\wilhe\.julia\packages\JuMP\e0Uc2\src\nlp.jl:569
[7] top-level scope at C:\Users\wilhe\Dropbox\My PC (DESKTOP-P6322LG)\Desktop\Specials_reg.jl:16
[8] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088
in expression starting at C:\Users\wilhe\Dropbox\My PC (DESKTOP-P6322LG)\Desktop\Specials_reg.jl:16
If I register this function using a different name, like below, everything works out fine.
using SpecialFunctions
using JuMP
model = Model()
@variable(model, x)
JuMP.register(model, :random_name, 1, x -> erf(x), autodiff = true)
@NLconstraint(model, c1, random_name(x) <= 0.0)
d = NLPEvaluator(model)
MOI.initialize(d, Symbol[:Grad])
out = zeros(1)
values = Float64[2.0]
MOI.eval_constraint(d, out, values)
Version and package info below:
julia>versioninfo()
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-2520:08 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU:Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
WORD_SIZE:64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR ="C:\Users\wilhe\AppData\Local\atom\app-1.52.0\atom.exe"-a
JULIA_NUM_THREADS =10
Closing as duplicate of #1803. The issue is that JuMP recognizes the erf symbol from Calculus so ignores the registered function. We should either add SpecialFunctions as in #2369, or remove them entirely.
I was trying to register erf as a work around for issue #1803 and ran into the following behavior. If I try to register the function using
:erf
with the below script then I receive an error.Namely, this error:
If I register this function using a different name, like below, everything works out fine.
Version and package info below:
The text was updated successfully, but these errors were encountered: