Skip to content

feat(ci): JAX+numba caches in lib-tests, numba cache in smoke-tests #215

Closed

Description

@Jammy2211

Overview

Census option O1 of the ci-timing-fast-tests epic (timings/unit_import_census_2026-09.md §6), widened by one finding. Library CI is compile-bound: lib-tests.yml restores no JAX and no numba cache (ten of PyAutoArray's 25 slowest CI tests are 24.8 s of a 101 s leg cold-numba, ≤ 0.02 s warm; a persistent JAX cache halves the local suite 43 → 21 s). The census also says smoke-tests.yml "has both since phase 7" — it does not: #211 cached the JAX compile cache and the datasets; NUMBA_CACHE_DIR=/tmp/numba_cache is set and nothing restores or saves it, so every smoke run compiles numba cold (the cold-numba term phase 8 found inflating three user-workspace scripts 4–6×).

One premise checked before planning: numba stamps every cache entry with the source file's (st_mtime, st_size) (numba/core/caching.py, _SourceFileBackedLocatorMixin.get_source_stamp) and stores it under NUMBA_CACHE_DIR/<parentdir>_<sha1(abs dirname)>. A fresh clone or a fresh pip install gives every source file a new mtime, so a restored numba cache would miss every entry unless the mtimes are normalised. The plan sets each .py file's mtime to a function of its content hash, so the stamp becomes a content fingerprint: identical content hits, changed content misses, and the prefix restore-keys fallback is safe.

Plan

  • Give lib-tests.yml's unittest job the JAX compile cache smoke-tests.yml already has, plus a numba cache, with the same discipline (restore/save, run-id-suffixed accumulating keys, epoch salt, every new step continue-on-error, pytest command byte-identical apart from env).
  • Add the numba cache to smoke-tests.yml beside the JAX one, and a "stamp source mtimes from content" step in both workflows so numba's stamps survive a fresh checkout.
  • Extend the cache_state.json sidecar with a numba section; lib-tests.yml writes one too (jax + numba) into test-results/ so it rides the existing unit-timings-<py> artifact.
  • Ingest: smoke_timings reads numba; unit_timings reads the sidecar and carries cache on every leg; the record (timings/scripts, timings/unit) stores it; the drift rules never compare two known but different cache states (unit rows compare on the combined jax+numba state); the board brackets it.
  • Wiring tests for both workflows; a dated correction note appended to the census §5.3.
  • Hot-vs-cold is read back from the record after the next daily runs, not claimed here. Cache scoping: a PR-branch save is invisible to main, so the first main run after merge misses and seeds.
Detailed implementation plan

Affected Repositories

  • PyAutoHeart (primary, only)

Branch Survey

Repository Current Branch Dirty?
./pyautoheart main clean

Suggested branch: feature/lib-tests-compile-caches

Implementation Steps

  1. .github/workflows/lib-tests.yml (unittest job only; unittest-nojax stays unchanged — its wiring test asserts that):
    • job-level env: PYAUTO_CACHE_EPOCH: "1".
    • After the Install step: Resolve cache keys (id keys, continue-on-error): jaxlib version or nojax; chain = sha256 (16 hex) over git rev-parse HEAD of the repo under test and its deps; pyfull = python -c 'import sys; print(sys.version.split()[0])' (the site-packages path carries the patch version, so it is part of what a numba path hashes to).
    • Restore the JAX compile cache (actions/cache/restore@v4, id jax-cache, path ${{ github.workspace }}/.pyauto_jax_cache, key pyauto-jax-${{ runner.os }}-py${{ matrix.python-version }}-jaxlib<jaxlib>-e<epoch>-${{ github.run_id }}, one prefix restore-keys line without the run id).
    • Restore the numba cache (actions/cache/restore@v4, id numba-cache, path ${{ github.workspace }}/.numba_cache, key pyauto-numba-${{ runner.os }}-py<pyfull>-e<epoch>-${{ github.run_id }}, one prefix fallback). Not keyed on the chain SHAs: the content-stamped mtimes below make a stale entry a miss, never a wrong answer, and a numba version bump invalidates the index on its own.
    • Stamp source mtimes from content (continue-on-error): a Python heredoc that, for every .py under each cloned repo dir (${{ steps.map.outputs.deps }} + repo) and under the installed PyAuto packages' importlib.util.find_spec(<pkg>).submodule_search_locations (no import of the package), sets mtime = 1_000_000_000 + int.from_bytes(sha1(content)[:4], "big") via os.utime. Roots reach the script through env:, never interpolated into the heredoc.
    • Measure the caches before the run (id cache-before) — du -sm + file count for both paths, as in smoke-tests.
    • Run tests: add JAX_COMPILATION_CACHE_DIR: ${{ github.workspace }}/.pyauto_jax_cache and NUMBA_CACHE_DIR: ${{ github.workspace }}/.numba_cache to the step env (add an env: block; the run: text is unchanged).
    • Record cache state (id cache-state, if: always(), continue-on-error): writes ${{ steps.map.outputs.repo }}/test-results/cache_state.json with schema cache_state/1, epoch, and jax + numba sections of the same shape as smoke's (restored_key, hit, exact, sizes/entries before/after); emits jax_changed / numba_changed outputs. Every input via env:.
    • Save the JAX compile cache / Save the numba cache (actions/cache/save@v4, if: always() && steps.cache-state.outputs.<x>_changed == 'true', continue-on-error, same path/key as the restores). Both save on red too: a compile-cache entry is complete or absent.
    • The existing upload step already globs test-results/, so the sidecar rides the artifact with no upload change.
  2. .github/workflows/smoke-tests.yml: Restore the numba cache (id numba-cache, path ${{ github.workspace }}/.numba_cache, key as above using steps.keys.outputs.pyfull, which the Resolve cache keys step gains) after the dataset restore; Stamp source mtimes from content over the installed PyAuto packages (site-packages — the smoke install is pip install ./<lib>, not PYTHONPATH) placed before the runner; Measure the caches before the run gains the numba path; the runner step's NUMBA_CACHE_DIR moves from /tmp/numba_cache to ${{ github.workspace }}/.numba_cache (Prepare cache dirs keeps making /tmp/matplotlib); Record cache state gains a numba section and numba_changed; Save the numba cache after the JAX save, if: always() && … numba_changed == 'true'. The runner command stays byte-identical.
  3. heart/checks/smoke_timings.py: parse_cache_state reads a numba section when present → hit/miss, absent → unknown (older sidecars predate it; unlike jax/datasets, absence is not evidence of a miss); cache_view and _cache_pair (in heart/timings.py) carry numba. classify_drift unchanged (scripts compare on jax, the compile term for scripts).
  4. heart/checks/unit_timings.py: read_downloaded_leg also reads the sidecar via smoke_timings.read_cache_state into meta["cache"]; build_sidecar legs carry cache; aggregate repos[] carries cache and classify_test_drift receives cache=unit_cache_state(cache) where the combined state is hit when jax and numba are both hit, miss when both miss, else unknown (a mixed or unknown leg compares normally); record_prev_rows rows carry cache_state. Schema docstrings updated.
  5. heart/timings.py: unit_lines_from_rollup writes "cache": {"jax", "numba"} per line (unknown on both for older rollups); previous_unit_rows hands cache_state to the drift rule; scripts lines gain numba in their cache block; module docstring / timings/README.md schema examples updated.
  6. heart/dashboard.py: the scripts per-repo bracket becomes [jax cache hit, numba hit] only when numba is known, else exactly [jax cache hit] as today; _unit_suite_details gains the same bracket when the leg's cache is known.
  7. Tests: extend tests/test_lib_tests_wiring.py (epoch salt, key shapes with one prefix fallback each, step order install → keys → restores → stamp → before → tests → record → upload → saves, non-fatality of every new step, pytest run: text unchanged, env keys named, sidecar schema string matches the check, nojax job unchanged); extend tests/test_smoke_tests_wiring.py for the numba restore/save/stamp steps and the runner env; unit tests for the numba section parse (present/absent/older sidecar), unit_cache_state, the unit leg carrying cache, the record line carrying it, the unit drift rule refusing two known different states, and both dashboard brackets. Fake names only.
  8. timings/unit_import_census_2026-09.md §5.3: append a dated note that smoke-tests.yml cached JAX + datasets only, and that this PR adds the numba cache to both workflows (the census's verdict is a record; do not rewrite it).
  9. Validate: python3 -m pytest -q -n auto in PyAutoHeart; then a dispatched run is not possible from here (the workflows are consumed @main), so hot-vs-cold lands in timings/unit/<repo>.jsonl and timings/scripts/<repo>.jsonl with the daily runs after merge and is read back, not claimed.

Key Files

  • .github/workflows/lib-tests.yml — the six libraries' reusable Tests gate
  • .github/workflows/smoke-tests.yml — the eleven workspaces' reusable smoke gate
  • heart/checks/smoke_timings.py, heart/checks/unit_timings.py — the two ingesters
  • heart/timings.py — the durable record
  • heart/dashboard.py — the board render
  • tests/test_lib_tests_wiring.py, tests/test_smoke_tests_wiring.py, tests/test_unit_timings.py, tests/test_smoke_timings.py, tests/test_timings.py, tests/test_dashboard.py
  • timings/unit_import_census_2026-09.md, timings/README.md

Original Prompt

Click to expand starting prompt

PyAutoMind draft/feature/pyautoheart/lib_tests_compile_caches_numba_smoke.md (moves to active/ with this issue). Census option O1 widened: JAX + numba caches for lib-tests.yml, a numba cache for smoke-tests.yml, cache state on every unit and script timing row, a dated census correction, honest measurement from the record after merge. Guard: settings and caches only; the closed jax-compile-time arc's verdict is honoured exactly; --xla_cpu_multi_thread_eigen=false stays wherever it is set.

Activity

  1. Jammy2211 commented on Sep 7, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    Merged in #217 (af03c75). lib-tests.yml now restores and saves a JAX compile cache and a numba cache with smoke-tests.yml's discipline; smoke-tests.yml gains the numba cache it never had; both stamp source mtimes from content so numba's (mtime, size) entry stamps survive a fresh checkout; the cache_state.json sidecar carries numba and rides the unit-timings artifact; unit and script timing rows record the cache state and the drift rules never compare two known but different states. Tests 893 → 924.

    What to watch: the callers consume both workflows @main, so the first main run of each seeds its caches and the second hits. Hot-vs-cold lands in timings/unit/<repo>.jsonl and timings/scripts/<repo>.jsonl with the daily runs; the board brackets it per leg. Mind record: PyAutoMind/complete/2026/09/lib-tests-compile-caches.md.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions