diff --git a/video_prediction_tools/env_setup/create_env.sh b/video_prediction_tools/env_setup/create_env.sh index 31f2065e9c7475762f654bcb878fcd5de7421ba4..82be2158275b527893c10e2347c6e858b49808f6 100755 --- a/video_prediction_tools/env_setup/create_env.sh +++ b/video_prediction_tools/env_setup/create_env.sh @@ -11,6 +11,25 @@ # Note that the basic output directory for the workflow may be set may passing a path as second argument to this script. # **************** Description **************** # +# **************** Auxiliary functions **************** +check_argin() { +# Handle input arguments and check if one is equal to -lcontainer +# Can also be used to check for non-positional arguments (such as -exp_id=*, see commented lines) + for argin in "$@"; do + if [[ $argin == *"-base_dir="* ]]; then + base_dir=${argin#"-base_dir="} + fi + if [[ $argin == *"-lcontainer"* ]]; then + bool_container=1 + fi + done + if [[ -z "${bool_container}" ]]; then + bool_container=0 + fi +} +# **************** Auxiliary functions **************** + +# **************** Actual script **************** # some first sanity checks if [[ ${BASH_SOURCE[0]} == ${0} ]]; then echo "ERROR: 'create_env.sh' must be sourced, i.e. execute by prompting 'source create_env.sh [virt_env_name]'" @@ -24,6 +43,11 @@ if [[ ! -n "$1" ]]; then return fi +if [[ "$#" -gt 1 ]]; then + check_argin ${@:2} # sets base_dir if provided, always sets l_container +fi + +# set some variables HOST_NAME=`hostname` ENV_NAME=$1 ENV_SETUP_DIR=`pwd` @@ -31,15 +55,22 @@ WORKING_DIR="$(dirname "$ENV_SETUP_DIR")" EXE_DIR="$(basename "$ENV_SETUP_DIR")" ENV_DIR=${WORKING_DIR}/${ENV_NAME} -# list of (Batch) scripts used for the steps in the workflow -# !!! Expects that a template named [script_name]_template.sh exists!!! -if [[ "${HOST_NAME}" == jwlogin2[1-4]* ]]; then +## perform sanity checks +# correct bool_container if host is Juwels Booster and ensure running singularity +if [[ "${bool_container}" == 0 ]] && [[ "${HOST_NAME}" == jwlogin2[1-4]* ]]; then + echo "******************************************** NOTE ********************************************" + echo " Running on Juwels Booster is only possible inside a container environment. " + echo "******************************************** NOTE ********************************************" + bool_container=1 +fi + +if [[ "${bool_container}" == 1 ]]; then echo "******************************************** NOTE ********************************************" echo " Make use of dedicated Horovod-related working branches only!!! " echo "******************************************** NOTE ********************************************" - # another sanity check for Juwels Booster -> ensure running singularity + # Check if singularity is running if [[ -z "${SINGULARITY_NAME}" ]]; then - echo "ERROR: create_env.sh must be executed in a running singularity on Juwels Booster." + echo "ERROR: create_env.sh must be executed in a running singularity on Juwels in conjuction with container-usage." echo "Thus, execute 'singularity shell [my_docker_image]' first!" return fi @@ -57,12 +88,34 @@ fi if [[ -d ${ENV_DIR} ]]; then echo "Virtual environment has already been set up under ${ENV_DIR}. The present virtual environment will be activated now." echo "NOTE: If you wish to set up a new virtual environment, delete the existing one or provide a different name." - ENV_EXIST=1 else ENV_EXIST=0 fi +## check integratability of modules +if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *jwlogin* ]]; then + if [[ "${bool_container}" > 0 ]]; then + # on Juwels Booster, we are in a container environment -> loading modules is not possible + echo "***** Note for container environment! *****" + echo "Already checked the required modules?" + echo "To do so, run 'source modules_train.sh' after exiting the singularity." + echo "***** Note for container environment! *****" + else + # load modules and check for their availability + echo "***** Checking modules required during the workflow... *****" + source ${ENV_SETUP_DIR}/modules_preprocess.sh purge + source ${ENV_SETUP_DIR}/modules_train.sh purge + source ${ENV_SETUP_DIR}/modules_postprocess.sh + fi +else + echo "ERROR: AMBS-workflow is currently only supported on the Juelich HPC-systems HDF-ML, Juwels and Juwels Booster" + return + # unset PYTHONPATH on every other machine that is not a known HPC-system + # unset PYTHONPATH +fi + + # Create fresh virtual environment or just activate the existing one if [[ "$ENV_EXIST" == 0 ]]; then # Check modules first @@ -84,6 +137,9 @@ if [[ "$ENV_EXIST" == 0 ]]; then # unset PYTHONPATH on every other machine that is not a known HPC-system unset PYTHONPATH fi + +## set up virtual environment +if [[ "$ENV_EXIST" == 0 ]]; then # Activate virtual environment and install additional Python packages. echo "Configuring and activating virtual environment on ${HOST_NAME}" @@ -95,11 +151,11 @@ if [[ "$ENV_EXIST" == 0 ]]; then source ${activate_virt_env} # install some requirements and/or check for modules - if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *juwels* ]]; then + if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *jwlogin* ]]; then # Install packages depending on host echo "***** Start installing additional Python modules with pip... *****" req_file=${ENV_SETUP_DIR}/requirements.txt - if [[ "${HOST_NAME}" == jwlogin2[1-4]* ]]; then req_file=${ENV_SETUP_DIR}/requirements_booster.txt; fi + if [[ "${bool_container}" > 0 ]]; then req_file=${ENV_SETUP_DIR}/requirements_container.txt; fi pip3 install --no-cache-dir -r ${req_file} else @@ -120,9 +176,9 @@ if [[ "$ENV_EXIST" == 0 ]]; then export PYTHONPATH=${WORKING_DIR}/model_modules:$PYTHONPATH >> ${activate_virt_env} export PYTHONPATH=${WORKING_DIR}/postprocess:$PYTHONPATH >> ${activate_virt_env} - if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *juwels* ]]; then + if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *jwlogin* ]]; then export PYTHONPATH=${ENV_DIR}/lib/python3.6/site-packages:$PYTHONPATH >> ${activate_virt_env} - if [[ "${HOST_NAME}" == jwlogin2[1-4]* ]]; then + if [[ "${bool_container}" > 0 ]]; then export PYTONPATH=/usr/locali/lib/python3.6/dist-packages:$PYTHONPATH fi fi @@ -137,21 +193,26 @@ if [[ "$ENV_EXIST" == 0 ]]; then if [[ "${HOST_NAME}" == hdfml* || "${HOST_NAME}" == *juwels* ]]; then echo "export PYTHONPATH=${ENV_DIR}/lib/python3.6/site-packages:\$PYTHONPATH" >> ${activate_virt_env} - if [[ "${HOST_NAME}" == jwlogin2[1-4]* ]]; then + if [[ "${bool_container}" > 0 ]]; then echo "export PYTONPATH=/usr/locali/lib/python3.6/dist-packages:\$PYTHONPATH" >> ${activate_virt_env} fi fi info_str="Virtual environment ${ENV_DIR} has been set up successfully." elif [[ "$ENV_EXIST" == 1 ]]; then # loading modules of postprocessing and activating virtual env are suifficient - source ${ENV_SETUP_DIR}/modules_postprocess.sh + if [[ "${bool_container}" == 0 ]]; then + source ${ENV_SETUP_DIR}/modules_postprocess.sh + fi source ${ENV_DIR}/bin/activate info_str="Virtual environment ${ENV_DIR} has been activated successfully." fi echo "Set up runscript template for user ${USER}..." -shift # shift parsed arguments so that name of venv is not parsed to setup_runscript_template.sh -source "${WORKING_DIR}"/utils/runscript_generator/setup_runscript_templates.sh +if [[ -z "${base_dir}" ]]; then + source "${WORKING_DIR}"/utils/runscript_generator/setup_runscript_templates.sh +else + source "${WORKING_DIR}"/utils/runscript_generator/setup_runscript_templates.sh ${base_dir} +fi echo "******************************************** NOTE ********************************************" echo "${info_str}"