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

Commit

Permalink
Added ability to control whether to use the containerized executable …
Browse files Browse the repository at this point in the history
…or not via the Python code
  • Loading branch information
daminton committed May 23, 2023
1 parent ffb8f30 commit 05aa725
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ IF (USE_SIMD)
"/QxSANDYBRIDGE" # Intel Windows
${GNUNATIVE} # GNU
)
ELSE
ELSE ()
# Optimize for the host's architecture
SET_COMPILE_FLAG(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}"
Fortran "-xhost" # Intel
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ENV VT_MPI='impi4'
ENV VT_ROOT='/opt/intel/oneapi/itac/2021.9.0'
ENV VT_SLIB_DIR='/opt/intel/oneapi/itac/2021.9.0/slib'

RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCMAKE_BUILD_TYPE=release && make && make install
RUN cd swiftest && cmake -P distclean.cmake && mkdir build && cd build && cmake .. -DCMAKE_PREFIX_PATH="${INDIR}" -DCMAKE_INSTALL_PREFIX="${INDIR}" -DCONTAINERIZE=ON -DCMAKE_BUILD_TYPE=release && make && make install

#Production container
FROM debian:stable-slim
Expand Down
2 changes: 1 addition & 1 deletion docker/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh --
singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF}
docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:latest "$@"
38 changes: 32 additions & 6 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(self,read_param: bool = False,
integrator : {"symba","rmvs","whm","helio"}, default "symba"
Name of the n-body integrator that will be used when executing a run.
Parameter input file equivalent: None
container : {"docker", "singularity"}, default None
Specify whether the driver exectuable is run from a Docker or Singularity container. Setting to `None`
read_param : bool, default False
Read the parameter file given by `param_file`.
param_file : str, path-like, or file-lke, default "param.in"
Expand Down Expand Up @@ -338,6 +340,7 @@ def __init__(self,read_param: bool = False,
self.init_cond = xr.Dataset()
self.encounters = xr.Dataset()
self.collisions = xr.Dataset()
self.container = None

# Set the location of the parameter input file, choosing the default if it isn't specified.
self.simdir = Path.cwd() / Path(simdir)
Expand Down Expand Up @@ -404,9 +407,11 @@ def _run_swiftest_driver(self):
"""

# Get current environment variables

env = os.environ.copy()
if self.container == "SINGULARITY" and "SWIFTEST_SIF" not in env:
env['SWIFTEST_SIF'] = Path(self.binary_source).parent.parent / "swiftest.sif"
cmd = f"{env['SHELL']} -l {self.driver_script}"


def _type_scrub(output_data):
int_vars = ["ILOOP","NPL","NTP","NPLM"]
Expand Down Expand Up @@ -829,7 +834,8 @@ def set_parameter(self, verbose: bool = True, **kwargs):
"restart": False,
"encounter_save" : "NONE",
"coarray" : False,
"simdir" : self.simdir
"simdir" : self.simdir,
"container" : None,
}
param_file = kwargs.pop("param_file",None)

Expand Down Expand Up @@ -891,8 +897,9 @@ def get_parameter(self, **kwargs):
return param_dict

def set_integrator(self,
codename: Literal["Swiftest", "Swifter", "Swift"] | None = None,
codename: None | Literal["Swiftest", "Swifter", "Swift"] = "Swiftest",
integrator: Literal["symba","rmvs","whm","helio"] | None = None,
container: Literal["docker", "singularity"] | None = None,
mtiny: float | None = None,
gmtiny: float | None = None,
verbose: bool | None = None,
Expand All @@ -905,6 +912,10 @@ def set_integrator(self,
codename : {"swiftest", "swifter", "swift"}, optional
integrator : {"symba","rmvs","whm","helio"}, optional
Name of the n-body integrator that will be used when executing a run.
container : {"docker", "singularity"}, default None
Specify whether the driver exectuable is run from a Docker or Singularity container.
Setting to `None` uses the local executable.
*Note*: Only valid for Swiftest.
mtiny : float, optional
The minimum mass of fully interacting bodies. Bodies below this mass interact with the larger bodies,
but not each other (SyMBA only). *Note.* Only mtiny or gmtiny is accepted, not both.
Expand All @@ -926,7 +937,15 @@ def set_integrator(self,
# TODO: Improve how it finds the executable binary

update_list = []


if container is not None:
valid_container = ["DOCKER", "SINGULARITY"]
if container.upper() not in valid_container:
warnings.warn(f"{container} is not a valid container type. Valid options are None, ",",".join(valid_container),stacklevel=2)
self.container = None
else:
self.container = container.upper()

if codename is not None:
valid_codename = ["Swiftest", "Swifter", "Swift"]
if codename.title() not in valid_codename:
Expand All @@ -941,7 +960,13 @@ def set_integrator(self,
self.param['! VERSION'] = f"{self.codename} input file"
update_list.append("codename")
if self.codename == "Swiftest":
self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver"
if self.container is None:
self.binary_source = Path(_pyfile).parent.parent.parent.parent / "bin" / "swiftest_driver"
elif self.container == "DOCKER":
self.binary_source = Path(_pyfile).parent.parent.parent.parent / "docker" / "bin" / "swiftest_driver"
elif self.container == "SINGULARITY":
self.binary_source = Path(_pyfile).parent.parent.parent.parent / "singularity" / "bin" / "swiftest_driver"

self.binary_path = self.simdir.resolve()
self.driver_executable = self.binary_path / "swiftest_driver"
if not self.binary_source.exists():
Expand Down Expand Up @@ -1016,7 +1041,8 @@ def get_integrator(self,arg_list: str | List[str] | None = None, verbose: bool |
valid_instance_vars = {"codename": self.codename,
"integrator": self.integrator,
"param_file": str(self.param_file),
"driver_executable": str(self.driver_executable)}
"driver_executable": str(self.driver_executable),
"container": self.container}

try:
self.integrator
Expand Down
2 changes: 1 addition & 1 deletion singularity/bin/swiftest_driver
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh --
docker run -v $(pwd):$(pwd) -w $(pwd) -t -e OMP_NUM_THREADS -e FOR_COARRAY_NUM_IMAGES swiftest:latest
singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@"
3 changes: 3 additions & 0 deletions singularity/setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# source this file to set the path to the swiftest.sif file
export SWIFTEST_SIF=${PWD}

0 comments on commit 05aa725

Please sign in to comment.