Skip to content

Commit

Permalink
add no-remotes workaround to docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCu committed Nov 11, 2024
1 parent fc9370f commit c436e88
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
12 changes: 7 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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)
Expand All @@ -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

Expand Down
54 changes: 49 additions & 5 deletions docker/HelloNGEN.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c436e88

Please sign in to comment.