Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Set the following environment variables before running the scripts:
| `$VERITAS_IRFPRODUCTION_DIR` | Path to the IRF production output directory |
| `$VERITAS_USER_DATA_DIR` | Path to user-specific data output |
| `$VERITAS_USER_LOG_DIR` | Path to log files |
| `$EVNDISP_MLSYS` | Path to the [Eventdisplay-ML](https://github.com/Eventdisplay/Eventdisplay-ML) installation (optional) |
| `$EVNDISP_ML_SYS` | Path to the [Eventdisplay-ML](https://github.com/Eventdisplay/Eventdisplay-ML) installation (optional) |
| `$EVNDISP_ML_ENV` | Name of the conda environment for Eventdisplay-ML (default: `eventdisplay_ml`) |

See [`./scripts/set_environment.sh`](./scripts/set_environment.sh) for a template with all variables configured for the DESY computing environment. Submission commands for various batch systems are available in [submissionCommands.dat](./scripts/submissionCommands.dat).
Expand Down
1 change: 1 addition & 0 deletions docs/changes/153.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Centralize XGB helper-script Conda activation and environment logging.
3 changes: 3 additions & 0 deletions scripts/ANALYSIS.dispXGB.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ rm -f "${LOGDIR}"/x* 2>/dev/null

# Job submission script
SUBSCRIPT="$(dirname "$0")/helper_scripts/ANALYSIS.dispXGB_sub"
HELPER_SCRIPTS_DIR="$(cd "$(dirname "$0")/helper_scripts" && pwd)"
TIMETAG=$(date +"%s")
CREATED_LOGSUBDIRS=" "

Expand All @@ -82,6 +83,8 @@ do
-e "s|XXGB|$XGB|" \
-e "s|XGB_TTYPE|$XGB_TYPE|" \
-e "s|ANALYSISTYPE|$ANALYSIS_TYPE|" \
-e "s|HHELPER_SCRIPTS_DIR|$HELPER_SCRIPTS_DIR|" \
-e "s|EENV_SNAPSHOT_DIR|$LOGDIR|" \
-e "s|OODIR|$ODIR|" "$SUBSCRIPT".sh > "$FSCRIPT".sh

chmod u+x "$FSCRIPT.sh"
Expand Down
3 changes: 3 additions & 0 deletions scripts/IRF.dispXGB.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ rm -f "${LOGDIR}"/x* 2>/dev/null

# Job submission script
SUBSCRIPT="$(dirname "$0")/helper_scripts/IRF.dispXGB_sub"
HELPER_SCRIPTS_DIR="$(cd "$(dirname "$0")/helper_scripts" && pwd)"

for FILE in $FILES
do
Expand All @@ -69,6 +70,8 @@ do
-e "s|XXGB|$XGB|" \
-e "s|XGB_TTYPE|$XGB_TYPE|" \
-e "s|ANALYSISTYPE|$ANALYSIS_TYPE|" \
-e "s|HHELPER_SCRIPTS_DIR|$HELPER_SCRIPTS_DIR|" \
-e "s|EENV_SNAPSHOT_DIR|$LOGDIR|" \
-e "s|OODIR|$ODIR|" "$SUBSCRIPT".sh > "$FSCRIPT".sh

chmod u+x "$FSCRIPT.sh"
Expand Down
3 changes: 3 additions & 0 deletions scripts/IRF.trainXGBforAngularReconstruction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ done
echo "FILE LIST: ${MSCWLIST}"

SUBSCRIPT="$(dirname "$0")/helper_scripts/IRF.trainXGBforAngularReconstruction_sub.sh"
HELPER_SCRIPTS_DIR="$(cd "$(dirname "$0")/helper_scripts" && pwd)"

echo "Processing Zenith = $ZA, Noise = $NOISE, Wobble = $WOBBLE"

FSCRIPT="$LOGDIR/trainXGBStereoAnalysis.ID${RECID}.${EPOCH}.ATM${ATM}.${ZA}.sh"
sed -e "s|OUTPUTDIR|$ODIR|" \
-e "s|MSCWLIST|$MSCWLIST|" \
-e "s|HHELPER_SCRIPTS_DIR|$HELPER_SCRIPTS_DIR|" \
-e "s|EENV_SNAPSHOT_DIR|$LOGDIR|" \
-e "s|NCORES|$ncore|" "$SUBSCRIPT" > "$FSCRIPT"

chmod u+x "$FSCRIPT"
Expand Down
3 changes: 3 additions & 0 deletions scripts/IRF.trainXGBforGammaHadronSeparationTraining.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ get_run_prefix()

# Job submission script
SUBSCRIPT="$(dirname "$0")/helper_scripts/IRF.trainXGBforGammaHadronSeparation_sub.sh"
HELPER_SCRIPTS_DIR="$(cd "$(dirname "$0")/helper_scripts" && pwd)"

SIGNALLIST="${ODIR}/signal_files.list"
rm -f "${SIGNALLIST}"
Expand Down Expand Up @@ -167,6 +168,8 @@ for (( i=0; i < NENE; i++ )); do
-e "s|MODELPARA|$RUNPAR|" \
-e "s|ENERGYBIN|$i|" \
-e "s|NCORES|$ncore|" \
-e "s|HHELPER_SCRIPTS_DIR|$HELPER_SCRIPTS_DIR|" \
-e "s|EENV_SNAPSHOT_DIR|$LOGDIR|" \
-e "s|OUTPUTDIR|${ODIR}|" "$SUBSCRIPT" > "$FSCRIPT"

chmod u+x "$FSCRIPT"
Expand Down
32 changes: 7 additions & 25 deletions scripts/helper_scripts/ANALYSIS.dispXGB_sub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
RUN=RRUN
ODIR=OODIR
env_name="${EVNDISP_ML_ENV:-eventdisplay_ml}"
HELPER_SCRIPTS_DIR="HHELPER_SCRIPTS_DIR"
ENV_SNAPSHOT_DIR="EENV_SNAPSHOT_DIR"
XGB="XXGB"
XGB_TYPE=XGB_TTYPE
ANATYPE=ANALYSISTYPE
Expand All @@ -26,29 +28,10 @@ mkdir -p "$TEMPDIR"
mkdir -p "${ODIR}"
echo -e "Output files will be written to:\n ${ODIR}"

check_conda_installation()
{
if command -v conda &> /dev/null; then
echo "Found conda installation."
else
echo "Error: found no conda installation."
echo "exiting..."
exit
fi
env_info=$(conda info --envs)
if [[ "$env_info" == *"$env_name"* ]]; then
echo "Found conda environment '$env_name'"
else
echo "Error: the conda environment '$env_name' does not exist."
echo "exiting..."
exit
fi
}

check_conda_installation

eval "$(conda shell.bash hook)"
conda activate "$env_name"
# shellcheck source=scripts/helper_scripts/UTILITY.conda_env.sh
source "${HELPER_SCRIPTS_DIR}/UTILITY.conda_env.sh"
evndisp_ml_setup_python_cache "$TEMPDIR" "$RUN"
evndisp_ml_activate_conda "$env_name"

# directory schema for preprocessed files
getNumberedDirectory()
Expand Down Expand Up @@ -113,7 +96,6 @@ $ML_EXEC --input_file "$MSCW_FILE" \
--model_prefix "$DISPDIR" \
--output_file "$OFIL.root" > "${LOGFILE}" 2>&1

python --version >> "${LOGFILE}"
conda list -n "$env_name" >> "${LOGFILE}"
evndisp_ml_log_environment "${LOGFILE}" "$env_name" "$ENV_SNAPSHOT_DIR"

conda deactivate
39 changes: 9 additions & 30 deletions scripts/helper_scripts/IRF.dispXGB_sub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
MSCW_FILE=FFILE
ODIR=OODIR
env_name="${EVNDISP_ML_ENV:-eventdisplay_ml}"
HELPER_SCRIPTS_DIR="HHELPER_SCRIPTS_DIR"
ENV_SNAPSHOT_DIR="EENV_SNAPSHOT_DIR"
XGB="XXGB"
XGB_TYPE=XGB_TTYPE
ANATYPE=ANALYSISTYPE
Expand All @@ -26,34 +28,10 @@ mkdir -p "$TEMPDIR"
mkdir -p "${ODIR}"
echo -e "Output files will be written to:\n ${ODIR}"

check_conda_installation()
{
if command -v conda &> /dev/null; then
echo "Found conda installation."
else
echo "Error: found no conda installation."
echo "exiting..."
exit
fi
env_info=$(conda info --envs)
if [[ "$env_info" == *"$env_name"* ]]; then
echo "Found conda environment '$env_name'"
else
echo "Error: the conda environment '$env_name' does not exist."
echo "exiting..."
exit
fi
}

check_conda_installation

# Avoid plugin/cache race conditions
export CONDA_NO_PLUGINS=true
PYTHONPYCACHEPREFIX="${TEMPDIR}/pycache_$(basename "$MSCW_FILE" .root)"
export PYTHONPYCACHEPREFIX
mkdir -p "$PYTHONPYCACHEPREFIX"
eval "$(conda shell.bash hook)"
conda activate "$env_name"
# shellcheck source=scripts/helper_scripts/UTILITY.conda_env.sh
source "${HELPER_SCRIPTS_DIR}/UTILITY.conda_env.sh"
evndisp_ml_setup_python_cache "$TEMPDIR" "$(basename "$MSCW_FILE" .root)"
evndisp_ml_activate_conda "$env_name"

if [[ ! -e ${MSCW_FILE} ]]; then
echo "File ${MSCW_FILE} not found. Exiting."
Expand Down Expand Up @@ -104,5 +82,6 @@ $ML_EXEC --input_file "$MSCW_FILE" \
--max_cores $MAXCORES \
--output_file "$OFIL.root" > "${LOGFILE}" 2>&1

python --version >> "${LOGFILE}"
python -m pip freeze >> "${LOGFILE}" || echo "pip freeze failed, continuing" >> "${LOGFILE}"
evndisp_ml_log_environment "${LOGFILE}" "$env_name" "$ENV_SNAPSHOT_DIR"

conda deactivate
32 changes: 7 additions & 25 deletions scripts/helper_scripts/IRF.trainXGBforAngularReconstruction_sub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
LLIST=MSCWLIST
ODIR=OUTPUTDIR
env_name="${EVNDISP_ML_ENV:-eventdisplay_ml}"
HELPER_SCRIPTS_DIR="HHELPER_SCRIPTS_DIR"
ENV_SNAPSHOT_DIR="EENV_SNAPSHOT_DIR"
P="0.5"
N="5000000"
MAXCORES=NCORES
Expand All @@ -24,29 +26,10 @@ mkdir -p "$TEMPDIR"
mkdir -p "${ODIR}"
echo -e "Output files will be written to:\n ${ODIR}"

check_conda_installation()
{
if command -v conda &> /dev/null; then
echo "Found conda installation."
else
echo "Error: found no conda installation."
echo "exiting..."
exit
fi
env_info=$(conda info --envs)
if [[ "$env_info" == *"$env_name"* ]]; then
echo "Found conda environment '$env_name'"
else
echo "Error: the conda environment '$env_name' does not exist."
echo "exiting..."
exit
fi
}

check_conda_installation

eval "$(conda shell.bash hook)"
conda activate "$env_name"
# shellcheck source=scripts/helper_scripts/UTILITY.conda_env.sh
source "${HELPER_SCRIPTS_DIR}/UTILITY.conda_env.sh"
evndisp_ml_setup_python_cache "$TEMPDIR" "train_stereo_$(basename "$LLIST" .list)"
evndisp_ml_activate_conda "$env_name"

PREFIX="${ODIR}/dispdir_bdt"
LOGFILE="${PREFIX}.log"
Expand All @@ -60,7 +43,6 @@ eventdisplay-ml-train-xgb-stereo \
--min_images 2 --memory_profile \
--train_test_fraction $P --max_events $N >| "${LOGFILE}" 2>&1

python --version >> "${LOGFILE}"
conda list -n "$env_name" >> "${LOGFILE}"
evndisp_ml_log_environment "${LOGFILE}" "$env_name" "$ENV_SNAPSHOT_DIR"

conda deactivate
32 changes: 7 additions & 25 deletions scripts/helper_scripts/IRF.trainXGBforGammaHadronSeparation_sub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ PARA=MODELPARA
EBIN=ENERGYBIN
ODIR=OUTPUTDIR
env_name="${EVNDISP_ML_ENV:-eventdisplay_ml}"
HELPER_SCRIPTS_DIR="HHELPER_SCRIPTS_DIR"
ENV_SNAPSHOT_DIR="EENV_SNAPSHOT_DIR"
P="0.5"
N="5000000"
MAXCORES=NCORES
Expand All @@ -27,29 +29,10 @@ mkdir -p "$TEMPDIR"
mkdir -p "${ODIR}"
echo -e "Output files will be written to:\n ${ODIR}"

check_conda_installation()
{
if command -v conda &> /dev/null; then
echo "Found conda installation."
else
echo "Error: found no conda installation."
echo "exiting..."
exit
fi
env_info=$(conda info --envs)
if [[ "$env_info" == *"$env_name"* ]]; then
echo "Found conda environment '$env_name'"
else
echo "Error: the conda environment '$env_name' does not exist."
echo "exiting..."
exit
fi
}

check_conda_installation

eval "$(conda shell.bash hook)"
conda activate "$env_name"
# shellcheck source=scripts/helper_scripts/UTILITY.conda_env.sh
source "${HELPER_SCRIPTS_DIR}/UTILITY.conda_env.sh"
evndisp_ml_setup_python_cache "$TEMPDIR" "train_gh_ebin${EBIN}"
evndisp_ml_activate_conda "$env_name"

PREFIX="${ODIR}/gammahadron_bdt"
LOGFILE="${PREFIX}_ebin${EBIN}.log"
Expand All @@ -66,7 +49,6 @@ eventdisplay-ml-train-xgb-classify \
--balance_class_zenith_weights \
--train_test_fraction $P --max_events $N >| "${LOGFILE}" 2>&1

python --version >> "${LOGFILE}"
conda list -n "$env_name" >> "${LOGFILE}"
evndisp_ml_log_environment "${LOGFILE}" "$env_name" "$ENV_SNAPSHOT_DIR"

conda deactivate
89 changes: 89 additions & 0 deletions scripts/helper_scripts/UTILITY.conda_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# Shared Conda setup and environment logging helpers for job scripts.

evndisp_ml_setup_python_cache()
{
local tempdir="$1"
local cache_tag="$2"

[[ -z "$tempdir" ]] && return

cache_tag="${cache_tag//\//_}"
export PYTHONPYCACHEPREFIX="${tempdir}/pycache_${cache_tag}"
mkdir -p "$PYTHONPYCACHEPREFIX"
echo "Python cache dir: $PYTHONPYCACHEPREFIX"
}

evndisp_ml_activate_conda()
{
local env_name="${1:-${EVNDISP_ML_ENV:-eventdisplay_ml}}"

export CONDA_NO_PLUGINS="${CONDA_NO_PLUGINS:-true}"

if ! command -v conda > /dev/null 2>&1; then
echo "Error: found no conda installation."
echo "exiting..."
exit 1
fi

eval "$(conda shell.bash hook)"
if ! conda activate "$env_name"; then
echo "Error: failed to activate conda environment '$env_name'."
echo "exiting..."
exit 1
fi
echo "Activated conda environment '$env_name'"
}

evndisp_ml_log_environment()
{
local logfile="$1"
local env_name="${2:-${EVNDISP_ML_ENV:-eventdisplay_ml}}"
local snapshot_dir="$3"
local snapshot_tag
local snapshot_file
local lock_dir
local tmp_file

{
echo "Python executable: $(command -v python)"
python --version
} >> "$logfile" 2>&1

[[ "${EVNDISP_ML_LOG_ENVIRONMENT:-snapshot}" == "none" ]] && return

if [[ -z "$snapshot_dir" ]]; then
python -m pip freeze >> "$logfile" 2>&1 \
|| echo "pip freeze failed, continuing" >> "$logfile"
return
fi

mkdir -p "$snapshot_dir"
snapshot_tag="${env_name//\//_}"
snapshot_file="${snapshot_dir}/conda_environment_${snapshot_tag}.txt"
lock_dir="${snapshot_file}.lock"

if [[ -f "$snapshot_file" ]]; then
echo "Conda environment snapshot: $snapshot_file" >> "$logfile"
return
fi

if mkdir "$lock_dir" 2> /dev/null; then
tmp_file="${snapshot_file}.$$"
{
echo "Conda environment: $env_name"
echo "Python executable: $(command -v python)"
python --version
echo
echo "pip freeze:"
python -m pip freeze || echo "pip freeze failed"
echo
echo "conda list:"
conda list
} > "$tmp_file" 2>&1
mv "$tmp_file" "$snapshot_file"
rmdir "$lock_dir"
fi

echo "Conda environment snapshot: $snapshot_file" >> "$logfile"
}
2 changes: 1 addition & 1 deletion scripts/set_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export EVNDISPSCRIPTS
########################################################################
# software settings
export V2DL3SYS=${USERAFSDIR}/EVNDISP/EVNDISP-400/GITHUB_Eventdisplay/PreProcessing/V2DL3-v0.8.1
export EVNDISP_MLSYS=${USERAFSDIR}/EVNDISP/EVNDISP-400/GITHUB_Eventdisplay/Eventdisplay-ML
export EVNDISP_ML_SYS=${USERAFSDIR}/EVNDISP/EVNDISP-400/GITHUB_Eventdisplay/Eventdisplay-ML
# EVENTDISPLAY using apptainers
if [[ $PROCESS == "apptainer"* ]]; then
export EVNDISP_APPTAINER="$VERITAS_DATA_DIR/shared/APPTAINERS/eventdisplay_v4_${EVNDISPVERSION}-rc5.sif"
Expand Down