data-science

Data science, data analysis, and machine learning in Clojure https://scicloj.github.io/pages/chat_streams/ for additional discussions
whilo 2020-05-24T03:34:55.248700Z

Hey. I have done some simple warmup tests to talk to Julia through libpython-clj (basically using pyjulia), but could not get it to work. I am interested in having a libpython-clj style interface to Julia. Has anybody worked in this direction yet?

2
whilo 2020-05-24T09:56:56.249500Z

Yes, I took a look at that and I am aware of the C bits. I think the tricky part is to map memory layouts between Clojure and the type signatures of Julia. @chris441 I have heard that you have already thought about this?

phronmophobic 2020-05-24T16:58:05.250200Z

that’s what jna helps you do

whilo 2020-05-24T20:06:25.250400Z

yes. are you working with it?

phronmophobic 2020-05-24T20:15:28.250600Z

I’ve been using JNA to integrate with c libraries, but not julia

phronmophobic 2020-05-24T20:19:44.250800Z

I’ve been using jna via https://github.com/Chouser/clojure-jna/, but it looks like libpython-clj uses their own clojure wrapper over jna, https://github.com/techascent/tech.jna

chrisn 2020-05-29T13:07:07.252900Z

@whilo - I am down to work with someone to take a crack at it. I also want to see julia access from Clojure but i havent put any real time in.

chrisn 2020-05-29T13:38:02.253200Z

I think it is doable, I think it is a moderate amount of work, and I think Julia is really visionary with a lot to offer.

chrisn 2020-05-29T13:52:24.253400Z

Another tack you could take would be Clojurists together funding. But my assumption is that it will take some pretty in-depth C knowledge as did libpython-clj.

whilo 2020-05-29T19:07:47.254Z

Right, that makes sense. I think it would be cool if it would be integrated with pyjulia as well, so you can share the same objects between Python and Julia, effectively being able to mix and match libraries from Clojure. Do you think this would be feasible?

chrisn 2020-05-30T00:10:07.254500Z

The best way to do that is to use pyjulia. Maybe file an issue with and we can look at it. Bespoke bindings would be best in the siruation where you do not want python involved.

chrisn 2020-05-30T15:13:49.254700Z

I just tried pyjulia and it isn't stable when used via python-clj. That should be an issue like I said but tracking it down may be really tough. This is why bindings to julia that don't involve python would be wise if we really want have julia in the ecosystem.

chrisn 2020-05-30T16:10:56.254900Z

Julia also isn't stable itself when loaded via jna. It fails on the initialize call. Julia support for the JVM appears to be a research project at this point. =

chrisn 2020-05-30T19:18:04.255100Z

Got past the intialize code if I use the binary distribution from http://julia.org and not the system installation. Still crashes on shutdown but I can run strings. It isn't clear that you can, for instance, register a foreign function although the pathway for that may be using the julia system to 'find' the function...

whilo 2020-06-03T04:13:37.255700Z

@chris441 Hmm, interesting. Is your code for this experiment somewhere?

whilo 2020-06-03T04:20:58.255900Z

That sounds already useful enough to play around and try out deeper integrations.

chrisn 2020-06-05T23:15:24.288400Z

https://github.com/cnuernber/julia-clj. It will always crash given time. Unless we get help from the julia team this can't go anywhere. The use stack manipulations that are incompatible with the JVM. I filed an issue on this that didn't get a response; the next step is to compile julia with some custom flags and see if that mitigates or eliminates the issue.

phronmophobic 2020-06-05T23:18:16.289800Z

are you hanging onto return values referenced from the clj side?

phronmophobic 2020-06-05T23:18:48.290100Z

otherwise, the jvm will think noone is using those values and garbage collect them

phronmophobic 2020-06-05T23:20:35.290300Z

oh didn’t realize you had also worked on libpython-clj and probably run into a million of those issues. nvmd. :homerdisappear:

chrisn 2020-06-07T14:17:04.296200Z

Yep, and this is simple calling `jl_init__threading` which doesn't return anything and then calling System/gc a few times_._ Once `jl_init__threading` is called *for sure* the jvm will crash at some undefined time in the future. My current guess is this is because Julia does something really fancy with stack frames and so does the jvm. This may have to come in via graal native and currently our entire ml stack would need to be changed somewhat to support graalnative so I am not in a rush to go there.

phronmophobic 2020-06-07T17:08:54.297800Z

the other type of crash I’ve seen when creating bindings for exotic libraries is issues with both environments adding signal handlers. see https://bitbucket.org/chromiumembedded/java-cef/issues/355/crash-on-cef-init-due-to-signal-handlers for an example. julia does have handlers for SIGBUS, SIGSEGV, but I’m not sure if this is related to the crash you’re seeing or is a problem in this case.

phronmophobic 2020-06-07T17:11:16.298300Z

I found this java library that provides embedded julia bindings https://github.com/rssdev10/julia4j . if I have some time, it would be interesting see if they run into the same issues, and if not, maybe that will provide a clue as to workaround. however, just browsing through the code seems like they aren’t doing anything special.

phronmophobic 2020-06-07T17:17:37.298700Z

this also looks interesting, https://github.com/JuliaInterop/JavaCall.jl

whilo 2020-06-12T00:04:48.317Z

@smith.adriane I think julia4j is mostly using Swig bindings and is not doing anything beyond that. I assume that integrating the GCs properly will be a lot more work. Thanks for the pointer about signal handlers.

phronmophobic 2020-06-12T00:06:30.318800Z

i thought the issue was whether julia and the jvm could even share the same process without stepping on eachothers toes. if the swig bindings work, then it seems like that is at least possible

whilo 2020-06-12T00:06:38.319Z

@chris441 Thanks, playing with your repo now. Where did you post the issue?

whilo 2020-06-12T00:06:59.319300Z

I see, I have not tried the Swig bindings.

phronmophobic 2020-06-12T00:08:42.319900Z

me neither. they might have the same problem

phronmophobic 2020-05-24T04:46:00.249100Z

libjulia has support for embedding, so you could access julia using jna (the same way libpython-clj accesses python), https://docs.julialang.org/en/v1/manual/embedding/index.html

phronmophobic 2020-05-24T04:46:33.249300Z

it would probably be helpful to be comfortable in C if you were going to go down this path