bcdev / jpy

A bi-directional Python-Java bridge used to embed Java in CPython or the other way round.
Apache License 2.0
187 stars 37 forks source link

Request for input for JPype #183

Open Thrameos opened 3 years ago

Thrameos commented 3 years ago

I am the lead developer for JPype. As one of the fellow bridge projects I wanted to drop by to see if there are unserved needs to be addressed in the Python/Java community. Thus far there hasn't been a lot of conflicts between these two projects but I will be adding new capabilities that put them more on a collision course. SO just like the PyJNIus project, I thought it would be a good idea to get the discussion started.

JPype is currently only a forward bridge presenting Java to Python, but I will be adding a reverse bridge to allow Java to execute Python code in the near future. JPype has been very much focused on providing a high quality native Python like interface to Java classes. Over the past 2 years I have been working primarily in the backend to make the core rock solid stable, deal with leaks, and boost performance for scientific coding. I am trying to design the reverse bridge to be much the same in which Python classes have as much of a native feel in Java as possible and can be customized to allow packages like numpy, scipy and matplot lib to be used in a very native like fashion. This means the JPype solution will be doing code analysis of Python classes to probe their capabilities and then use a code generator to mixin Java interfaces to create a Java class that best represents the abilities of the class (Number like, List like, Dictionary like). This will allow Python classes to be operated on by Java using the collections libraries and such. This makes use a lot of Java ASM for code generation. I believe this is likely a different approach than JPY.

As I am working to develop the reverse bridge, I am looking at JPY to understand how other reverse bridges are presenting Java concepts. Unfortunately the documentation on this project seems pretty underwhelming so it seems like I need to recruit some JPY users to help give me a prospective on how they feel Python should be presented in Java. The other collaboration source being Jython, but as they are actually implementing rather than just providing a view it is difficult to see it as giving a native feel.

I see there has been some progress on this project in terms of commits over the past few years but I also see outstanding pull requests running back 2 years in times. How active is this project? Are there users who are in need of an alternative? Is there anyone willing to participate in the evaluation and review process for a potential alpha quality reverse bridge over the next 6 months? How do you see an ideal presentation of Python objects in Java?

forman commented 3 years ago

Hi @Thrameos, thanks for your feedback! Although the project is currently not very active it is still alive and jpy is still in heavy use. Our use case is the satellite data processing software SNAP, that we develop for ESA, see snap-python.

Our whole team feels very sorry about not being able to respond to PRs and issues in a timely, (cough!) ok, adequate manner. There have also been offers from skilled people to help maintaining the project. But we fear that jps`s further development would diverge from our own core requirements, which originate from efficient array data processing using Python numpy and the like using native Java array in-memory references.

I'd really like to promise improving jpy's documentation and deal with its issues in a proper way, but we are all currently occupied by other work. This may change again in the future. However, I can offer to explain some of the jpy concepts to you, and provide some core requirements that may be helpful for your implementation. Btw, we are not reluctant of using a robust, alternate bi-directional bridge one day, i.e. JPype. We developed jpy, because there was no such software at that time.

Thrameos commented 3 years ago

JPype also specializes in high speed transfer of buffers and arrays. As a scientist trying to provide a bridge for a group of physists that has been a major requirement. Though as a unidirectional bridge this is mainly to allow Java buffers and arrays to be used in numpy rather than the other way around. I also implemented exporting of Python buffers to Java. But write through sharing of memory is limited by the JNI. It is a shame that you cant create locked native arrays.

Perhaps you can lay out some of the requirements that jpy as sample code you would like to be able to run. I may already be close on some areas.

Thrameos commented 3 years ago

Perhaps I should begin by laying out JPype requirements so that we can see what is covered and what items you would add. If you read a blog post on the topic of Python/Java bridges, one could get the idea that all the projects do the same thing (JPype, JEP, JPY, PyJNIus, ...). But as they all have different implementations and different goals, (and in many cases poor documentation) it is really hard to distinguish them without getting down to a requirements/specification list. Unfortunately the other side effect of so many bridges is a divided user community and poor ability to address user needs. Hence my desire to reach out an olive branch to the other bridges to find out what about the needs that I don't understand. Some like Py4J serve a very different purpose and thus will always need to be separate, while others are just duplicative efforts which would be best to be merged.

So I will put down what I believe JPype requirements are and you can copy and paste it to mark down JPY requirements, add to the list etc. Not every JPype requirement has been realized so I will check those that we have and leave those that I see as goals unchecked.

JPype requirements/specifications are as follows. General:

Python to Java:

Java to Python:

If you can be so kind as marking up JPY requires/specification or putting down items that you feel JPype is missing, it would go a long way to helping me define what I need to achieve in a reverse bridge.