In Julia, how one can generate arbitrary code to serialize it into a file for future execution under completely different program instance? Is it even possible? Is there a need to store any current context for future execution?
In Julia, how one can generate arbitrary code to serialize it into a file for future execution under completely different program instance? Is it even possible? Is there a need to store any current context for future execution?
Here is a more detailed answer
Put your code in a Julia package. This is something you should do with any production code - it is so much more convenient. Let say it is MyPackage
Create a script that runs all methods in the package with types that you plan to use so the compiler knows which version of those methods to compile. Let us call it precompile_MyPackage.jl. You could use commands/scenarios that you use regularly plus perhaps test sets from MyPackage.
Compile the package using PackageCompiler
using PackageCompiler
create_sysimage(:MyPackage, sysimage_path="sys_MyPackage.so", precompile_execution_file="precompile_MyPackage.jl")
julia --sysimage sys_MyPackage.so
Finally, please have a look at the excellent tutorial video https://live.juliacon.org/talk/Z8TE39