Skip to content

Commit 5511475

Browse files
authored
Build python virtual environments. (#249)
build python virtual environments
1 parent c566b94 commit 5511475

File tree

22 files changed

+369
-138
lines changed

22 files changed

+369
-138
lines changed

.github/workflows/build_macOS.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
export HPC_COMPILER="${{ matrix.compiler }}/${gcc_ver}"
4949
export HPC_MPI="${{ matrix.mpi }}/${mpi_ver}"
5050
export HPC_PYTHON="python/${python_ver}"
51-
./build_stack.sh -p $prefix -c config/config_mac.sh -y config/stack_mac.yaml
51+
./build_stack.sh -p $prefix -c config/config_mac.sh -y stack/stack_mac.yaml
5252
5353
- name: Upload logs
5454
if: ${{ always() }}

.github/workflows/build_ubuntu.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
export HPC_COMPILER="gnu/${gnu_ver}"
5151
export HPC_MPI="${{ matrix.mpi }}/${mpi_ver}"
5252
export HPC_PYTHON="python/${python_ver}"
53-
./build_stack.sh -p $prefix -c config/config_custom.sh -y config/stack_custom.yaml
53+
./build_stack.sh -p $prefix -c config/config_custom.sh -y stack/stack_custom.yaml
5454
5555
- name: Upload logs
5656
if: ${{ always() }}

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ some of the parameter settings available.
102102
- **MAKE_VERBOSE:** Print out extra information to the log files during the build
103103

104104
The next step is to choose what components of the stack you wish to
105-
build. This is done by editing the file `config/stack_custom.yaml`
105+
build. This is done by editing the file `stack/stack_custom.yaml`
106106
which defines the software packages to be built along with their
107107
version, options and compiler flags along with other package specific
108108
options.
@@ -174,10 +174,13 @@ script.
174174
- [EMC_post](https://github.com/noaa-emc/EMC_post.git)
175175

176176
* JEDI Dependencies
177-
- [ecbuild](https://github.com/jcsda/ecbuild.git)
178-
- [eckit](https://github.com/jcsda/eckit.git)
179-
- [fckit](https://github.com/jcsda/fckit.git)
180-
- [atlas](https://github.com/jcsda/atlas.git)
177+
- [ecbuild](https://github.com/ecmwf/ecbuild.git)
178+
- [eckit](https://github.com/ecmwf/eckit.git)
179+
- [fckit](https://github.com/ecmwf/fckit.git)
180+
- [atlas](https://github.com/ecmwf/atlas.git)
181+
182+
* Python Virtual Environments
183+
- [r2d2](https://github.com/jcsda-internal/r2d2.git)
181184

182185
**IMPORTANT: Steps 1, 2, and 3 need to be repeated for each
183186
compiler/MPI combination that you wish to install.** The new
@@ -270,7 +273,7 @@ default is to use `$HOME/opt` and `config/config_custom.sh`
270273
respectively. `<yaml>` represents a user configurable yaml file
271274
containing a list of packages that need to be built in the stack along
272275
with their versions and package options. The default value of `<yaml>`
273-
is `config/stack_custom.yaml`.
276+
is `stack/stack_custom.yaml`.
274277

275278
## Additional Notes:
276279

@@ -303,9 +306,11 @@ template
303306
2. define a new section in the `yaml` file for that library/package in
304307
config directory
305308

306-
3. Add a call to the new build script in `build_stack.sh`
309+
3. if the package is a python virtual environment, add a `requirements.txt` file listing the python packages required to install the package in `pyvenv/package_name.txt`
310+
311+
4. Add a call to the new build script in `build_stack.sh`
307312

308-
4. Create a new module template at the appropriate place in the
313+
5. Create a new module template at the appropriate place in the
309314
modulefiles directory, using exising files as a template
310315

311316
### Configuring for a new HPC

build_stack.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ usage() {
3333
library=""
3434
export PREFIX="$HOME/opt"
3535
config="${HPC_STACK_ROOT}/config/config_custom.sh"
36-
yaml="${HPC_STACK_ROOT}/config/stack_custom.yaml"
36+
yaml="${HPC_STACK_ROOT}/stack/stack_custom.yaml"
3737
export MODULES=false
3838

3939
while getopts ":p:c:y:l:mh" opt; do
@@ -151,11 +151,6 @@ build_lib nco
151151
build_lib cdo
152152
build_lib pio
153153

154-
# UFS 3rd party dependencies
155-
156-
build_lib esmf
157-
build_lib fms
158-
159154
# NCEPlibs
160155

161156
build_lib bacio
@@ -183,6 +178,14 @@ build_lib prod_util
183178
build_lib grib_util
184179
build_lib ncio
185180

181+
# Other
182+
183+
build_lib madis
184+
185+
# Python virtual environments
186+
187+
build_lib r2d2
188+
186189
# JEDI 3rd party dependencies
187190

188191
build_lib boost
@@ -196,15 +199,17 @@ build_lib json
196199
build_lib json_schema_validator
197200
build_lib pybind11
198201

199-
# JCSDA JEDI dependencies
202+
# JEDI dependencies
200203

201204
build_lib ecbuild
202205
build_lib eckit
203206
build_lib fckit
204207
build_lib atlas
205208

206-
# Other
207-
build_lib madis
209+
# UFS 3rd party dependencies
210+
211+
build_lib esmf
212+
build_lib fms
208213

209214
# ==============================================================================
210215
# optionally clean up

config/config_mac.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Compiler/MPI combination
44
export HPC_COMPILER="clang/12.0.5"
55
export HPC_MPI="mpich/3.3.2"
6-
export HPC_PYTHON="python/3.9.4"
6+
export HPC_PYTHON="python/3.9.5"
77

88
# Build options
99
export USE_SUDO=N

cron-ci/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Set these variables in `setup-cron.sh`
2323

2424
* HPC_CONFIG - Custom config so compiler/MPI and other options can be set
2525

26-
* HPC_STACK_FILE - The yaml file that specifies which libraries and versions to build. Default to config/stack_noaa.yaml
26+
* HPC_STACK_FILE - The yaml file that specifies which libraries and versions to build. Default to stack/stack_noaa.yaml
2727

2828
* LOG_PATH - The path to write logs to. Defaults to HPC_HOMEDIR/logs.
2929

3030
* HPC_MACHINE_ID - Name of machine (hera, orion, gaea, etc).
31-
This is used to edit the correct modules in ufs-weather-model/machine.compiler
31+
This is used to edit the correct modules in ufs-weather-model/machine.compiler
3232

3333
* TEST_UFS - Run ufs-weather-model regression tests. Defaults to true.
3434

cron-ci/setup-cron.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export HPC_DOWNLOAD_PATH=
1515
# I put these in the HPC_HOMEDIR
1616
export HPC_CONFIG=${HPC_HOMEDIR}/
1717
# hpc-stack yaml file to build with, use stack_noaa by default
18-
export HPC_STACK_FILE=config/stack_noaa.yaml
18+
export HPC_STACK_FILE=stack/stack_noaa.yaml
1919

2020
# set machine name (hera, jet, orion, etc) so script edits correct ufs modulefiles
2121
export HPC_MACHINE_ID=
@@ -74,7 +74,7 @@ echo ""
7474

7575
./cron-ci/build-hpc-stack.sh >> ${hpc_log} 2>&1
7676

77-
# check if hpc-stack build succeded
77+
# check if hpc-stack build succeded
7878
if grep -qi "build_stack.sh: SUCCESS!" ${hpc_log}; then
7979
echo "hpc-stack build: PASS"
8080
else

libs/build_pyvenv.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
name=$1
6+
7+
var="STACK_${name}_version"
8+
set +u
9+
stack_version=${!var}
10+
set -u
11+
version=${2:-$stack_version}
12+
13+
var="STACK_${name}_requirements"
14+
set +u
15+
stack_rqmts=${!var}
16+
set -u
17+
rqmts=${stack_rqmts:-"requirements.txt"}
18+
19+
python=$(echo $HPC_PYTHON | sed 's/\//-/g')
20+
21+
if $MODULES; then
22+
set +x
23+
source $MODULESHOME/init/bash
24+
module load hpc-$HPC_PYTHON
25+
module list
26+
set -x
27+
prefix="${PREFIX:-"/opt/modules"}/$python/$name/$version"
28+
if [[ -d $prefix ]]; then
29+
[[ $OVERWRITE =~ [yYtT] ]] && ( echo "WARNING: $prefix EXISTS: OVERWRITING!";$SUDO rm -rf $prefix ) \
30+
|| ( echo "WARNING: $prefix EXISTS, SKIPPING"; exit 1 )
31+
fi
32+
else
33+
nameUpper=$(echo $name | tr [a-z] [A-Z])
34+
eval prefix="\${${nameUpper}_ROOT:-'/usr/local'}"
35+
fi
36+
37+
# Determine python version; 3.x
38+
python_version=$(python3 -c 'import sys;print(sys.version_info[0],".",sys.version_info[1],sep="")')
39+
40+
# Support python version >= 3.6
41+
min_python_version=3.6
42+
if (( $(echo "$min_python_version >= $python_version" | bc -l) )); then
43+
echo "Must have python version ($python_version) >= ${min_python_version}. ABORT!"
44+
exit 1
45+
fi
46+
47+
# Check for requirements file
48+
rqmts_file=${HPC_STACK_ROOT}/pyvenv/$rqmts
49+
[[ ! -f $rqmts_file ]] && ( echo "Unable to find requirements file: $rqmts \nABORT!"; exit 1 )
50+
51+
# for python >= v3.9, upgrade dependencies (pip, setuptools) in place with '--upgrade-deps'
52+
upgrade_deps=""
53+
if (( $(echo "$python_version >= 3.9" | bc -l) )); then
54+
upgrade_deps="--upgrade-deps"
55+
fi
56+
57+
# Create a new virtual env.
58+
python3 -m venv --prompt $name $upgrade_deps $prefix
59+
60+
# Activate newly created virtual env.
61+
set +x
62+
source $prefix/bin/activate
63+
set -x
64+
65+
# Upgrade pip
66+
pip install --upgrade pip
67+
68+
# Install packages from $rqmt_file
69+
pip install --no-cache-dir -r $rqmts_file
70+
71+
# List installed packages
72+
pip list
73+
74+
# generate modulefile from template
75+
$MODULES && update_modules python $name $version $python_version
76+
echo $name $version $rqmts_file >> ${HPC_STACK_ROOT}/hpc-stack-contents.log

modulefiles/core/hpc-cray-python/hpc-cray-python.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ load(python)
1717
prereq(python)
1818

1919
local opt = os.getenv("HPC_OPT") or os.getenv("OPT") or "/opt/modules" or "/opt"
20-
local mpath = pathJoin(opt,"modulefiles","cray-python",pkgVersion)
20+
local mpath = pathJoin(opt,"modulefiles/python","cray-python",pkgVersion)
2121
prepend_path("MODULEPATH", mpath)
2222

2323
whatis("Name: ".. pkgName)

modulefiles/core/hpc-miniconda3/hpc-miniconda3.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ load(python)
1717
prereq(python)
1818

1919
local opt = os.getenv("HPC_OPT") or os.getenv("OPT") or "/opt/modules"
20-
local mpath = pathJoin(opt,"modulefiles/core","miniconda3",pkgVersion)
20+
local mpath = pathJoin(opt,"modulefiles/python","miniconda3",pkgVersion)
2121
prepend_path("MODULEPATH", mpath)
2222

2323
whatis("Name: ".. pkgName)

0 commit comments

Comments
 (0)