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

Trouble calling Julia Function from Python Code #153

Closed
bdas123 opened this issue Aug 9, 2022 · 4 comments
Closed

Trouble calling Julia Function from Python Code #153

bdas123 opened this issue Aug 9, 2022 · 4 comments

Comments

@bdas123
Copy link

bdas123 commented Aug 9, 2022

I am running the following Julia code from a Python script:

function optimization(x0)

#     jacobian = CustomGradFunction(calc_sse, calc_der)
#     model = Model(jacobian)
    model = Model(calc_sse)
    addvar!(model, zeros(size(x0)), zeros(size(x0)).+100, init = x0)
    alg = NLoptAlg(:LD_MMA)
    options = NLoptOptions(ftol_rel = 1e-2)
    result = optimize(model, alg, x0, options = options)
    
    return result
    
end

However, when I do so, I get the following error:

JuliaError: Exception 'MethodError: no method matching is_propertynames_overloaded(::Type{NonconvexNLopt.NLoptResult{Vector{Float64}, Float64, NLopt.Opt, Symbol, NLoptAlg{Nothing}, NLoptOptions{NamedTuple{(:suboptions, :ftol_rel, :ftol_abs, :xtol_rel, :xtol_abs), Tuple{NLoptOptions{NamedTuple{(), Tuple{}}}, Float64, Float64, Float64, Float64}}}, Int64}}) The applicable method may be too new: running in world age 46028, while current world is 91608. Closest candidates are: is_propertynames_overloaded(::Type) at /home/ubuntu/.julia/packages/ConstructionBase/sfPqM/src/ConstructionBase.jl:71 (method too new to be called from this world context.)' occurred while calling julia code: optimization(x0)

This was not a problem before the recent update.

@bdas123 bdas123 changed the title Trouble calling Trouble calling Julia Function from Python Code Aug 9, 2022
@mohamed82008
Copy link
Member

could you please post a complete example I can run to reproduce the error?

@bdas123
Copy link
Author

bdas123 commented Aug 11, 2022

Python Code:


from julia.api import Julia
jl = Julia(compiled_modules=False)
from julia import Main
jl.eval('include("Julia functions.jl")')
result= jl.eval("Base.invokelatest(optimization,x0)")

Julia Code

model = Model(calc_sse)
addvar!(model, zeros(size(540)), zeros(size(540)).+100)

function calc_sse(x0)
    
  return sum(x0.^2)
    
end

function optimization(x0)

    alg = NLoptAlg(:LD_MMA)
    options = NLoptOptions(ftol_rel = 1e-2)
    result = optimize(model, alg, x0, options = options)
    
    return result
    
end

x0 = rand(540)

@mohamed82008
Copy link
Member

is this still an issue with the latest versions of Julia, pyjulia and Nonconvex?

@bdas123
Copy link
Author

bdas123 commented Dec 9, 2023

Hello, no it is not.

@bdas123 bdas123 closed this as completed Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants