diff --git a/cmake/Modules/SetFortranFlags.cmake b/cmake/Modules/SetFortranFlags.cmake index 782fdc808..ead3e1433 100644 --- a/cmake/Modules/SetFortranFlags.cmake +++ b/cmake/Modules/SetFortranFlags.cmake @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index f1532b7c3..c6d728b2d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/bin/swiftest_driver b/docker/bin/swiftest_driver index 0553553a7..d2cb42a90 100755 --- a/docker/bin/swiftest_driver +++ b/docker/bin/swiftest_driver @@ -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 "$@" diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 804eee651..0ae7f540b 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -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" @@ -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) @@ -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"] @@ -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) @@ -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, @@ -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. @@ -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: @@ -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(): @@ -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 diff --git a/singularity/bin/swiftest_driver b/singularity/bin/swiftest_driver index 45765b4a7..dba0863a9 100755 --- a/singularity/bin/swiftest_driver +++ b/singularity/bin/swiftest_driver @@ -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 \ No newline at end of file +singularity run --bind $(pwd):$(pwd) --env OMP_NUM_THREADS=${OMP_NUM_THREADS},FOR_COARRAY_NUM_IMAGES=${FOR_COARRAY_NUM_IMAGES} ${SWIFTEST_SIF} "$@" \ No newline at end of file diff --git a/singularity/setenv.sh b/singularity/setenv.sh new file mode 100644 index 000000000..769339754 --- /dev/null +++ b/singularity/setenv.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# source this file to set the path to the swiftest.sif file +export SWIFTEST_SIF=${PWD} \ No newline at end of file