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

Can't register erf as :erf #2368

Closed
mewilhel opened this issue Nov 5, 2020 · 1 comment · Fixed by #2369
Closed

Can't register erf as :erf #2368

mewilhel opened this issue Nov 5, 2020 · 1 comment · Fixed by #2369

Comments

@mewilhel
Copy link

mewilhel commented Nov 5, 2020

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-25 20: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
 [c52e3926] Atom v0.12.24
  [6e4b80f9] BenchmarkTools v0.5.0
  [336ed68f] CSV v0.7.7
  [7057c7e9] Cassette v0.3.3
  [e2554f3b] Clp v0.8.1
  [a93c6f00] DataFrames v0.21.7
  [864edb3b] DataStructures v0.17.20
  [163ba53b] DiffResults v1.0.2
  [0c46a032] DifferentialEquations v6.15.0
  [bb8be931] EAGO v0.5.0 `C:\Users\wilhe\Desktop\Package Development\EAGO.jl`
  [587475ba] Flux v0.11.1
  [f6369f11] ForwardDiff v0.10.12
  [4b11ee91] Gaston v1.0.2
  [7073ff75] IJulia v1.22.0
  [d1acc4aa] IntervalArithmetic v0.17.5
  [d2bf35a9] IntervalRootFinding v0.5.4
  [b6b21f68] Ipopt v0.6.3
  [4076af6c] JuMP v0.21.4
  [e5e0dc1b] Juno v0.8.4
  [b964fa9f] LaTeXStrings v1.2.0
  [33e6dc65] MKL v0.2.0 `https://github.com/JuliaComputing/MKL.jl#master`
  [b8f27783] MathOptInterface v0.9.17
  [53c679d3] McCormick v0.9.0 `C:\Users\wilhe\Desktop\Package Development\McCormick.jl`
  [2774e3e8] NLsolve v4.4.1
  [91a5bcdd] Plots v1.6.10
  [d330b81b] PyPlot v2.9.0
  [189a3867] Reexport v0.2.0
  [295af30f] Revise v3.1.4
  [276daf66] SpecialFunctions v0.10.3
  [90137ffa] StaticArrays v0.12.4
  [c3572dad] Sundials v3.9.0
  [d1185830] SymbolicUtils v0.5.1
  [6aa5eb33] TaylorSeries v0.10.8
  [d621b6e3] ValidatedNumerics v0.11.0
@odow
Copy link
Member

odow commented Nov 8, 2020

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.

@odow odow closed this as completed Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants