Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Made significant improvements to the Docker, Apptainer, and Singulari…
Browse files Browse the repository at this point in the history
…ty containers.
  • Loading branch information
daminton committed Jun 7, 2023
1 parent c8ba090 commit 10935fb
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 66 deletions.
40 changes: 23 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ RUN echo 'find_path(NETCDF_INCLUDE_DIR NAMES netcdf.mod HINTS ENV NETCDF_FORTRAN

# Production container
FROM continuumio/miniconda3
COPY ./python/. /opt/conda/pkgs/swiftest/python/
SHELL ["/bin/bash", "--login", "-c"]
ENV SHELL="/bin/bash"
ENV PATH="/opt/conda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/lib"

COPY environment.yml .

RUN apt-get update && apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Expand All @@ -172,27 +177,28 @@ RUN apt-get update && apt-get upgrade -y && \
conda update --all -y && \
conda install conda-libmamba-solver -y && \
conda config --set solver libmamba && \
conda install -c conda-forge conda-build numpy scipy matplotlib pandas xarray astropy astroquery tqdm x264 bottleneck ffmpeg h5netcdf netcdf4 dask -y && \
conda update --all -y && \
cd /opt/conda/pkgs/swiftest/python/swiftest && conda develop . && \
conda clean --all -y
conda env create -f environment.yml && \
conda init bash && \
echo "conda activate swiftest-env" >> ~/.bashrc

ENV LD_LIBRARY_PATH="/usr/local/lib"
ENV SHELL="/bin/bash"
COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /usr/local/lib/
COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /usr/local/lib/
COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /usr/local/lib/
COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /usr/local/bin/
COPY --from=build /usr/local/bin/swiftest_driver /usr/local/bin
COPY --from=build /usr/local/bin/swiftest_driver_caf /usr/local/bin/
COPY ./python/. /opt/conda/pkgs/
COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/envs/swiftest-env/bin/
COPY --from=build /usr/local/bin/swiftest_driver /opt/conda/bin/
COPY --from=build /usr/local/bin/swiftest_driver_caf /opt/conda/envs/swiftest-env/bin/
COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libicaf.so /opt/conda/envs/swiftest-env/lib/
COPY --from=build /opt/intel/oneapi/mpi/2021.9.0//lib/release/libmpi.so.12 /opt/conda/envs/swiftest-env/lib/
COPY --from=build /opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin/libintlc.so.5 /opt/conda/envs/swiftest-env/lib/
COPY --from=build /opt/intel/oneapi/mpi/latest/bin/mpiexec.hydra /opt/conda/envs/swiftest-env/bin/

RUN mkdir -p /.astropy && \
# Start new shell to activate the environment and install Swiftest
RUN cd /opt/conda/pkgs/swiftest && conda develop . && \
conda clean --all -y && \
mkdir -p /.astropy && \
chmod -R 777 /.astropy && \
mkdir -p /.cache/matplotlib && \
mkdir -p /.config/matplotlib && \
chmod -R 777 /.cache/matplotlib && \
chmod -R 777 /.config/matplotlib && \
mkdir -p /opt/conda/pkgs/swiftest/bin && \
ln -s /usr/local/bin/swiftest_driver /opt/conda/pkgs/swiftest/bin/swiftest_driver
ln -s /opt/conda/bin/swiftest_driver /opt/conda/bin/driver

ENTRYPOINT ["/opt/conda/bin/python"]
ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "swiftest-env"]
3 changes: 1 addition & 2 deletions apptainer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
!bin/
!bin/swiftest_driver
!bin/swiftest_python
!bin/swiftest
!install.sh
!setenv.sh
2 changes: 2 additions & 0 deletions apptainer/bin/swiftest_python → apptainer/bin/swiftest
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/sh --
OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`}
FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1}
apptainer run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@"
2 changes: 2 additions & 0 deletions apptainer/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/sh --
OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`}
FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1}
apptainer exec --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@"
26 changes: 18 additions & 8 deletions apptainer/install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#!/bin/sh --
# This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin.
# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, which requires this script to be called via source:
# $ . ./install.sh
# This will install the Apptainer version of the swiftest_driver in place of the native compiled version into ../bin as
# well as the swiftest_python script that is used to execute a Python input file.
# The swiftest.sif file will be copied to the SIF_DIR directory. The default location is ${HOME}/.apptainer.
# To change this, just set environment variable SIF_DIR prior to running this script.
#
# The script takes an optional argument "tag" if you want to pull a container other than "latest".
#
tag=${1:-latest}
echo "Installing swiftest.sif Singularity container and executable script from swiftest:${tag} Docker container"
apptainer pull --force swiftest.sif docker://daminton/swiftest:${tag}
# In order to use one executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif,
# which requires this script to be called via source:
# $ source ./install.sh
# or
# $ . ./install.sh
TAG=${1:-latest}

SIF_DIR=${SIF_DIR:-${HOME}/.apptainer}
echo "Installing ${SIF_DIR}/swiftest.sif container from mintongroup/swiftest:${TAG} Docker container"
apptainer pull --force ${SIF_DIR}/swiftest.sif docker://mintongroup/swiftest:${TAG}
cp -rf bin/swiftest ../bin/
cp -rf bin/swiftest_driver ../bin/
cp -rf bin/swiftest_python ../bin/
source ./setenv.sh
export SWIFTEST_SIF=${SIF_DIR}/swiftest.sif
4 changes: 0 additions & 4 deletions apptainer/setenv.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docker/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
!.gitignore
!install.sh
!bin
!bin/swiftest_python
!bin/swiftest
!bin/swiftest_driver
4 changes: 4 additions & 0 deletions docker/bin/swiftest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh --
OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`}
FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1}
docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES mintongroup/swiftest "$@"
4 changes: 3 additions & 1 deletion docker/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/sh --
docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti --entrypoint /usr/local/bin/swiftest_driver -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:1.0.0 "$@"
OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`}
FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1}
docker run -v $(pwd):$(pwd) -w $(pwd) --user "$(id -u):$(id -g)" -ti --entrypoint /usr/local/bin/swiftest_driver -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES MintonGroup/swiftest "$@"
2 changes: 0 additions & 2 deletions docker/bin/swiftest_python

This file was deleted.

5 changes: 3 additions & 2 deletions docker/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh --
tag=${1:-latest}
echo "Installing swiftest:${tag} Docker container and executable script"
docker pull daminton/swiftest:${tag}
cp -rf bin/swiftest ../bin/
docker pull mintongroup/swiftest:${tag}
cp -rf bin/swiftest ../bin/
cp -rf bin/swiftest_driver ../bin/
23 changes: 9 additions & 14 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ def _type_scrub(output_data):
sys.exit()
except:
warnings.warn(f"Error executing main swiftest_driver program", stacklevel=2)
res = p.communicate()
for line in res[1]:
print(line, end='')
sys.exit()

pbar.close()
Expand Down Expand Up @@ -502,11 +505,9 @@ def run(self,dask: bool = False, **kwargs):

if not self.binary_source.exists():
msg = "Path to swiftest_driver has not been set!"
msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_path)}"
msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_source.parent)}"
warnings.warn(msg,stacklevel=2)
return
else:
shutil.copy2(self.binary_source, self.driver_executable)

if not self.restart:
self.clean()
Expand Down Expand Up @@ -942,16 +943,15 @@ def set_integrator(self,
update_list.append("codename")
if self.codename == "Swiftest":
self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver"
self.binary_path = self.simdir.resolve()
self.driver_executable = self.binary_path / "swiftest_driver"
self.driver_executable = self.binary_source
if not self.binary_source.exists():
warnings.warn(f"Cannot find the Swiftest driver in {str(self.binary_path)}",stacklevel=2)
warnings.warn(f"Cannot find the Swiftest driver at {str(self.binary_source)}",stacklevel=2)
self.driver_executable = None
else:
if self.binary_path.exists():
if self.binary_source.exists():
self.driver_executable.resolve()
else:
self.binary_path = "NOT IMPLEMENTED FOR THIS CODE"
self.binary_source = "NOT IMPLEMENTED FOR THIS CODE"
self.driver_executable = None
update_list.append("driver_executable")

Expand Down Expand Up @@ -1200,8 +1200,6 @@ def set_feature(self,
msg = f"Cannot create the {self.simdir.resolve()} directory: File exists."
msg += "\nDelete the file or change the location of param_file"
raise NotADirectoryError(msg)
self.binary_path = self.simdir.resolve()
self.driver_executable = self.binary_path / "swiftest_driver"
self.param_file = Path(kwargs.pop("param_file","param.in"))

if self.codename == "Swiftest":
Expand Down Expand Up @@ -2754,7 +2752,6 @@ def write_param(self,
self.driver_script = os.path.join(self.simdir, "swiftest_driver.sh")
with open(self.driver_script, 'w') as f:
f.write(f"#{self._shell_full}\n")
#f.write(f"source ~/.{self._shell}rc\n")
f.write(f"cd {self.simdir}\n")
f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n")

Expand Down Expand Up @@ -2991,11 +2988,9 @@ def save(self,
self.write_param(param_file=param_file,**kwargs)
if not self.binary_source.exists():
msg = "Path to swiftest_driver has not been set!"
msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_path)}"
msg += f"\nMake sure swiftest_driver is compiled and the executable is in {str(self.binary_source.parent)}"
warnings.warn(msg,stacklevel=2)
return
else:
shutil.copy2(self.binary_source, self.driver_executable)
elif codename == "Swifter":
swifter_param = io.swiftest2swifter_param(param)
if "rhill" in self.data:
Expand Down
1 change: 0 additions & 1 deletion singularity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
!bin/swiftest_driver
!bin/swiftest_python
!install.sh
!setenv.sh
2 changes: 2 additions & 0 deletions singularity/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/sh --
OMP_NUM_THREADS=${OMP_NUM_THREADS:-`nproc --all`}
FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES:-1}
singularity exec --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} swiftest_driver "$@"
2 changes: 0 additions & 2 deletions singularity/bin/swiftest_python

This file was deleted.

26 changes: 18 additions & 8 deletions singularity/install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#!/bin/sh --
# This will install the Singularity container version of the swiftest_driver in place of the native compiled version into ../bin.
# In order to use the executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif, which requires this script to be called via source:
# $ . ./install.sh
# This will install the Singularity version of the swiftest_driver in place of the native compiled version into ../bin as
# well as the swiftest_python script that is used to execute a Python input file.
# The swiftest.sif file will be copied to the SIF_DIR directory. The default location is ${HOME}/.singularity.
# To change this, just set environment variable SIF_DIR prior to running this script.
#
# The script takes an optional argument "tag" if you want to pull a container other than "latest".
#
tag=${1:-latest}
echo "Installing swiftest.sif Singularity container and executable script from swiftest:${tag} Docker container"
singularity pull --force swiftest.sif docker://daminton/swiftest:${tag}
# In order to use one executable script, the SWIFTEST_SIF environment variable must be set to point to the location of swiftest.sif,
# which requires this script to be called via source:
# $ source ./install.sh
# or
# $ . ./install.sh
TAG=${1:-latest}

SIF_DIR=${SIF_DIR:-${HOME}/.singularity}
echo "Installing ${SIF_DIR}/swiftest.sif container from mintongroup/swiftest:${TAG} Docker container"
singularity pull --force ${SIF_DIR}/swiftest.sif docker://mintongroup/swiftest:${TAG}
cp -rf bin/swiftest ../bin/
cp -rf bin/swiftest_driver ../bin/
cp -rf bin/swiftest_python ../bin/
source ./setenv.sh
export SWIFTEST_SIF=${SIF_DIR}/swiftest.sif
4 changes: 0 additions & 4 deletions singularity/setenv.sh

This file was deleted.

0 comments on commit 10935fb

Please sign in to comment.