From d58e9815d5fd619df7ddf6335a92225b2c83610d Mon Sep 17 00:00:00 2001 From: Florian Felten Date: Wed, 14 May 2025 17:25:58 +0200 Subject: [PATCH 1/4] Change the path to bashrc in Airfoil --- engibench/problems/airfoil/v0.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engibench/problems/airfoil/v0.py b/engibench/problems/airfoil/v0.py index 6e96747e..3581833b 100644 --- a/engibench/problems/airfoil/v0.py +++ b/engibench/problems/airfoil/v0.py @@ -296,7 +296,7 @@ def __design_to_simulator_input(self, design: DesignType, config: dict[str, Any] # The script generates the mesh and FFD files try: bash_command = ( - "source ~/.bashrc_mdolab && cd /home/mdolabuser/mount/engibench && python " + "source /home/mdolabuser/.bashrc_mdolab && cd /home/mdolabuser/mount/engibench && python " + self.__docker_study_dir + "/pre_process.py" + " > " @@ -410,7 +410,7 @@ def simulate(self, design: DesignType, config: dict[str, Any] | None = None, mpi # The script takes a mesh and ffd and performs an optimization try: bash_command = ( - "source ~/.bashrc_mdolab && cd /home/mdolabuser/mount/engibench && mpirun -np " + "source /home/mdolabuser/.bashrc_mdolab && cd /home/mdolabuser/mount/engibench && mpirun -np " + str(mpicores) + " python " + self.__docker_study_dir @@ -484,7 +484,7 @@ def optimize( # Launches a docker container with the optimize_airfoil.py script # The script takes a mesh and ffd and performs an optimization bash_command = ( - "source ~/.bashrc_mdolab && cd /home/mdolabuser/mount/engibench && mpirun -np " + "source /home/mdolabuser/.bashrc_mdolab && cd /home/mdolabuser/mount/engibench && mpirun -np " + str(mpicores) + " python " + self.__docker_study_dir From 29edc09f033aa6efe8ff4ad7f6c0707cbf32d7a7 Mon Sep 17 00:00:00 2001 From: fgvangessel-umd Date: Tue, 27 May 2025 15:22:29 -0400 Subject: [PATCH 2/4] Updated singularity pull function to reflect Docker-Singularity naming conventions. Additionally, chekc for presence of container prior to pull. --- engibench/utils/container.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/engibench/utils/container.py b/engibench/utils/container.py index c3f2cfb0..de989234 100644 --- a/engibench/utils/container.py +++ b/engibench/utils/container.py @@ -230,9 +230,33 @@ def pull(cls, image: str) -> None: Args: image: Container image to pull. """ + # Convert to docker URI if needed if "://" not in image: - image = "docker://" + image - subprocess.run([cls.executable, "pull", image], check=True) + docker_uri = "docker://" + image + else: + docker_uri = image + # Extract just the image part if it's already a docker URI + if docker_uri.startswith("docker://"): + image = docker_uri[len("docker://"):] + + # Parse the image name to match Singularity's naming convention + # For "mdolab/public:u22-gcc-ompi-stable", Singularity creates "public_u22-gcc-ompi-stable.sif" + if '/' in image: + # Get the part after the last '/' + image_name = image.split('/')[-1] + else: + image_name = image + + # Replace ":" with "_" in the image name + sif_filename = image_name.replace(":", "_") + ".sif" + + # Check if the image already exists + if os.path.exists(sif_filename): + print(f"Image file already exists: {sif_filename} - skipping pull") + return + + # Image doesn't exist, proceed with pull + subprocess.run([cls.executable, "pull", docker_uri], check=True) @classmethod def run( From 6cdfad1404b7901ea69278eafc69caf1e10eaf8b Mon Sep 17 00:00:00 2001 From: fgvangessel-umd Date: Tue, 27 May 2025 16:05:02 -0400 Subject: [PATCH 3/4] Added additional mount location to address singularity requirement for copying files to containers /tmp directory --- engibench/problems/airfoil/v0.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/engibench/problems/airfoil/v0.py b/engibench/problems/airfoil/v0.py index 3581833b..a860c545 100644 --- a/engibench/problems/airfoil/v0.py +++ b/engibench/problems/airfoil/v0.py @@ -210,6 +210,7 @@ def __init__(self, base_directory: str | None = None) -> None: # Docker target directory # This is used for files that are mounted into the docker container self.__docker_base_dir = "/home/mdolabuser/mount/engibench" + self.__docker_tmp_dir = "/tmp" self.__docker_target_dir = self.__docker_base_dir + "/engibench_studies/problems/airfoil" super().__init__() @@ -308,7 +309,7 @@ def __design_to_simulator_input(self, design: DesignType, config: dict[str, Any] command=["/bin/bash", "-c", bash_command], image=self.container_id, name="machaero", - mounts=[(self.__local_base_directory, self.__docker_base_dir)], + mounts=[(self.__local_base_directory, self.__docker_base_dir), (self.__local_base_directory, self.__docker_tmp_dir)], ) except Exception as e: @@ -423,7 +424,7 @@ def simulate(self, design: DesignType, config: dict[str, Any] | None = None, mpi command=["/bin/bash", "-c", bash_command], image=self.container_id, name="machaero", - mounts=[(self.__local_base_directory, self.__docker_base_dir)], + mounts=[(self.__local_base_directory, self.__docker_base_dir), (self.__local_base_directory, self.__docker_tmp_dir)], ) except Exception as e: raise RuntimeError( @@ -497,7 +498,7 @@ def optimize( command=["/bin/bash", "-c", bash_command], image=self.container_id, name="machaero", - mounts=[(self.__local_base_directory, self.__docker_base_dir)], + mounts=[(self.__local_base_directory, self.__docker_base_dir), (self.__local_base_directory, self.__docker_tmp_dir)], ) except Exception as e: raise RuntimeError(f"Optimization failed: {e!s}. Check logs in {self.__local_study_dir}") from e From d594d38516a7da04d91231cb4eb92557b7b2d4eb Mon Sep 17 00:00:00 2001 From: fgvangessel-umd Date: Tue, 27 May 2025 16:16:46 -0400 Subject: [PATCH 4/4] Updated formatting with ruff --- engibench/utils/container.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/engibench/utils/container.py b/engibench/utils/container.py index de989234..441e37a3 100644 --- a/engibench/utils/container.py +++ b/engibench/utils/container.py @@ -238,23 +238,19 @@ def pull(cls, image: str) -> None: # Extract just the image part if it's already a docker URI if docker_uri.startswith("docker://"): image = docker_uri[len("docker://"):] - + # Parse the image name to match Singularity's naming convention # For "mdolab/public:u22-gcc-ompi-stable", Singularity creates "public_u22-gcc-ompi-stable.sif" - if '/' in image: - # Get the part after the last '/' - image_name = image.split('/')[-1] - else: - image_name = image - + image_name = image.split("/")[-1] if "/" in image else image + # Replace ":" with "_" in the image name sif_filename = image_name.replace(":", "_") + ".sif" - + # Check if the image already exists if os.path.exists(sif_filename): print(f"Image file already exists: {sif_filename} - skipping pull") return - + # Image doesn't exist, proceed with pull subprocess.run([cls.executable, "pull", docker_uri], check=True)