JuliaPy / JuliaPy/PyCall.jl

TypeError("cannot pickle 'PyCall.jlwrap' object")

Đang mở
#968 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Julia
Star
1.5k
Fork
186
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi,

I'm trying to find a way to use the python package adaptive from Julia using PyCall, but I can't even get the simplest example working: https://adaptive.readthedocs.io/en/latest/tutorial/tutorial.Learner1D.html#tutorial-learner1d

```julia

using PyCall

adaptive = pyimport("adaptive")

f(x) = x*x
learner = adaptive.Learner1D(f, bounds=(-1, 1))
runner = adaptive.Runner(learner, goal=l -> l.loss() < 0.01 )
```

This gives the following error:

```
PyError ($(Expr(:escape, :(ccall(#= /home/user/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw)))))
TypeError("cannot pickle 'PyCall.jlwrap' object")
File "/home/user/.local/lib/python3.10/site-packages/adaptive/runner.py", line 527, in __init__
pickle.dumps(learner.function)

Stacktrace:
[1] pyerr_check
@ ~/.julia/packages/PyCall/L0fLP/src/exception.jl:62 [inlined]
[2] pyerr_check
@ ~/.julia/packages/PyCall/L0fLP/src/exception.jl:66 [inlined]
[3] _handle_error(msg::String)
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/exception.jl:83
[4] macro expansion
@ ~/.julia/packages/PyCall/L0fLP/src/exception.jl:97 [inlined]
[5] #107
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:43 [inlined]
[6] disable_sigint
@ ./c.jl:458 [inlined]
[7] __pycall!
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:42 [inlined]
[8] _pycall!(ret::PyObject, o::PyObject, args::Tuple{PyObject}, nargs::Int64, kw::PyObject)
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:29
[9] _pycall!
@ ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:11 [inlined]
[10] (::PyObject)(args::PyObject; kwargs::Base.Pairs{Symbol, var"#7#8", Tuple{Symbol}, NamedTuple{(:goal,), Tuple{var"#7#8"}}})
@ PyCall ~/.julia/packages/PyCall/L0fLP/src/pyfncall.jl:86
[11] top-level scope
@ In[15]:1
[12] eval
@ ./boot.jl:373 [inlined]
[13] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196
```

The python code in adaptive package throwing the error is this: https://github.com/python-adaptive/adaptive/blob/master/adaptive/runner.py#L527

So somehow, the adaptive package doesn't like the Julia function, because `pickle.dump` throws an error on it (is this a bug?). Are there any workarounds for using adaptive from Julia?

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Read adaptive/runner.py around line 527 and the PyCall src/pyfncall.jl and exception.jl entries in the stack trace; first reproduce the minimal Julia/Python example and inspect the pickle call. Done means establishing whether the reported interoperability failure is supported and recording a confirmed fix or workaround.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
julia, python
Lĩnh vực
developer-experience
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.