-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_pkg.qmd
124 lines (86 loc) · 3.2 KB
/
05_pkg.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: "Managing Julia packages on HPC"
engine: knitr
---
## Overview
Installing a package in Julia includes two steps (1) downloading (2) pre-compiling.
In a laptop, both are done in one shot using
```julia
]
activate experiment_repo/julia_env
add NameOfPackage
```
In an HPC setup, step (2) requires computational effort hence is best done in compute node. However
in some HPC setups such as Sockeye, compute nodes do not have internet access, so the
process needs to be split. We cover here some utilities that facilitate this.
## Julia environment
A Julia environment is a specification of all package
dependencies and their versions.
By convention, we will store it in a
directory called `experiment_repo/julia_env`.
## Adding a package
There are two syntaxes in Julia to install packages: the
interactive Julia package manager or using programmatic Pkg
syntax. We cover both below.
In both syntaxes, we first need to tell Julia which environment
to use. This is called "activating" an environment.
### Interactive Julia package manager
The most common method is to use the interactive Julia package
manager. To start it, type `]` followed by `enter`.
Activating is done with the `activate` keyword.
You can then add a package using the `add` command. The argument of
`add` can be either a registered Julia package, for example
we show here how to add the
[Pigeons package](https://github.com/Julia-Tempering/Pigeons.jl)
for MCMC sampling:
```julia
ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0 # Hold off precompile since we are in login node
]
activate experiment_repo/julia_env
add Pigeons
```
Alternatively, the package can be a git repository, optionally with a specific
commit/tag:
```julia
add Example#master
add Example#c37b675
add https://github.com/JuliaLang/Example.jl#master
add [email protected]:JuliaLang/Example.jl.git
add "[email protected]:JuliaLang/Example.jl.git"#master
add https://github.com/Company/MonoRepo:juliapkgs/Package.jl
```
To exit the interactive Julia package manager, type `control-C`.
### Programmatic interface
Alternatively, a programmatic interface is also available
for scripting:
```{julia output = F}
ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0 # Hold off precompile since we are in login node
using Pkg
Pkg.activate("experiment_repo/julia_env")
Pkg.add("Pigeons")
```
## Precompilation on HPC
Once we have downloaded the packages in the login node,
we now turn to the task of performing pre-compilation.
```{bash}
cd experiment_repo
./nextflow run nf-nest/pkg.nf -profile cluster
```
Optionally, you can append an argument to
specify the number of threads
to request and use during pre-compilation: e.g. add `--nPrecompileThreads 20`
to request 20 threads instead of the default of 10.
## Testing your Julia environment interactively
In the code above, we have added the package
[Pigeons](https://github.com/Julia-Tempering/Pigeons.jl) as an example.
To interactively test an installed package, simply activate the
environment from a Julia session:
```{julia output = F}
using Pkg
Pkg.activate("experiment_repo/julia_env")
using Pigeons
pigeons(target = toy_mvn_target(1000))
```
## More information
See [Pkg.jl documentation](https://pkgdocs.julialang.org/v1/).