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

MethodError when using (indirectly) StaticArrays #105

Closed
Alexander-Barth opened this issue Jul 4, 2017 · 4 comments · Fixed by JuliaPy/PyCall.jl#416 or JuliaLang/julia#22987
Closed

Comments

@Alexander-Barth
Copy link

Since julia version 0.6 I get an error Julia exception: MethodError when I try to call a julia module (https://github.com/gher-ulg/divand.jl/) from python. I tried to track the origin of this error and it seems that it is related to the module StaticArrays (which is used indirectly in my module trough the model Roots, requiring ForewardDiff which requires StaticArrays).

Here is the minimal code which reproduces this issue:

The file TestModule.jl:

module TestModule
# this line generates the error, despite StaticArrays are not used
# RuntimeError: Julia exception: MethodError(TestModule.myx2, (Any[1, 2, 3],), 0x0000000000005537)
using StaticArrays
myx2(x)  = x.^2

export myx2
end

The file test_simple_module.py:

import julia
j = julia.Julia()
# add to directory to TestModule.jl
j.eval('push!(LOAD_PATH,joinpath(ENV["HOME"],"projects/Julia/share"))')
j.using('TestModule')
print j.myx2([1,2,3])

I run this example as:

~/.julia/v0.6/Conda/deps/usr/bin/python2.7 test_simple_module.py

The produces the following error:

WARNING: redefining constant JULIA_HOME
Traceback (most recent call last):
  File "test_simple_module.py", line 6, in <module>
    print j.myx2([1,2,3])
RuntimeError: Julia exception: MethodError(TestModule.myx2, (Any[1, 2, 3],), 0x0000000000005537)

(The python interpreter that comes with my Ubuntu installation produces a Segmentation fault)

One can also reproduce this error by just copying 2 lines from StaticArrays:

module TestModule
# The error above can also be reproduced by just including these two lines from StaticArrays.jl
# from StaticArrays/src/StaticArrays.jl
abstract type StaticArray{S <: Tuple, T, N} <: AbstractArray{T, N} end
# from StaticArrays/src/convert.jl:3
@inline (::Type{SA})(x...) where {SA <: StaticArray} = SA(x)

myx2(x)  = x.^2

export myx2
end

In particular it is the conversion operation (::Type{SA})(x...) which generates this MethodError error.
I am using pyjulia current as of today (last update Fri Jun 16 22:59:09 2017, commit d01b42b).
229 packages depend on StaticArrays. It is possible that this issue affect other packages as well.

Any help would be greatly appreciated.

@TsurHerman
Copy link
Contributor

TsurHerman commented Jul 19, 2017

This is a world age issue probably(I infer that from the MethodException type) but not sure.

a minimal working example not including StaticArrays

import julia

j = julia.Julia()
j.eval("abstract type foo end; (::Type{T})(x...) where T <: foo  = 5")

f = j.eval("f(x) = 2*x")
g = f(2)

since eval just calls jl_eval_str ,I guess this is probably a bug in other embeddings of Julia

my personal workaround is to avoid using the jlwrap objects and to just eval everything
this works:
g = j.eval("f(2)")

@Alexander-Barth
Copy link
Author

Thank you for your comment. However in my case, I have to pass a lot of data. I don't think that I can use j.eval here.

I did not know initially what you mean by world age issue. It seems hover, that you are referring to issues like these: JuliaLang/julia#21412
However, I do not see an error message like The applicable method may be too new: running in world age ....

@TsurHerman
Copy link
Contributor

TsurHerman commented Jul 20, 2017

I deduce this from this issue
and from this code running in repl Juno :

f(x) = x;
f(2);
sprint(Base.showerror, MethodError(f, (2,), 0x0000000000005537))

Please follow up on this thread if you find a proper solution, this is very frustrating.

@ihnorton
Copy link
Member

Thanks for the minimal reproduction examples to make this easier to understand. I proposed a fix in PyCall:

JuliaPy/PyCall.jl#416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants