Hello,
I have a complex function wrapped in a pkl file and I want to use to define my objective function. Here is a small example that I want to realize and the problem I meet:
using JuMP
using PyCall
py"""
import pickle
def add(x):
return x[0] + x[1] - x[2] * x[3]
def save_pickle(fpath):
with open(fpath, 'wb') as f:
pickle.dump(add, f)
def load_pickle(fpath):
with open(fpath, "rb") as f:
data = pickle.load(f)
return data
"""
save_pickle = py"save_pickle"
load_pickle = py"load_pickle"
save_pickle("function.pkl")
func = load_pickle("function.pkl")
func((1, 2, 3, 4))
model = Model()
register(model, :func, 4, func, autodiff=true)
@variable(model, x[1:2, 1:2])
@NLobjective(model, Min, func(Tuple(1.0reshape(x, 4))))
MethodError: no method matching register(::Model, ::Symbol, ::Int64, ::PyObject; autodiff=true)
Closest candidates are:
register(::Model, ::Symbol, ::Integer, ::Function; autodiff) at ~/.julia/packages/JuMP/Y4piv/src/nlp.jl:2043
register(::Model, ::Symbol, ::Integer, ::Function, ::Function; autodiff) at ~/.julia/packages/JuMP/Y4piv/src/nlp.jl:2129
register(::Model, ::Symbol, ::Integer, ::Function, ::Function, ::Function) at ~/.julia/packages/JuMP/Y4piv/src/nlp.jl:2207 got unsupported keyword argument "autodiff"
Stacktrace:
[1] top-level scope
@ In[45]:2
[2] eval
@ ./boot.jl:373 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196