Save module/function using PackageCompiler

Is it possible to save the compiled version of a function, f, which is not in a package, using PackageCompiler? For example, suppose I have a file model.jl which contains:

module Model
  include("func.jl")
end

f(rand(2,2))

where func.jl contains the julia code for a function f. I would really like to be able to save the compiled version of f for reuse in some downstream application. Is this possible?

Longer story of where this comes from: I am using FastDifferentiation to generate the jacobian of a large system of equations. This jacobian takes a few hours to calculate, and the resultant function takes another few hours to compile when you call it first. I would like to be able to reuse this compiled function across many different independent Julia processes. Right now I use FastDiff to generate an expression of this function, which I then save as a file (hence the file func.jl in the example). This works great in the repl, but I am so far unable to save the compiled function :confused:

Any help would be appreciated!

Wow, a few hours for differentiation? Have you given other autodiff systems a try?

I’m the author of FastDifferentiation.jl. My experience has been that computing the symbolic derivative is generally pretty fast, even for fairly big functions.

But, compiling the code to an executable can get really slow when the symbolic derivative transforms to a julia function that is a hundred thousand lines of code or more. The LLVM compiler takes a long time compiling programs that big.

If it’s the compilation stage that’s not something I can fix. But It is possible there is a bug in FastDiff that is slowing things down. If you can share your code I’ll look at it to see if it can be sped up.

1 Like