Skip to content

feat(smoke-tests): CI caches — JAX compile cache + simulated datasets across runs, cache state on every timing row #210

Closed

Description

@Jammy2211

Overview

autonerves/jax_wrapper.py already writes a persistent JAX compilation cache (JAX_COMPILATION_CACHE_DIR, default ~/.cache/pyauto_jax, JAX_PERSISTENT_CACHE_MIN_COMPILE_TIME_SECS=1), certified by the closed jax-compile-time arc at 51× local / 5.9× A100. The one reusable smoke workflow every workspace / _test / HowTo gate calls — .github/workflows/smoke-tests.yml — has no actions/cache step, so the cache helps only within one job and is discarded between runs. Likewise dataset/ is gitignored in every workspace, so CI clones fresh and should_simulate re-simulates every dataset family on every run (~10–20 s per family including import).

The legacy digest (timings/legacy_round_2026-09.md, #209) shows where that lands: in both _test flagships the time sits in ~15 compile-dominated jax_likelihood scripts (autogalaxy_test 537 s / 39 scripts; autolens_test 435 s / 27). This task adds both caches to the reusable workflow, records the cache state into the timing artifact so every ingested row says whether it ran hot or cold, and lets the record measure the win honestly. Phase 7 of the ci-timing-fast-tests epic, pulled forward before the phase-5/6 rebuild waves per the epic ledger's review (the waves then target what remains once compile is cached, and their before/after is measured on one cache state).

Plan

  • smoke-tests.yml: restore/save the JAX compile cache (explicit JAX_COMPILATION_CACHE_DIR under the job workspace) keyed on runner OS × Python leg × jaxlib version × a manual epoch salt; restore/save workspace/dataset keyed on the hash of the simulator scripts × the dependency-chain HEAD SHAs × the salt. Every cache step non-fatal — the workflow is referenced @main by eleven repos.
  • Write test-results/cache_state.json after the runner (restored key, hit/miss, sizes before/after) so it rides the existing smoke-timings-<py> artifact.
  • smoke_timings ingests it: legs/rows/record lines gain an additive cache field; drift is not classified across differing known cache states (a cold run after a hot one is not a regression); the board's per-repo lines say jax cache hit/miss.
  • Measure after merge from the record: hit vs miss per-script seconds and gate wall-clock, and the restore/save overhead on the small repos.
Detailed implementation plan

Affected Repositories

  • PyAutoHeart (primary, only). The workspaces inherit through the reusable workflow — no per-workspace change. PyAutoNerves is named in the prompt but needs no change: its default cache location is simply overridden by the workflow env.

Work Classification

Library (organ code / CI infrastructure) — no workspace follow-up.

Branch Survey

Repository Current Branch Dirty?
./PyAutoHeart main @ ad56720 clean

Branch: claude/ci-test-timing-epic-ke2lul (designated for the epic; restarted from main; cloud session, no task worktree).

Facts the design rests on

  • The smoke runner builds each script's env from os.environ.copy() plus the profile (PyAutoHands/autohands/env_config.py), so a job-level JAX_COMPILATION_CACHE_DIR reaches every script subprocess; autonerves/jax_wrapper.py only sets its default when the var is absent.
  • should_simulate (PyAutoArray/autoarray/util/dataset_util.py) keeps a dataset only when its SMALLDAT stamp/shape matches the regime in force; a restored small-regime dataset is reused by small-regime scripts and deleted+re-simulated by full-regime ones — exactly today's within-job behaviour, so restoring dataset/ changes nothing about correctness, only about how often the first script of each family pays the simulation.
  • Simulators live at **/simulator*.py, **/simulator/**, **/simulators/** in the workspaces (e.g. autolens_workspace_test has 18 such files); dataset/** is gitignored with an ! allowlist for real/external data.
  • The smoke-timings-<py> upload already globs workspace/test-results/, so a new sidecar file there ships with no change to the upload.

Implementation Steps

  1. smoke-tests.yml — job-level env: PYAUTO_CACHE_EPOCH: "1" (the manual salt; bump to invalidate every cache at once — comment says so) and JAX_COMPILATION_CACHE_DIR: ${{ github.workspace }}/.pyauto_jax_cache on the runner step's env (beside JAX_ENABLE_X64), with a comment that autonerves would otherwise default to ~/.cache/pyauto_jax; an explicit workspace path is what the cache step can name.

  2. Step "Resolve cache keys" (after "Install", id: keys, continue-on-error: true):

    • jaxlib=$(python -c 'import jaxlib; print(jaxlib.__version__)' 2>/dev/null || echo nojax) → output jaxlib.
    • chain hash: for dep in ${{ inputs.chain }}; do git -C "$dep" rev-parse HEAD; done | sha256sum | cut -c1-16 → output chain (the inputs.chain value reaches the shell through env:, never interpolated into run:; the existing clone step's pattern is the model).
    • simulator hash: ${{ hashFiles('workspace/**/simulator*.py', 'workspace/**/simulator/**', 'workspace/**/simulators/**') }} → output sims (empty when a workspace has none — the dataset cache then keys on the chain only, which is still correct).
  3. Step "Restore the JAX compile cache" — actions/cache/restore@v4, id: jax-cache, continue-on-error: true, path: ${{ github.workspace }}/.pyauto_jax_cache, key: pyauto-jax-${{ runner.os }}-py${{ matrix.python-version }}-jaxlib${{ steps.keys.outputs.jaxlib }}-e${{ env.PYAUTO_CACHE_EPOCH }}-${{ github.run_id }}, restore-keys: pyauto-jax-${{ runner.os }}-py${{ matrix.python-version }}-jaxlib${{ steps.keys.outputs.jaxlib }}-e${{ env.PYAUTO_CACHE_EPOCH }}-. Comment: the run-id suffix makes every save a fresh superset (the standard accumulating-cache pattern); traced-code changes miss individual entries naturally, which is correct; the jaxlib version is in the key because a compiled executable is jaxlib-specific.

  4. Step "Restore simulated datasets" — actions/cache/restore@v4, id: dataset-cache, continue-on-error: true, path: workspace/dataset, key: pyauto-datasets-${{ runner.os }}-e${{ env.PYAUTO_CACHE_EPOCH }}-sim${{ steps.keys.outputs.sims }}-chain${{ steps.keys.outputs.chain }}-${{ github.run_id }}, restore-keys: the same prefix without the run id and nothing broader — a different simulator or library commit must miss (correctness over hit rate; comment says why). Not keyed on the Python leg: simulated FITS do not depend on the interpreter minor.

  5. Runner step unchanged apart from the env var in step 1.

  6. Step "Record cache state (unit of the timing dataset)" — if: always(), continue-on-error: true, after the runner, before the upload: writes workspace/test-results/cache_state.json = {"schema": "cache_state/1", "epoch": "<salt>", "jax": {"path", "restored_key": "<cache-matched-key or ''>", "hit": <bool: matched key non-empty>, "exact": <bool: cache-hit == 'true'>, "size_mb_before", "size_mb_after", "entries_before", "entries_after"}, "datasets": {same fields}}. Sizes via du -sm, entry counts via find -type f | wc -l; the "before" figures are captured by a tiny step right after the restores (id: cache-before, outputs) so the record step can compare. A Python heredoc reading the figures from env vars (never ${{ }} inside the script body).

  7. Save steps — actions/cache/save@v4 with continue-on-error: true: JAX cache if: always() (a compiled entry is complete or absent; a red script does not poison it) and datasets if: success() only (a killed simulator can leave a truncated FITS that should_simulate would then keep). Both skip the save when nothing changed (entries_after == entries_before && size_after == size_before → the step's if: reads the record step's outputs) so an unchanged cache is not re-uploaded on every run.

  8. Heart ingester (heart/checks/smoke_timings.py) — additive:

    • parse_cache_state(text) -> (dict|None, error) validating schema == "cache_state/1", normalised to {"jax": {"hit": bool|None, "restored_key": str}, "datasets": {...}, "epoch": str}.
    • read_downloaded_leg also reads cache_state.json when present → leg cache: {"jax": "hit"|"miss"|"unknown", "datasets": "hit"|"miss"|"unknown", "epoch": str} (unknown when the file is absent — a run from before this shipped).
    • aggregate: each repos[] item and each rows[] item gains cache ({"jax", "datasets"} on the item; cache_jax on the row for the field that matters to compile time). classify_drift gains prev_cache/cache awareness through a thin wrapper: when both the previous and current jax cache states are known and differ, no comparison (ok, no ratio) — a cold run after a hot one is not a regression and must not raise a warn. Prompts and events unchanged.
    • Board (heart/dashboard.py _smoke_timings_section): the per-repo line gains [jax cache hit] / [jax cache miss] when known; nothing when unknown (older snapshots byte-identical).
    • heart/timings.py: scripts_lines_from_rollup writes cache: {"jax", "datasets"} on each record line (absent → "unknown"); previous_script_rows returns cache_jax on each prev row so the drift rule can read it. README: the field and the "never compare across cache states" rule.
  9. Tests — tests/test_workflow_wiring.py or a new tests/test_smoke_tests_wiring.py: the two restore steps exist with continue-on-error, the JAX key names the Python leg, jaxlib and the epoch salt, the dataset key names the simulator hash and the chain hash and has no broad restore-key, the runner env sets JAX_COMPILATION_CACHE_DIR under the workspace, the record step is if: always(), the dataset save is if: success(), the JAX save if: always(), PYAUTO_CACHE_EPOCH is declared. tests/test_smoke_timings.py: cache-state parse, leg cache from a downloaded dir with/without the file, rows/items carry it, drift skipped across differing known states and classified normally when equal or unknown; tests/test_timings.py: record line carries cache, previous_script_rows returns cache_jax; tests/test_dashboard.py: the bracket suffix only when known. Fake names throughout; existing tests unmodified.

  10. Validate: yaml.safe_load on the workflow, full suite green (baseline 864), tenant firewall OK. After merge (judgment tier): the first PR run on a _test repo is a miss (saves), the second a hit; compare the per-script seconds of the jax_likelihood class and the gate p50 across the two in the record, and the size_mb/restore overhead for autocti_workspace_test (3 entries) — write the numbers into the issue's Shipped comment and the epic ledger.

Out of scope

  • Any change to script content, datasets or pins (phases 5/6).
  • Caching pip installs (setup-python already caches wheels in lib-tests.yml; the smoke install epilogue is workspace-owned and out of this phase).

Original Prompt

Click to expand starting prompt
# CI caches in the reusable smoke workflow: JAX compile cache + dataset builds

Type: feature
Target: PyAutoHeart
Repos:
- PyAutoHeart
- PyAutoNerves
Difficulty: large
Autonomy: safe
Priority: high
Status: formalised
Consequence: judge
Review-minutes: 25
Unattended: needs-slicing
Epic: ci-timing-fast-tests
Phase: 7

CI caches in the reusable smoke workflow: persist the JAX compile cache and dataset builds across runs.

`autonerves/jax_wrapper.py:98-125` already auto-writes a persistent JAX compilation cache
to `~/.cache/pyauto_jax` (JAX_PERSISTENT_CACHE_MIN_COMPILE_TIME_SECS=1), and the closed
jax-compile-time arc certified the cache at both scales (51x local, 5.9x A100 end-to-end).
But `PyAutoHeart/.github/workflows/smoke-tests.yml` — the one reusable workflow every
workspace/_test/HowTo smoke gate calls — has NO actions/cache step: the cache helps within
one job (scripts are subprocesses) and is discarded between runs.

1) Add an `actions/cache` step for `~/.cache/pyauto_jax`, keyed on jaxlib version + python
matrix leg (+ a manual epoch salt for invalidation). Expected: removes the 12-18s+ compile
from every `ENV: jax` script on cache-hit runs — plausibly 30-50% off the jax_likelihood
wall total. Traced-code changes miss the cache naturally, which is correct. (Run
33078033016 already refuted any interaction between the cache and the Eigen-pool hang.)

2) Same mechanism for simulated dataset builds: `should_simulate` auto-simulation persists
datasets locally but CI runners start clean, so each job re-simulates each dataset family
(~10-20s incl. import per family). Cache the dataset build trees keyed on a hash of the
simulator scripts so any simulator edit invalidates.

3) Measure honestly: compare cache-hit vs cache-miss gate wall-clock on the phase-1/2
timing surface, and confirm cache restore/save overhead doesn't eat the win for the small
repos (autocti: 3 entries).

Activity

  1. Jammy2211 commented on Sep 6, 2026

    @Jammy2211
    ContributorAuthor

    Shipped

    PyAutoHeart#211 → bfcd302, merged 2026-09-06 (CI green on both matrix legs; suite 864 → 893).

    • smoke-tests.yml (reusable, called by eleven repos): the JAX persistent compile cache is restored/saved per runner OS × Python leg × jaxlib × PYAUTO_CACHE_EPOCH, run-id suffixed (accumulating), saved even on red runs; the workspace's simulated dataset/ tree is restored/saved keyed on the simulator-script hash × dependency-chain SHAs × the salt with no broader fallback, saved only on green runs. JAX_COMPILATION_CACHE_DIR is an explicit workspace path in the runner env. Every new step is continue-on-error; the runner command is unchanged; the diff is purely additive.
    • test-results/cache_state.json rides the existing smoke-timings artifact; smoke_timings, the timings/scripts record and the board carry cache on every leg/row ([jax cache hit|miss]), and drift is never classified across two known but different cache states.

    Measurement (item 3 of the prompt) is pending live runs: the first PR run on each repo after this merge is a miss that saves; the second restores. Compare the jax_likelihood per-script seconds and gate p50 hot vs cold in timings/scripts/ and timings/gates.jsonl (the rows now say which they were), and the restore/save overhead on autocti_workspace_test. Numbers go into the epic ledger when they exist.

    Phase 7 of the ci-timing-fast-tests epic; phase 5 (the autogalaxy_workspace_test physical+fast rebuild) is next.


    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