Skip to content

Generalize scripts for building prognostic run environment #2035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 12, 2022
12 changes: 12 additions & 0 deletions .environment-scripts/install_call_py_fort.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

PREFIX=$1

URL=https://github.com/nbren12/call_py_fort.git
BRANCH=v0.2.0
git clone $URL --branch=$BRANCH $PREFIX
cd $PREFIX
make
make install
ldconfig
32 changes: 32 additions & 0 deletions .environment-scripts/install_esmf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e

CLONE_PREFIX=$1
INSTALL_PREFIX=$2
ESMF_OS=$3
ESMF_COMPILER=$4
ESMF_SITE=$5
NETCDF_INCLUDE=$6

export ESMF_DIR=$CLONE_PREFIX
export ESMF_INSTALL_PREFIX=$INSTALL_PREFIX
export ESMF_INSTALL_MODDIR=$ESMF_INSTALL_PREFIX/include
export ESMF_INSTALL_HEADERDIR=$ESMF_INSTALL_PREFIX/include
export ESMF_INSTALL_LIBDIR=$ESMF_INSTALL_PREFIX/lib
export ESMF_INSTALL_BINDIR=$ESMF_INSTALL_PREFIX/bin
export ESMF_NETCDF_INCLUDE=$NETCDF_INCLUDE
export ESMF_NETCDF_LIBS="-lnetcdf -lnetcdff"
export ESMF_BOPT=O3

# These flags set how the build is configured depending on the platform:
# https://github.com/esmf-org/esmf/tree/develop/build_config
export ESMF_OS=$ESMF_OS
export ESMF_COMPILER=$ESMF_COMPILER
export ESMF_SITE=$ESMF_SITE

# We may want to upgrade to ESMF_8_1_0 to make things easier on other platforms.
git clone -b ESMF_8_0_0 --depth 1 https://github.com/esmf-org/esmf.git $ESMF_DIR
cd $ESMF_DIR
make lib -j24
make install
make installcheck
10 changes: 10 additions & 0 deletions .environment-scripts/install_fms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

INSTALL_PREFIX=$1

cd $INSTALL_PREFIX
autoreconf -f --install
./configure
make -j8
mv $INSTALL_PREFIX/*/*.o $INSTALL_PREFIX/*/*.h $INSTALL_PREFIX/*/*.mod $INSTALL_PREFIX/
11 changes: 11 additions & 0 deletions .environment-scripts/install_fv3gfs_fortran.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

PREFIX=$1
PLATFORM=$2
INSTALL_PREFIX=$3

cd $PREFIX
./configure $PLATFORM
make -j 8
PREFIX=$INSTALL_PREFIX make install
11 changes: 11 additions & 0 deletions .environment-scripts/install_fv3net_python_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

REQUIREMENTS_PATH=$1
LOCAL_DEPENDENCIES=${@:2}

pip install --no-cache-dir -r $REQUIREMENTS_PATH
for dependency in $LOCAL_DEPENDENCIES
do
pip install --no-cache-dir --no-dependencies -e $dependency
done
16 changes: 16 additions & 0 deletions .environment-scripts/install_nceplibs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

CLONE_PREFIX=$1
INSTALL_PREFIX=$2
PLATFORM=$3
COMPILER=$4

URL=https://github.com/NCAR/NCEPlibs.git
SHA=3da51e139d5cd731c9fc27f39d88cb4e1328212b

git clone $URL $CLONE_PREFIX
cd $CLONE_PREFIX
git checkout $SHA
mkdir -p $INSTALL_PREFIX
echo "y" | bash make_ncep_libs.sh -s $PLATFORM -c $COMPILER -d $INSTALL_PREFIX -o 1
7 changes: 7 additions & 0 deletions .environment-scripts/install_python_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

FV3_DIR=$1

make -C $FV3_DIR wrapper_build
pip install --no-dependencies $FV3_DIR/wrapper/dist/*.whl
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CACHE_TAG =latest
BEAM_VERSION = 2.37.0
UBUNTU_IMAGE = ubuntu@sha256:9101220a875cee98b016668342c489ff0674f247f6ca20dfc91b91c0f28581ae
# prognostic base image is updated manually, not on every commit
PROGNOSTIC_BASE_VERSION = 1.0.0
PROGNOSTIC_BASE_VERSION = 1.0.1
DOCKER_INTERACTIVE_ARGS = \
--tty \
--interactive \
Expand Down
66 changes: 26 additions & 40 deletions docker/prognostic_run/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,39 @@ FROM ${BASE_IMAGE} as bld

# build/install the fortran model
COPY external/fv3gfs-fortran/ /tmp/fortran-build
RUN cd /tmp/fortran-build/FV3 && \
./configure gnu_docker && \
sed -i "33i CALLPYFORT=Y" conf/configure.fv3 && \
make -j 8 && \
PREFIX=/usr/local make install

# Python Stuff Here
#
# Equivalent to passing --no-cache-dir to every pip install
ENV PIP_NO_CACHE_DIR=off

# Install dependencies
COPY docker/prognostic_run/requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt

# compile and install the wrapper. Then import fv3gfs.wrapper as a minimal test
# that it works.
RUN make -C /tmp/fortran-build/FV3 wrapper_build &&\
pip3 install --no-dependencies /tmp/fortran-build/FV3/wrapper/dist/*.whl && \
python3 -c 'import fv3gfs.wrapper'
COPY .environment-scripts/install_fv3gfs_fortran.sh .
RUN CALLPYFORT=Y bash install_fv3gfs_fortran.sh /tmp/fortran-build/FV3 gnu_docker /usr/local

# Install the Python dependencies
COPY docker/prognostic_run/requirements.txt /fv3net/docker/prognostic_run/requirements.txt
COPY external/vcm /fv3net/external/vcm
RUN pip3 install --no-dependencies -e /fv3net/external/vcm

COPY external/artifacts /fv3net/external/artifacts
RUN pip3 install --no-dependencies -e /fv3net/external/artifacts

COPY external/loaders /fv3net/external/loaders
RUN pip3 install --no-dependencies -e /fv3net/external/loaders

COPY external/fv3fit /fv3net/external/fv3fit
RUN pip3 install --no-dependencies -e /fv3net/external/fv3fit

COPY external/fv3kube /fv3net/external/fv3kube
RUN pip3 install --no-dependencies -e /fv3net/external/fv3kube

COPY workflows/post_process_run /fv3net/workflows/post_process_run
RUN pip3 install --no-dependencies -e /fv3net/workflows/post_process_run
COPY workflows/prognostic_c48_run/ /fv3net/workflows/prognostic_c48_run
COPY external/emulation /fv3net/external/emulation
COPY external/radiation /fv3net/external/radiation

COPY .environment-scripts/install_fv3net_python_dependencies.sh .
RUN bash install_fv3net_python_dependencies.sh \
/fv3net/docker/prognostic_run/requirements.txt \
/fv3net/external/vcm \
/fv3net/external/artifacts \
/fv3net/external/loaders \
/fv3net/external/fv3fit \
/fv3net/external/fv3kube \
/fv3net/workflows/post_process_run \
/fv3net/workflows/prognostic_c48_run \
/fv3net/external/emulation \
/fv3net/external/radiation

# compile and install the wrapper. Then import fv3gfs.wrapper as a minimal test
# that it works.
COPY .environment-scripts/install_python_wrapper.sh .
RUN CALLPYFORT=Y bash install_python_wrapper.sh /tmp/fortran-build/FV3
RUN python3 -c 'import fv3gfs.wrapper'

RUN echo "ulimit -s unlimited" >> /etc/bash.bashrc && \
mkdir /outdir && \
Expand All @@ -52,12 +47,7 @@ RUN echo "ulimit -s unlimited" >> /etc/bash.bashrc && \
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

COPY workflows/prognostic_c48_run/ /fv3net/workflows/prognostic_c48_run
RUN pip install --no-dependencies -e /fv3net/workflows/prognostic_c48_run

# Override microphysics emulation
COPY external/emulation /fv3net/external/emulation
RUN pip install --no-dependencies -e /fv3net/external/emulation
ENV VAR_META_PATH=/fv3net/external/emulation/microphysics_parameter_metadata.yaml
ENV OUTPUT_FREQ_SEC=18000

Expand All @@ -66,10 +56,6 @@ COPY projects/microphysics/scripts /fv3net/projects/microphysics/scripts
RUN chmod +x /fv3net/projects/microphysics/scripts/*
ENV PATH=/fv3net/projects/microphysics/scripts:${PATH}

# Add python radiation port
COPY external/radiation /fv3net/external/radiation
RUN pip install --no-dependencies -e /fv3net/external/radiation

ENV PYTHONPATH=/fv3net/workflows/prognostic_c48_run:/fv3net/external/fv3fit:/fv3net/external/emulation:/fv3net/external/vcm:/fv3net/external/artifacts:/fv3net/external/loaders:/fv3net/external/fv3kube:/fv3net/workflows/post_process_run:/fv3net/external/radiation:${PYTHONPATH}
WORKDIR /fv3net/workflows/prognostic_c48_run
CMD ["bash"]
Expand Down
24 changes: 15 additions & 9 deletions docker/prognostic_run/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,39 @@ RUN apt-get update && \
rsync \
wget

COPY docker/prognostic_run/scripts/install_esmf.sh install_esmf.sh
RUN bash install_esmf.sh /usr/local/esmf
COPY .environment-scripts/install_esmf.sh .
RUN bash install_esmf.sh /esmf /usr/local/esmf Linux gfortran default

COPY docker/prognostic_run/scripts/install_fms.sh install_fms.sh
COPY .environment-scripts/install_fms.sh .
COPY external/fv3gfs-fortran/FMS /FMS
RUN bash install_fms.sh /FMS
RUN CC=/usr/bin/mpicc \
FC=/usr/bin/mpif90 \
LDFLAGS='-L/usr/lib' \
LOG_DRIVER_FLAGS='--comments' \
CPPFLAGS='-I/usr/include -Duse_LARGEFILE -DMAXFIELDMETHODS_=500 -DGFS_PHYS' \
FCFLAGS='-fcray-pointer -Waliasing -ffree-line-length-none -fno-range-check -fdefault-real-8 -fdefault-double-8 -fopenmp' \
bash install_fms.sh /FMS

COPY docker/prognostic_run/scripts/install_nceplibs.sh .
RUN bash install_nceplibs.sh /opt/NCEPlibs
COPY .environment-scripts/install_nceplibs.sh .
RUN bash install_nceplibs.sh /NCEPlibs /opt/NCEPlibs linux gnu


ENV ESMF_DIR=/usr/local/esmf
ENV CALLPY_DIR=/usr/local
ENV FMS_DIR=/FMS
ENV FV3GFS_FORTRAN_DIR=/external/fv3gfs-fortran
ENV ESMF_INC="-I${ESMF_DIR}/include -I${ESMF_DIR}/mod/modO3/Linux.gfortran.64.mpiuni.default/"
ENV ESMF_INC="-I${ESMF_DIR}/include"

ENV FMS_LIB=${FMS_DIR}/libFMS/.libs/
ENV ESMF_LIB=${ESMF_DIR}/lib
ENV CALLPYFORT_LIB=${CALLPY_DIR}/lib
ENV CALLPYFORT_INCL=${CALLPY_DIR}/include
ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ESMF_LIB}:${FMS_LIB}:${CALLPYFORT_LIB}

RUN cd /opt && git clone https://github.com/nbren12/call_py_fort.git --branch=v0.2.0
ENV CALLPY=/opt/call_py_fort \
PYTHONPATH=${CALLPY}/src/:$PYTHONPATH
RUN cd ${CALLPY} && make && make install && ldconfig
COPY .environment-scripts/install_call_py_fort.sh .
RUN bash install_call_py_fort.sh $CALLPY

# Install gcloud
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates gnupg curl gettext && \
Expand Down
21 changes: 0 additions & 21 deletions docker/prognostic_run/scripts/install_esmf.sh

This file was deleted.

18 changes: 0 additions & 18 deletions docker/prognostic_run/scripts/install_fms.sh

This file was deleted.

9 changes: 0 additions & 9 deletions docker/prognostic_run/scripts/install_nceplibs.sh

This file was deleted.