Skip to content

Commit 6123edc

Browse files
authored
Merge pull request #3 from ActivitySim/fix/writable-numba-cache
Fix non-root Numba caching and release 0.1.2
2 parents d09b0e7 + cb968bd commit 6123edc

6 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uvx abench --help
1111
uvx abench experiments.yaml
1212
```
1313

14-
For a specific release use `uvx abench@0.1.1 experiments.yaml`; use
14+
For a specific release use `uvx abench@0.1.2 experiments.yaml`; use
1515
`uvx abench@latest` to refresh to the latest release. Docker and model data must
1616
still be available locally. macOS and Linux hosts are supported.
1717

@@ -414,6 +414,12 @@ persistent host cache defaults to `~/.cache/abench/flows`. Change it with
414414
writes with `--no-reuse-flows` (`reuse_flows: false`). `--cache-from` remains an
415415
explicit seed option with its existing stricter dependency checks.
416416

417+
Containers set `NUMBA_CACHE_DIR` to `/results/cache/flows/.numba`, a writable
418+
directory included in those snapshots. This covers installed-library helpers
419+
(such as `sharrow.maths`) as well as generated flows without writing into
420+
root-owned site-packages or relying on the container user's home directory.
421+
Warmup may recompile entries from older snapshots that used Numba's default paths.
422+
417423
Compatibility uses the **installed** Sharrow, Numba, llvmlite, and NumPy versions,
418424
plus their source repository/commit identities when applicable, Python version,
419425
and container architecture/CPU features. ActivitySim and model settings are

‎src/abench/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Reproducible ActivitySim experiments in Linux containers."""
22

3-
__version__ = "0.1.1"
3+
__version__ = "0.1.2"

‎src/abench/cli.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def container_phase(spec, output, data, image, phase_name):
187187
# so outputs and caches remain writable between attempts and experiments.
188188
"--user",
189189
f"{os.getuid()}:{os.getgid()}",
190+
# Installed packages and the default home are not writable by this UID.
191+
# Configure Numba before Python starts, including all spawned workers.
192+
# Keep compiled artifacts in the shared flow snapshot so warmup work is
193+
# reusable across measured attempts and compatible experiments.
194+
"--env",
195+
"NUMBA_CACHE_DIR=/results/cache/flows/.numba",
190196
"--env",
191197
f"BENCH_SPEC_PATH=/results/{phase_name}/{snapshot_name}",
192198
"--env",

‎src/abench/runtime/worker.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import subprocess
77
import sys
8+
import tempfile
89
import time
910
from pathlib import Path
1011

@@ -255,6 +256,14 @@ def supervise(spec, phase):
255256
(phase / "output").mkdir()
256257
for name in ("flows", "model"):
257258
Path(f"/results/cache/{name}").mkdir(parents=True, exist_ok=True)
259+
# Fail before running models if the configured compilation cache is unusable.
260+
numba_cache = Path(os.environ["NUMBA_CACHE_DIR"])
261+
try:
262+
numba_cache.mkdir(parents=True, exist_ok=True)
263+
with tempfile.TemporaryFile(dir=numba_cache):
264+
pass
265+
except OSError as error:
266+
raise RuntimeError(f"Numba cache is not writable: {numba_cache}") from error
258267
env = dict(os.environ, BENCH_MODEL="1", BENCH_PHASE_DIR=str(phase))
259268
env["BENCH_STRICT_CACHE"] = "0"
260269
env["BENCH_TRACK_CACHE"] = (

‎tests/fixtures/tiny/tiny_extension.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def bench_initialize(state: workflow.State):
2828
@workflow.step
2929
def bench_compute(state: workflow.State, households: pd.DataFrame):
3030
"""Exercise compiled overload reuse, including a measured-only test signature."""
31+
# Unlike generated modules, installed Sharrow helpers live in root-owned
32+
# site-packages. Importing them must work as the unprivileged model user,
33+
# including in spawned workers, and their compiled code must load on reuse.
34+
from sharrow.maths import piece
35+
36+
assert piece(3.0, 1.0, 4.0) == 2.0
3137
sys.path.insert(0, state.settings.sharrow_cache_dir)
3238
twice = importlib.import_module("tiny_generated").twice
3339
households = households.copy()

‎tests/test_docker.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_tiny_model(tmp_path, multiprocess, sharrow, retry):
6464
assert cli.main(args) == 0
6565
run = load_run(output)
6666
assert run["valid"]
67+
assert list((output / "cache/flows/.numba").rglob("maths.piece-*.nbc"))
6768
attempts = run["spec"]["attempts"]
6869
assert len(attempts) == (2 if retry else 1)
6970
assert attempts[-1]["status"] == "accepted"

0 commit comments

Comments
 (0)