IJulia notebook using a system image?

I’m starting to explore using notebooks for teaching (econometrics) purposes. There are some nice resources out there to steal ideas from, for example,

Perusing those, I think that my students might like this approach.

So far, I have been using scripts. I can run then from the REPL or from vscode, and in both cases, I can easily use a custom system image which has many packages and warmup code precompiled for instant access.

I am able to use my code in an IJulia jupyter notebook. However, I don’t see any way of making the Jupyter kernel use my Julia system image, so I don’t get the nice “instant on” experience. Is it possible to make jupyter use a custom system image?

Just register a kernel - I haven’t tried this but starting your sysimage and doing ]build IJulia should work. Otherwise you can register a kernel from the package itself. This is what I do to get a kernel with four threads:

julia> using IJulia

julia> installkernel("Julia (4 threads)", env = Dict("JULIA_NUM_THREADS" => "4"))

I don’t see any way of making the Jupyter kernel use my Julia system image

This is what I wrote up for my students to do exactly that:


Thanks to both. So far, I haven’t quite got it to work, but it’s good to know it’s possible. I will summarize what I come up with.

Well, no luck so far. I have made some kernels appear as options in IJulia, but they fail to start. With other experiments, the notebook() command fails. The system image I’m trying to use is large, about 500MB. Perhaps that’s too large? Also, the image has MKL.jl built in. Maybe that’s not good?

I changed my file to use both Plots and MKL, and it works well. (The size of this sysimage is around 250 MB.) May I suggest that you start with something simple and then add a few packages at a time?

Btw. for what sort of problems do you find MKL useful? (In my own experiments the speedup is rather modest.)

I must have messed something up in the course of my trials. I am now playing around with Neptune.jl, which seems a lot simpler to install. I need something that I’m confident that the students will be able to install on their own computers without too many headaches. Getting them to the Julia REPL is not a problem. From the REPL to Neptune seems pretty easy, after a morning of playing around.

Regarding MKL, I haven’t done any real measurements. I’m going to drop it from the package for the students, it’s certainly not needed there.

Note that a custom sysimage will silently override the dependency manager. As the documentation says:

The biggest drawback is that packages that are compiled into a sysimage (including their dependencies!) are “locked” to the version they were at when the sysimage was created. This means that no matter what package version you have installed in your current project, the one in the sysimage will take precedence. This can lead to bugs where you start with a project that needs a specific version of a package, but you have another one compiled into the sysimage.

So it takes some caution and discipline to make sure you don’t use incompatible dependencies, and to have reproducible results (since the package versions recorded in the project files might not be correct).

Personally I find it too dangerous to use with IJulia: once you install the kernel, it will be available globally as an option in all your projects. It’s very easy to pick the “wrong” kernel and boom! your project files are bypassed without you realizing.

Some people don’t mind the risk. In any case I thought it deserved a mention in this thread.

1 Like