JuliaPy / JuliaPy/PyCall.jl

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

未关闭
#968 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Julia
星标
1.5k
派生
186
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

这个仓库没有索引到贡献指南

调研方向

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.

由索引模型根据 Issue 内容生成。

评估

技术栈
julia, python
领域
developer-experience
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。