Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions engibench/problems/airfoil/v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
# 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"

Check failure on line 213 in engibench/problems/airfoil/v0.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (S108)

engibench/problems/airfoil/v0.py:213:33: S108 Probable insecure usage of temporary file or directory: "/tmp"
self.__docker_target_dir = self.__docker_base_dir + "/engibench_studies/problems/airfoil"

super().__init__()
Expand Down Expand Up @@ -296,7 +297,7 @@
# 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"
+ " > "
Expand All @@ -308,7 +309,7 @@
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:
Expand Down Expand Up @@ -410,7 +411,7 @@
# 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
Expand All @@ -423,7 +424,7 @@
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(
Expand Down Expand Up @@ -484,7 +485,7 @@
# 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
Expand All @@ -497,7 +498,7 @@
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
Expand Down
24 changes: 22 additions & 2 deletions engibench/utils/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading