Easy way to precompile all installed packages?

803 views
Skip to first unread message

Oliver Schulz

unread,
Feb 17, 2016, 6:58:10 AM2/17/16
to julia-users
Is there an easy way to precompile all installed packages, e.g. after a `Pkg.update()`?

This would come in handy when using a cluster of Julia machines (using an shared home dir on a network filesystem), to ensure precompilation is done before all machines load (and start precompiling) packages (e.g. from a shared home directory via a network filesystem).

Also, as precompilation of many packages can take quite a bit of time, it would be nice to be able to choose when it happens (i.e. right now, instead later when I may want to give a tutorial or so ;-) ).

Sorry if this is somewhere in the docs, I didn't find anything about it. I'd love to be able to just do `Pkg.update(precompile = true)` or so.


Cheers,

Oliver

Message has been deleted

Tom Lee

unread,
Feb 17, 2016, 8:00:31 AM2/17/16
to julia-users

I haven't tested this properly, but maybe something like:

req = split( open("$(Pkg.dir())/REQUIRE") do f ; readall(f);end , '\n' )
for pkgstr in req
    p = symbol(pkgstr)
   
@eval using $p
end


PS apologies for the incomplete post before. Very frustrating that typing <TAB> in a coding block, then <space> after that doesn't work leads to inadvertent posting...

Steven G. Johnson

unread,
Feb 17, 2016, 8:20:21 AM2/17/16
to julia-users
map(require, keys(Pkg.installed()))

Oliver Schulz

unread,
Feb 17, 2016, 10:13:22 AM2/17/16
to julia-users
Sure, that kinda works. Unfortunately, it doesn't include site-wide packages (resp. packages in LOAD_PATH). Is there a way to list all packages that are available to import/using?

On Wednesday, February 17, 2016 at 2:20:21 PM UTC+1, Steven G. Johnson wrote:
map(require, keys(Pkg.installed()))

Oliver Schulz

unread,
Feb 17, 2016, 10:15:16 AM2/17/16
to julia-users
Also, require gives a deprecation warning. ;-)

Oliver Schulz

unread,
Feb 18, 2016, 5:41:39 AM2/18/16
to julia-users
The best I've come up with so far is

for pkg in vcat(["IJulia"], collect(keys(Pkg.installed())))
   
if !isdefined(Symbol(pkg))
        info
("Importing $(pkg)...")
       
try (@eval import $(Symbol(pkg))) catch end
   
end
end

I had to manually add IJulia because it's installed site-wide (in my case). The try/catch prevents an abort if precompilation of a package fails (e.g. because Julia has to be reloaded, as happens with some packages). I found that I usually need to run this at least twice, from a clean state (empty ".julia/lib").

Tony Kelman

unread,
Feb 18, 2016, 7:07:07 AM2/18/16
to julia-users
Base.compilecache may be more reliable here.

Oliver Schulz

unread,
Feb 18, 2016, 7:33:49 AM2/18/16
to julia-users
But Base.compilecache compiles every time right, not just when necessary? So when looping over all packages after a "Pkg.update()", it would recompile everything,
no matter if outdated or not?

Jeremy Cavanagh

unread,
Feb 19, 2016, 1:43:53 PM2/19/16
to julia-users
Hi Oliver,

This is probably not what you are looking for, but, if you are using atom as an editor then you will recompile stale caches simply by 'Start Julia'. However, I suspect you are wanting to run some simple code in the REPL (I can't help you there).

I hope this may be of some assistance, but, one thing is clear from this. It can be done.

regards Jeremy

Steven G. Johnson

unread,
Feb 19, 2016, 4:30:17 PM2/19/16
to julia-users


On Thursday, February 18, 2016 at 7:33:49 AM UTC-5, Oliver Schulz wrote:
But Base.compilecache compiles every time right, not just when necessary? So when looping over all packages after a "Pkg.update()", it would recompile everything,
no matter if outdated or not?

Worse, compilecache will try to compile things regardless of whether they have been marked as precompile-safe.

Oliver Schulz

unread,
Feb 21, 2016, 2:17:02 PM2/21/16
to julia-users
I looks like this is indeed not something that the average user will be able to do with one or two commands (let alone do it cleanly). So how about adding something like
    
    Pkg.precompile()

I think it would be very useful - both for teaching/presentation situations and for running jobs on a compute cluster.

cdm

unread,
Feb 21, 2016, 5:03:30 PM2/21/16
to julia-users

a possible (non-Julia) solution:



good luck !
Reply all
Reply to author
Forward
0 new messages