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
6 changes: 6 additions & 0 deletions engibench/problems/heatconduction2d/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def run_container_script(
shutil.copy(cli_module_path, "templates/engibench/utils")
shutil.copy(script, "templates/")

# Keep the FEniCS JIT cache on the host, otherwise every container run recompiles all forms.
jit_cache = Path(os.environ.get("SCRATCH") or Path.home(), ".cache", "engibench", "dijitso")
jit_cache.mkdir(parents=True, exist_ok=True)

container.run(
command=[
"python3",
Expand All @@ -39,7 +43,9 @@ def run_container_script(
mounts=[
(os.getcwd(), "/home/fenics/shared"),
(cli_module_path, "/home/fenics/shared/templates/engibench/utils/cli.py"),
(str(jit_cache), "/home/fenics/.cache/dijitso"),
],
env={"DIJITSO_CACHE_DIR": "/home/fenics/.cache/dijitso"},
stdin=stdin,
)
return output_path
Expand Down
21 changes: 21 additions & 0 deletions tests/test_heatconduction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path
from typing import Any

import pytest

from engibench.problems.heatconduction2d import shared
from engibench.utils import container


def test_run_container_script_mounts_jit_cache(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
calls: list[dict[str, Any]] = []
monkeypatch.setattr(container, "run", lambda **kwargs: calls.append(kwargs))
monkeypatch.setenv("SCRATCH", str(tmp_path))
monkeypatch.chdir(tmp_path)

shared.run_container_script("image", Path(shared.__file__), (), "out.txt")

jit_cache = tmp_path / ".cache" / "engibench" / "dijitso"
assert jit_cache.is_dir()
assert (str(jit_cache), "/home/fenics/.cache/dijitso") in calls[0]["mounts"]
assert calls[0]["env"] == {"DIJITSO_CACHE_DIR": "/home/fenics/.cache/dijitso"}
Loading