-
Notifications
You must be signed in to change notification settings - Fork 189
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
RFC: Lazier and more interface-based conversion #617
Comments
I'm in favor of making pyjlwrap more full-featured and being at least somewhat more conservative about automatic conversions, although the exact boundaries are debatable. |
Good to know! I'll look into Python C API to translate what I did to Julia/PyCall code. |
Is there anything I can help here? If this will happen soon (say, within a few months), I'd like to make it as soon as possible for some reason. |
The roadmap is explained in #629. This feature would be a breaking change so I think we need to wait until 2.0. Currently I think there is just one issue #636 before releasing 1.19. My understanding is that, once 1.19 is released, we can start implementing it. But I'm not super confident that this can happen in a few months. Sorry about non-definitive answer... |
So #636 is now closed and 1.19 would probably be released soon. But I think the only type of human resources required here is the ones who write the code (I know it's a bit harsh to say but that's kind of always true in OSS...). I'm not working on it right now and I guess there are no one else. If you want to implement it please go ahead and do it. I think there are some useful code in my PyBase.jl so I can point to how to integrate that. By the way, I always assume that @stevengj wants to use C-API for implementing it. If using Python "shim" class as I did PyBase.jl is OK, adding this feature would be pretty easy (basically just copying the code from PyBase.jl). So convincing him to go to this direction, maybe at least for the first implementation, is another way to speed it up. (But using C-API may not be so hard. It's just that how difficult it would be is more uncertain to me.) |
Thanks, maybe I need to familiarize myself with the code of PyCall.jl. I've glanced over PyBase.jl and found that approach is really elegant and promising! I'm going to spare my time to understand more about these two packages this weekend. |
@marius311 Answering your comments in #676
This probably would work (not 100% certain as it's a C API) but it would need to create a Python callable object so it wouldn't be as efficient as it can be. If we want to squeeze out performance, we may need to use https://docs.python.org/3/c-api/typeobj.html#number-object-structures But we can also start from slow implementation based on PyBase.jl and try to make it correct by adding tests as much as possible first. See my previous comment #617 (comment) |
@stevengj Are you OK with start implementing this feature based on Python shim class as in PyBase.jl? That is to say, having a Python class with a bunch of methods like this: def __add__(self, other):
return self.__add(self.__jlwrap, other)
def __sub__(self, other):
return self.__sub(self.__jlwrap, other)
def __mul__(self, other):
return self.__mul(self.__jlwrap, other)
def __matmul__(self, other):
return self.__matmul(self.__jlwrap, other) where We can always move things to use C API after implementing enough test set to make sure the implementation gets the right semantics. |
I started looking at what it would take to solve #507, which eventually led to this issue. For what it's worth I think the PyBase approach looks very promising and I'd prefer to wait for that rather than solving these various issues independently. |
I just discussed with @stevengj in hackathon. He prefers to avoid indirection (Python shim class) and implements everything using C API. |
Is this being actively worked on? If not, I have started adding some methods to |
I think nobody is working on it. It would be great if you can send a PR. |
Ok I'll work on it. |
I have just made a PR for jlwrap. On the topic of automatic conversion, my two cents is:
|
Is there any progress on this so far? I'm having performance problems when working with sparse arrays and I think this might be the cause. |
Rather than trying to convert and copy values between Python and Julia, I propose to:
Enhance
pyjlwrap
and implement most of Python data model such that virtually all Julia values are usable withpyjlwrap
. For example, we can translategetindex
to__getitem__
etc. such that we can use anAbstractArray
without translating it to a Numpy array. We can also implement__array__
in Julia side to makenumpy.asarray
fast.Restrict automatic conversion to Julia types which supports ("practically") lossless round-trip (Julia -> Python -> Julia). Maybe something like:
Here is a reference implementation that shows this approach works: https://github.com/tkf/PyBase.jl
It would solve, e.g.,:
#11
#175
#507
#555
#616
JuliaPy/PyPlot.jl#391
JuliaPy/PyPlot.jl#400
JuliaPy/pyjulia#122
JuliaPy/pyjulia#123
SciML/diffeqpy#21
There are many details that can be refined (e.g., rather than using a single Python class, maybe define a few base class? Or even create Python class on-demand?) but first I'd like to know if it is a reasonable direction for PyCall.jl.
The text was updated successfully, but these errors were encountered: