diff --git a/engibench/problems/airfoil/v0.py b/engibench/problems/airfoil/v0.py index 6e96747e..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__() @@ -296,7 +297,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" + " > " @@ -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: @@ -410,7 +411,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 @@ -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( @@ -484,7 +485,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 @@ -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 diff --git a/engibench/utils/container.py b/engibench/utils/container.py index c3f2cfb0..441e37a3 100644 --- a/engibench/utils/container.py +++ b/engibench/utils/container.py @@ -230,9 +230,29 @@ 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" + 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) @classmethod def run(