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
29 changes: 28 additions & 1 deletion agents/conductors/profiling/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ prompt, PyAutoMind `issued/profiling_agent.md`.
| Mode | Question | Emits |
|------|----------|-------|
| `campaign` | Which grid runs are done / CPU-unusable / missing on this tier, and how do I dispatch the rest? | dispatch plan (local sweep flags incl. the per-run timeout; A100 submit list) |
| `campaign` on a `profiling-summary@3` catalogue | Per likelihood × class × measurement, which planned cells are current / stale / superseded / missing? | coverage rows, per-cell states, local-host and class-mismatch flags, a plan routed by `host_class` |
| `ingest` | Which probe JSONs aren't in the vram tables yet, and which results have no pin? | table-update rows, pin list, baseline + dashboard steps |
| `ingest --axis compile` | Which warm compile rows are unpinned, and which have drifted from their pin? | drifted rows (with pinned vs observed), unpinned keys, confirm/classify/re-pin steps |
| `triage` | What do the pinned-drift findings mean? | per-finding classification: stale pin → re-pin here; library regression → `bug/` via intake |
Expand Down Expand Up @@ -79,6 +80,29 @@ neither counts as grid coverage, and neither is silently dropped.
instrument)` identity triple are reported as **sibling-instrument** records, not
as malformed — only a record missing *some* of its key fields is corruption.

### The lifecycle grid (`profiling-summary@3`)

When the published `dashboard/catalogue.json` is `profiling-summary@3`,
`campaign` diffs its `planned_cells` against its `records` instead of the sweep
grid. A cell is keyed (likelihood, instrument, `setup_id`, `host_class`,
`model_variant`, measurement) and is `current` (a current record on a
reference host), `stale` (that record's `release_pin` is behind the
catalogue's pin — the envelope's, else the newest record's), `superseded`
(only superseded records) or `missing`. The mirrored tree
`results/<dataset_type>/<variant>/<instrument>/<setup_id>/<host_class>/` is
read when it exists, and a directory with no catalogue row is listed.
`setup_id` follows `<backend>_<device>_<operator>_<precision>[_<transformer>]`;
anything else is refused as `SetupIdError`. `local_*` host classes never count
as current and are flagged. The class is the producer's declaration from a
Pulse `designation` decision: this conductor reports it, flags a record whose
class disagrees with its planned cell, and never assigns one. The plan routes
CPU cells to `--partition=ral` and A100 cells to `gpu` with `--gres`. A v2 or
absent catalogue keeps the legacy grid byte-identical.

The L0–L7 sequence a likelihood follows (register → figures → profile →
designate → validate → gradient → samplers → close) is the phase-prompt
template in [`skills/profiling/lifecycle.md`](../../../skills/profiling/lifecycle.md).

## Fundamental principles

- **The classification is the result** for CPU-unusable cells (the usability
Expand Down Expand Up @@ -123,7 +147,10 @@ as malformed — only a record missing *some* of its key fields is corruption.
versioned `profiling-summary` read contract, ingest receipts and the board.
It validates the exchange contract only and never judges; this conductor
(`triage`) stays the only judge of what a timing or a drift means, with the
human. The projects keep their producers, results, pins and drift policy.
human. Lookups read `class: optimal` + `status: current` unless asked
otherwise; `optimal` is always a Pulse `designation` decision. Full-fit
wall-time validation is Pulse's `walltime-validation@1` axis (instance
`lens-walltime`, producer autolens_inference), never PyAutoInsight's. The projects keep their producers, results, pins and drift policy.
Same split as Heart ↔ vitals and Eyes ↔ the Eyes conductor. (Organ row
born in PyAutoMind#463; its reader and board arrived in phase 2.)
- **Where drift candidates are read** — the
Expand Down
154 changes: 151 additions & 3 deletions agents/conductors/profiling/_catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def read_catalogue(ws: Path):
if not isinstance(doc, dict):
raise ValueError("Profiling catalogue must be an object")
if source == published:
if doc.get("schema") != "profiling-summary" or doc.get("version") not in (1, 2):
if doc.get("schema") != "profiling-summary" or doc.get("version") not in (1, 2, 3):
raise ValueError("Unsupported published profiling catalogue")
if "script_routes" not in doc:
return None
if doc["version"] != 2:
raise ValueError("Source routes require profiling-summary v2")
if doc["version"] not in (2, 3):
raise ValueError("Source routes require profiling-summary v2 or v3")
doc = doc["script_routes"]
if not isinstance(doc, dict) or doc.get("schema") != "profiling-script-routes" or doc.get("version") != 1:
raise ValueError("Unsupported profiling script routes schema/version")
Expand Down Expand Up @@ -119,3 +119,151 @@ def read_catalogue(ws: Path):
"compile_probe": probe,
"missing_sources": sorted(path for path in paths if not (ws / path).is_file()),
}


# ---------------------------------------------------------------------------
# profiling-summary@3: the lifecycle catalogue (PyAutoPulse REFERENCE.md)
# ---------------------------------------------------------------------------
#
# The vocabulary below mirrors the Pulse contract's enumerations for the fields
# the conductor reads. Pulse validates the whole document; the conductor only
# refuses what it cannot place on its coverage grid. It REPORTS the producer's
# `class` and `status` and never assigns either.

SETUP_ID_GRAMMAR = "<backend>_<device>_<operator>_<precision>[_<transformer>]"
SETUP_BACKENDS = ("numba", "jax")
SETUP_DEVICES = ("cpu", "gpu")
SETUP_OPERATORS = ("dense", "sparse", "na")
SETUP_PRECISIONS = ("fp64", "mixed")
# `na` is the absence of a transformer and is never spelled in a setup_id.
SETUP_TRANSFORMERS = ("dft", "nufft", "wtilde", "streaming")
DATASET_TYPES = ("imaging", "interferometer", "datacube", "point_source_image",
"point_source_source", "multi_galaxy", "group", "cluster",
"multi_dataset", "weak")
CLASSES = ("optimal", "secondary", "experimental")
# `archived` records leave `records[]` (counted in `archive_record_count`).
STATUSES = ("current", "superseded")
# Host classes with this prefix never qualify as `current` (reference-host rule).
LOCAL_HOST_PREFIX = "local_"
LIFECYCLE_SOURCE = "dashboard/catalogue.json"


class SetupIdError(ValueError):
"""A `setup_id` that does not follow the canonical grammar."""

def __init__(self, value, where=""):
place = f" in {where}" if where else ""
super().__init__(f"SetupIdError: {value!r}{place} does not match {SETUP_ID_GRAMMAR}")


def parse_setup_id(value, where=""):
"""`setup_id` -> {backend, device, operator, precision, transformer}.

Refuses anything off the grammar with `SetupIdError`, including an explicit
`_na` transformer (the canonical form omits it)."""
parts = value.split("_") if isinstance(value, str) else []
if len(parts) not in (4, 5):
raise SetupIdError(value, where)
backend, device, operator, precision = parts[:4]
transformer = parts[4] if len(parts) == 5 else "na"
if (backend not in SETUP_BACKENDS or device not in SETUP_DEVICES
or operator not in SETUP_OPERATORS or precision not in SETUP_PRECISIONS
or (len(parts) == 5 and transformer not in SETUP_TRANSFORMERS)):
raise SetupIdError(value, where)
return {"backend": backend, "device": device, "operator": operator,
"precision": precision, "transformer": transformer}


def is_local_host(host_class):
return isinstance(host_class, str) and host_class.startswith(LOCAL_HOST_PREFIX)


def pin_order(pin):
"""Sortable form of a release pin (`2026.10.16.2`); None when unparsable."""
if not isinstance(pin, str):
return None
try:
return tuple(int(part) for part in pin.split("."))
except ValueError:
return None


def lifecycle_key(row, where):
"""(dataset_type, variant, instrument, setup_id, host_class, model_variant,
measurement) — the Pulse one-current-per-key identity."""
likelihood = row.get("likelihood")
if not isinstance(likelihood, dict):
raise ValueError(f"Lifecycle row without a likelihood: {where}")
dataset_type = _token(likelihood.get("dataset_type"))
if dataset_type not in DATASET_TYPES:
raise ValueError(f"Unknown dataset_type {dataset_type!r}: {where}")
setup_id = row.get("setup_id")
setup = parse_setup_id(setup_id, where)
declared = row.get("setup")
if isinstance(declared, dict) and any(
declared.get(field, setup[field]) != setup[field] for field in setup):
raise ValueError(f"setup does not match setup_id {setup_id!r}: {where}")
return (dataset_type, _token(likelihood.get("variant")), _token(row.get("instrument")),
setup_id, _token(row.get("host_class")), _token(row.get("model_variant")),
_token(row.get("measurement")))


def read_lifecycle(ws: Path):
"""The published `profiling-summary@3` catalogue, or None (v1/v2/absent).

None keeps every caller on its pre-lifecycle path unchanged; an unreadable
published file is left to `read_catalogue`, which already owns that error.
A v3 document the grid cannot place is refused, never half-read.
"""
source = ws / LIFECYCLE_SOURCE
if not source.is_file():
return None
raw = source.read_bytes()
try:
doc = json.loads(raw)
except (ValueError, UnicodeError):
return None
if not isinstance(doc, dict) or doc.get("schema") != "profiling-summary" or doc.get("version") != 3:
return None
records, planned = doc.get("records"), doc.get("planned_cells", [])
if not isinstance(records, list) or not isinstance(planned, list):
raise ValueError("profiling-summary@3 records and planned_cells must be lists")
rows = []
for index, record in enumerate(records):
where = f"records[{index}]"
if not isinstance(record, dict):
raise ValueError(f"Invalid lifecycle record: {where}")
key = lifecycle_key(record, where)
if record.get("class") not in CLASSES:
raise ValueError(f"Unknown class {record.get('class')!r}: {where}")
if record.get("status") not in STATUSES:
raise ValueError(f"Status {record.get('status')!r} cannot be in records[]: {where}")
rows.append({"id": str(record.get("id", where)), "key": key, "class": record["class"],
"status": record["status"], "release_pin": record.get("release_pin")})
cells = {}
for index, cell in enumerate(planned):
where = f"planned_cells[{index}]"
if not isinstance(cell, dict):
raise ValueError(f"Invalid planned cell: {where}")
key = lifecycle_key(cell, where)
if cell.get("class") not in CLASSES:
raise ValueError(f"Unknown class {cell.get('class')!r}: {where}")
if key in cells:
raise ValueError(f"Duplicate planned cell: {where}")
cells[key] = cell["class"]
# The pin a current record is judged against: the envelope's own when it
# declares one, else the newest pin the catalogue's records carry.
pin, pin_source = doc.get("release_pin"), "envelope"
if pin_order(pin) is None:
pins = [r["release_pin"] for r in rows if pin_order(r["release_pin"]) is not None]
pin, pin_source = (max(pins, key=pin_order), "newest record") if pins else (None, None)
return {
"source": LIFECYCLE_SOURCE,
"sha256": hashlib.sha256(raw).hexdigest(),
"version": 3,
"release_pin": pin,
"release_pin_source": pin_source,
"archive_record_count": doc.get("archive_record_count"),
"records": rows,
"planned": cells,
}
Loading
Loading