From c436e88cd73cbcdef9674a12e41f555361bc1c02 Mon Sep 17 00:00:00 2001 From: Josh Cunningham Date: Mon, 11 Nov 2024 14:33:23 -0600 Subject: [PATCH] add no-remotes workaround to docker image --- docker/Dockerfile | 12 +++++----- docker/HelloNGEN.sh | 54 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index fb4f3b0..311d1ab 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -174,11 +174,9 @@ RUN dnf update -y && \ WORKDIR /ngen # Copy necessary files from build stages -COPY HelloNGEN.sh /ngen/HelloNGEN.sh -COPY --from=restructure_files /dmod /dmod + COPY --from=troute_build /ngen/t-route/src/troute-*/dist/*.whl /tmp/ -RUN ln -s /dmod/bin/ngen /usr/local/bin/ngen ENV UV_INSTALL_DIR=/root/.cargo/bin RUN curl -LsSf https://astral.sh/uv/install.sh | sh ENV PATH="/root/.cargo/bin:${PATH}" @@ -189,13 +187,14 @@ RUN uv venv && \ RUN rm -rf /tmp/*.whl # DONT ADD THE VENV TO THE PATH YET +COPY --from=restructure_files /dmod /dmod +RUN ln -s /dmod/bin/ngen /usr/local/bin/ngen # Set up library path RUN echo "/dmod/shared_libs/" >> /etc/ld.so.conf.d/ngen.conf && ldconfig -v # Add mpirun to path ENV PATH=$PATH:/usr/lib64/mpich/bin -RUN chmod a+x /dmod/bin/* /ngen/HelloNGEN.sh - +RUN chmod a+x /dmod/bin/* # Only here after everything else is done will the ngen binary work and provide --info # This mess is parsing the version number RUN uv pip install numpy==$(/dmod/bin/ngen --info | grep -e 'NumPy Version: ' | cut -d ':' -f 2 | uniq | xargs) @@ -216,6 +215,9 @@ RUN uv pip install --no-cache-dir /ngen/ngen/extern/lstm --extra-index-url https COPY --from=troute_build /tmp/troute_url /ngen/troute_url COPY --from=ngen_build /tmp/ngen_url /ngen/ngen_url +COPY HelloNGEN.sh /ngen/HelloNGEN.sh +RUN chmod a+x /ngen/HelloNGEN.sh + RUN echo "export PS1='\u\[\033[01;32m\]@ngiab_dev\[\033[00m\]:\[\033[01;35m\]\W\[\033[00m\]\$ '" >> ~/.bashrc diff --git a/docker/HelloNGEN.sh b/docker/HelloNGEN.sh index beed714..9b0f7fe 100644 --- a/docker/HelloNGEN.sh +++ b/docker/HelloNGEN.sh @@ -45,11 +45,12 @@ echo -e "\n" echo -e "${CYAN}\e[4mFound these Realization files:${RESET}" && echo "$NGEN_REALIZATIONS" || echo -e "${RED}No Realization files found.${RESET}" echo -e "\n" +no_remotes=$(grep "remotes_enabled" $selected_realization | grep false | wc -l) + generate_partition() { - # Store the grep result (0 if "false" is found, 1 if not) - grep_result=$(grep "remotes_enabled" $4 | grep false | wc -l) + # Store the grep result (0 if "false" is found, 1 if not) - if [ "$grep_result" -eq 0 ]; then + if [ "$no_remotes" -eq 0 ]; then # Use the original partition generator /dmod/bin/partitionGenerator "$1" "$2" "partitions_$3.json" "$3" '' '' else @@ -58,6 +59,14 @@ generate_partition() { fi } +#sed '/^[[:space:]]*"routing":/,/^[[:space:]]*},/d' realization.json >> modified.json + +if [ "$no_remotes" -eq 1 ]; then + # Use the original partition generator + mv $selected_realization modified_noremote.json + sed '/^[[:space:]]*"routing":/,/^[[:space:]]*},/d' modified_noremote.json >> $selected_realization +fi + if [ "$2" == "auto" ] then echo "AUTO MODE ENGAGED" @@ -75,9 +84,25 @@ if [ "$2" == "auto" ] else echo "Found paritions file! "$partitions fi - + rm -f /ngen/ngen/data/outputs/ngen/*.csv mpirun -n $procs /dmod/bin/ngen-parallel $selected_catchment all $selected_nexus all $selected_realization $(pwd)/partitions_$procs.json - + #TODO run troute manually if remotes were disabled + if [ "$no_remotes" -eq 1 ]; then + # diff two files to check if routing is needed + routing_used=$(wc -l < "$selected_realization") + modified_lines=$(wc -l < "modified_noremote.json") + if [ "$routing_used" -ne "$modified_lines" ]; then + routing_used=1 + else + routing_used=0 + fi + rm $selected_realization + mv modified_noremote.json $selected_realization + ts-merger /ngen/ngen/data/outputs/ngen/ _output.csv nex- + if [ "$routing_used" -eq 1 ]; then + python -m nwm_routing -V4 -f /ngen/ngen/data/config/troute.yaml + fi + fi echo "Run completed successfully, exiting, have a nice day!" exit 0 else @@ -139,6 +164,25 @@ else fi command_status=$? + +#TODO run troute manually if remotes were disabled +if [ "$no_remotes" -eq 1 ]; then + # diff two files to check if routing is needed + routing_used=$(wc -l < "$selected_realization") + modified_lines=$(wc -l < "modified_noremote.json") + if [ "$routing_used" -ne "$modified_lines" ]; then + routing_used=1 + else + routing_used=0 + fi + rm $selected_realization + mv modified_noremote.json $selected_realization + ts-merger /ngen/ngen/data/outputs/ngen/ _output.csv nex- + if [ "$routing_used" -eq 1 ]; then + python -m nwm_routing -V4 -f /ngen/ngen/data/config/troute.yaml + fi +fi + # Set message color based on command status if [ $command_status -eq 0 ]; then color=$GREEN