Calling Julia from Python without severe startup

Hello!

I’m writing this issue because when I googled around this issue, I found a few different solutions, and all of them have been either painful or slow. Hopefully a discoverable thread with the details of how we are able to use Julia from Python without incurring severe startup times, whilst still having a decent development loop will exist now.

My usecase is a Qt GUI app, created with the PyQt interface. This app is showing some information which is gathered from a file and some plots of a simulation which is running in Julia when the app starts.

It seems like Julia should be a good language for this. The simulations have been generally pleasant to write, and run efficiently once they are compiled.

At the moment, in the app (in an imported python file), we use the pattern

import juliacall
jl = juliacall.newmodule("MyModulePy")
jl.seval("""
using PythonCall
using MyModule
""")

where MyModule is the module containing the simulations. We then call the simulations with jl.MyModule.simulation_function(args).

Doing some naive logging of timing, I get

Juliacall is imported in  2.652151107788086
Juliacall starts in 1.3792328834533691
The using statements took 2.039438247680664

The JIT compilation of the simulations takes a significant amount of time (20+ seconds). I’m aware that starting Julia with a sysimage of the simulation module can improve this significantly.

What’s the right way to improve the time taken for these steps, especially the startup of juliacall?

1 Like

Use GitHub - Suzhou-Tongyuan/jnumpy: Writing Python C extensions in Julia within 5 minutes. and Home · PrecompileTools.jl .

If you make your module a package and add instructions for precompilation you might be able to move most of that time to the installation process only.

This looks like malware.

The discourse spam filter thought so too. It’s indeed very odd.

In the context of juliacall, as a first pass, I’d use PackageCompiler to create a sysimage along with the -X juliacall-sysimage=<file> flag.

1 Like