-
Notifications
You must be signed in to change notification settings - Fork 2
/
singularity_ngen.def
160 lines (136 loc) · 6.12 KB
/
singularity_ngen.def
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Bootstrap: docker
From: rockylinux:9.1
%environment
export TROUTE_REPO="CIROH-UA/t-route"
export TROUTE_BRANCH="datastream"
export NGEN_REPO="CIROH-UA/ngen"
export NGEN_BRANCH="main"
export PATH="/usr/lib64/mpich/bin:$PATH"
export PATH="/root/.cargo/bin:$PATH"
export PATH="/ngen/.venv/bin:$PATH"
%post
# First set the environment variables for use in %post
TROUTE_REPO="CIROH-UA/t-route"
TROUTE_BRANCH="datastream"
NGEN_REPO="CIROH-UA/ngen"
NGEN_BRANCH="main"
# Install system dependencies
echo "max_parallel_downloads=10" >> /etc/dnf/dnf.conf
dnf update -y
dnf install -y epel-release
dnf config-manager --set-enabled crb
dnf install -y sudo vim gcc gcc-c++ make cmake ninja-build tar git gcc-gfortran libgfortran sqlite sqlite-devel \
python3 python3-devel python3-pip gdal gdal-devel \
bzip2 expat expat-devel flex bison udunits2 udunits2-devel zlib-devel \
wget mpich mpich-devel hdf5 hdf5-devel netcdf netcdf-devel \
netcdf-fortran netcdf-fortran-devel netcdf-cxx netcdf-cxx-devel lld
# Create necessary directories
mkdir -p /ngen
mkdir -p /ngen/t-route
# Build Boost
cd /
wget https://archives.boost.io/release/1.79.0/source/boost_1_79_0.tar.gz
tar -xzf boost_1_79_0.tar.gz
cd boost_1_79_0
./bootstrap.sh && ./b2 && ./b2 headers
export BOOST_ROOT=/boost_1_79_0
# Setup for troute
cd /ngen
export FC=gfortran
export NETCDF=/usr/lib64/gfortran/modules/
ln -s /usr/bin/python3 /usr/bin/python
# Install UV and setup Python environment
pip3 install uv && uv venv
. /ngen/.venv/bin/activate
uv pip install -r "https://raw.githubusercontent.com/${TROUTE_REPO}/refs/heads/${TROUTE_BRANCH}/requirements.txt"
# Build t-route
cd /ngen/t-route
git clone --depth 1 --single-branch --branch $TROUTE_BRANCH https://github.com/$TROUTE_REPO.git .
echo $(git remote get-url origin | sed 's/\.git$//' | awk '{print $0 "/tree/" }' | tr -d '\n' && git rev-parse HEAD) >> /tmp/troute_url
git submodule update --init --depth 1
uv pip install build wheel
# Modify and run compiler
sed -i 's/build_[a-z]*=/#&/' compiler.sh
./compiler.sh no-e
# Install troute packages
uv pip install --config-setting='--build-option=--use-cython' src/troute-network/
uv build --wheel --config-setting='--build-option=--use-cython' src/troute-network/
uv pip install --no-build-isolation --config-setting='--build-option=--use-cython' src/troute-routing/
uv build --wheel --no-build-isolation --config-setting='--build-option=--use-cython' src/troute-routing/
uv build --wheel --no-build-isolation src/troute-config/
uv build --wheel --no-build-isolation src/troute-nwm/
# Clone and build NGEN
cd /ngen
git clone --single-branch --branch $NGEN_BRANCH https://github.com/$NGEN_REPO.git
cd ngen
git submodule update --init --recursive --depth 1
echo $(git remote get-url origin | sed 's/\.git$//' | awk '{print $0 "/tree/" }' | tr -d '\n' && git rev-parse HEAD) >> /tmp/ngen_url
# Build NGEN
export COMMON_BUILD_ARGS="-DNGEN_WITH_EXTERN_ALL=ON \
-DNGEN_WITH_NETCDF:BOOL=ON \
-DNGEN_WITH_BMI_C:BOOL=ON \
-DNGEN_WITH_BMI_FORTRAN:BOOL=ON \
-DNGEN_WITH_PYTHON:BOOL=ON \
-DNGEN_WITH_ROUTING:BOOL=ON \
-DNGEN_WITH_SQLITE:BOOL=ON \
-DNGEN_WITH_UDUNITS:BOOL=ON \
-DUDUNITS_QUIET:BOOL=ON \
-DNGEN_WITH_TESTS:BOOL=OFF \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX=. \
-DCMAKE_CXX_FLAGS='-fuse-ld=lld'"
# Build serial version
cmake -G Ninja -B cmake_build_serial -S . ${COMMON_BUILD_ARGS} -DNGEN_WITH_MPI:BOOL=OFF
cmake --build cmake_build_serial --target all -- -j $(nproc)
# Build parallel version
dnf install -y netcdf-cxx4-mpich-devel
export MPI_BUILD_ARGS="-DNGEN_WITH_MPI:BOOL=ON \
-DNetCDF_ROOT=/usr/lib64/mpich \
-DCMAKE_PREFIX_PATH=/usr/lib64/mpich \
-DCMAKE_LIBRARY_PATH=/usr/lib64/mpich/lib"
cmake -G Ninja -B cmake_build_parallel -S . ${COMMON_BUILD_ARGS} ${MPI_BUILD_ARGS} \
-DNetCDF_CXX_INCLUDE_DIR=/usr/include/mpich-$(arch) \
-DNetCDF_INCLUDE_DIR=/usr/include/mpich-$(arch)
cmake --build cmake_build_parallel --target all -- -j $(nproc)
# Setup final directories
mkdir -p /dmod/datasets /dmod/datasets/static /dmod/shared_libs /dmod/bin
cp -a ./extern/*/cmake_build/*.so* /dmod/shared_libs/. || true
find ./extern/noah-owp-modular -type f -iname "*.TBL" -exec cp '{}' /dmod/datasets/static \;
cp -a ./cmake_build_parallel/ngen /dmod/bin/ngen-parallel || true
cp -a ./cmake_build_serial/ngen /dmod/bin/ngen-serial || true
cp -a ./cmake_build_parallel/partitionGenerator /dmod/bin/partitionGenerator || true
cd /dmod/bin && \
(stat ngen-parallel && ln -s ngen-parallel ngen) || (stat ngen-serial && ln -s ngen-serial ngen)
# Final setup
echo "/dmod/shared_libs/" >> /etc/ld.so.conf.d/ngen.conf && ldconfig -v
ln -s /dmod/bin/ngen /usr/local/bin/ngen
chmod a+x /dmod/bin/*
# Install final Python dependencies
export UV_INSTALL_DIR="/root/.cargo/bin"
export PATH="$UV_INSTALL_DIR:$PATH"
curl -LsSf https://astral.sh/uv/install.sh | sh
uv self update && uv venv
cd /ngen/t-route/src
ls -la troute-*/
for pkg in troute-network troute-routing troute-config troute-nwm; do
if [ -d "$pkg" ]; then
echo "Installing package from: $pkg"
uv pip install --no-cache-dir "$pkg/"
fi
done
uv pip install --no-cache-dir netCDF4==1.6.3
uv pip install numpy==$(/dmod/bin/ngen --info | grep -e 'NumPy Version: ' | cut -d ':' -f 2 | uniq | xargs)
# Make everything in /ngen accessible
chmod -R 755 /ngen
# Set permissions for critical directories and files
chmod -R 755 /dmod
chmod -R 755 /usr/local/bin
chmod -R 755 /ngen/.venv
# Ensure specific files are executable
chmod 755 /ngen/HelloNGEN.sh
chmod 755 /dmod/bin/*
chmod 755 /usr/local/bin/ngen
%files
templates/guide/HelloNGEN.sh /ngen/HelloNGEN.sh
%runscript
exec /ngen/HelloNGEN.sh "$@"