diff --git a/engibench/problems/heatconduction2d/shared.py b/engibench/problems/heatconduction2d/shared.py index a3f8c8db..7882b63b 100644 --- a/engibench/problems/heatconduction2d/shared.py +++ b/engibench/problems/heatconduction2d/shared.py @@ -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", @@ -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 diff --git a/tests/test_heatconduction.py b/tests/test_heatconduction.py new file mode 100644 index 00000000..29c4998b --- /dev/null +++ b/tests/test_heatconduction.py @@ -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"}