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
13 changes: 11 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,17 @@ threads}` and the matching `setup_id`, `host_class`, `model_variant` (e.g.
**Rules.**

- Exactly one `current` record per key (`likelihood`, `instrument`,
`setup_id`, `host_class`, `model_variant`, `measurement`). The producer
chooses which one under the day-zero rule; a second `current` is refused.
`setup_id`, `host_class`, `model_variant`, `measurement`, `regime`). The
producer chooses which one under the day-zero rule; a second `current` is
refused. `regime` joined the key for the producer's declared size variants
(autolens_profiling#468): a `source_pixels_<n>` row is current beside its
`standard` row on otherwise equal fields. Two current rows of the same regime
are still refused. This only relaxes the rule, so every capture valid before
stays valid: no version bump (the same additive convention as the resources
fields below).
- A planned cell may declare a `regime` (non-empty string); it is then part of
that cell's key. A cell without one names the cell on the other key fields
and is covered by a current record of any regime.
- `class: optimal` requires a `decision_id`. `pyauto-pulse check` and ingest
resolve every `decision_id` against this organ's `decisions.yaml`
(the `designation` decisions below); an unresolved id makes the capture
Expand Down
24 changes: 21 additions & 3 deletions pulse/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,25 @@ def setup_id(setup: dict) -> str:
return "_".join(parts)


CURRENT_KEY_FIELDS = (*KEY_FIELDS, "regime")


def lifecycle_key(item: dict) -> str:
"""The one-``current``-per-key identity of a v3 record or planned cell."""
return json.dumps({k: item.get(k) for k in KEY_FIELDS}, sort_keys=True)
"""The one-``current``-per-key identity of a v3 record or planned cell.

``regime`` (the source-size bin) is part of the key when the item declares
one: a record always does, so a ``source_pixels_<n>`` size variant is current
beside its ``standard`` row. A planned cell may omit it and then names the
cell on the other key fields alone (see ``covers``).
"""
fields = CURRENT_KEY_FIELDS if "regime" in item else KEY_FIELDS
return json.dumps({k: item.get(k) for k in fields}, sort_keys=True)


def covers(record: dict, cell: dict) -> bool:
"""Whether ``record`` sits on planned ``cell``: every key field the cell declares."""
fields = CURRENT_KEY_FIELDS if "regime" in cell else KEY_FIELDS
return all(record.get(k) == cell.get(k) for k in fields)


class _Check:
Expand Down Expand Up @@ -630,13 +646,15 @@ def _validate_v3(check, doc):
"records",
f"second current record {item['id']!r} on the key of {prior!r}; the producer "
"declares exactly one current per (likelihood, instrument, setup_id, host_class, "
"model_variant, measurement)",
"model_variant, measurement, regime)",
)
planned = check.objects(doc.get("planned_cells", []), "planned_cells")
seen = set()
for i, cell in enumerate(planned):
where = f"planned_cells[{i}]"
_cell_key_fields(check, cell, where)
if "regime" in cell:
check.text(cell.get("regime"), f"{where}.regime")
key = lifecycle_key(cell)
check.require(key not in seen, where, "duplicate planned cell")
seen.add(key)
Expand Down
6 changes: 2 additions & 4 deletions pulse/setup_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,11 @@ def default_visible(record) -> bool:

def not_measured(doc) -> list[dict]:
"""Optimal planned cells with no current record on their key (producer-declared)."""
current = {
catalogue.lifecycle_key(r) for r in doc.get("records") or [] if r.get("status") == "current"
}
current = [r for r in doc.get("records") or [] if r.get("status") == "current"]
return [
cell
for cell in doc.get("planned_cells") or []
if cell.get("class") == "optimal" and catalogue.lifecycle_key(cell) not in current
if cell.get("class") == "optimal" and not any(catalogue.covers(r, cell) for r in current)
]


Expand Down
31 changes: 31 additions & 0 deletions tests/test_catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,37 @@ def test_one_current_per_key_counts_host_class_and_variant_as_identity(v3):
assert any("second current record 'clash'" in e for e in summary.validate(v3))


def test_a_size_variant_is_current_beside_its_standard_row(v3):
# The regime (source-size bin) is part of the one-current key: a current
# source_pixels_784 row validates beside the current standard row.
size = copy.deepcopy(v3["records"][0])
size.update(id="size-784", regime="source_pixels_784")
v3["records"].append(size)
v3["coverage"]["observed"].update(records=7, current=6)
assert summary.classify(v3, V3) == ("ok", [])
clash = copy.deepcopy(size)
clash["id"] = "clash-784"
v3["records"].append(clash)
v3["coverage"]["observed"].update(records=8, current=7)
errors = summary.validate(v3)
assert any("second current record 'clash-784'" in e for e in errors)
assert any(
"(likelihood, instrument, setup_id, host_class, model_variant, measurement, regime)" in e
for e in errors
)


def test_a_planned_cell_without_a_regime_is_covered_by_any_regime():
cell = {"instrument": "hst", "setup_id": "s", "host_class": "hpc_a100"}
cell.update(likelihood={"dataset_type": "imaging", "variant": "x"})
cell.update(model_variant="default", measurement="runtime")
record = dict(cell, regime="n_vis_lt_1e5")
assert catalogue.covers(record, cell)
assert catalogue.covers(record, dict(cell, regime="n_vis_lt_1e5"))
assert not catalogue.covers(record, dict(cell, regime="standard"))
assert catalogue.lifecycle_key(record) != catalogue.lifecycle_key(cell)


def test_local_gpu_rows_may_be_kept_but_never_current(v3):
row = copy.deepcopy(v3["records"][4])
row.update(id="laptop-gpu", host_class="local_gpu", status="superseded")
Expand Down
52 changes: 52 additions & 0 deletions tests/test_setup_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,55 @@ def test_columns_with_differing_visible_values_stay():
page = setup_browser.render(lifecycle_capture())
assert re.search(r'data-id="constant-caption" hidden>', page)
assert not re.search(r'<th data-col="[a-z_]+"[^>]* hidden>', page)


def size_variant_capture():
"""The A100 runtime + breakdown also measured at a declared size (regime source_pixels_784)."""
snapshot = lifecycle_capture()
doc = snapshot.doc
for rid in ("imaging-delaunay-hst-a100-runtime", "imaging-delaunay-hst-a100-breakdown"):
record = next(r for r in doc["records"] if r["id"] == rid)
doc["records"].append(
dict(record, id=rid + "-784", regime="source_pixels_784", run_id="run-784")
)
doc["coverage"]["observed"].update(records=8, current=7)
return snapshot


def test_a_size_variant_row_renders_beside_its_standard_row():
from pulse import summary

snapshot = size_variant_capture()
assert summary.validate(snapshot.doc) == []
# The size variant neither opens nor closes a coverage gap (coverage stays as before).
assert [c["instrument"] for c in setup_browser.not_measured(snapshot.doc)] == ["euclid"]
page = setup_browser.render(snapshot)
for rid in ("imaging-delaunay-hst-a100-runtime", "imaging-delaunay-hst-a100-runtime-784"):
assert _row(page, rid)
assert 'data-value="source_pixels_784"' in _row(page, "imaging-delaunay-hst-a100-runtime-784")
# Only the two sizes of one cell visible: Source size differs, so it is not hidden.
snapshot.doc["records"] = [
r
for r in snapshot.doc["records"]
if r["id"] in ("imaging-delaunay-hst-a100-runtime", "imaging-delaunay-hst-a100-runtime-784")
]
page = setup_browser.render(snapshot)
assert re.search(r'<th data-col="regime"[^>]*>', page)
assert not re.search(r'<th data-col="regime"[^>]* hidden>', page)
assert re.search(r'<th data-col="lens_light"[^>]* hidden>', page)
md = "\n".join(setup_browser.markdown(snapshot))
assert "| Source size |" in md and "source_pixels_784" in md


def test_detail_pages_never_mix_two_source_sizes():
pages = setup_browser.detail_pages(size_variant_capture(), "#x", "PyAutoLens")
standard = _article(pages, "imaging-delaunay-hst-a100-runtime")
size = _article(pages, "imaging-delaunay-hst-a100-runtime-784")
assert "imaging-delaunay-hst-a100-runtime-784" not in standard
assert "record=imaging-delaunay-hst-a100-runtime-old" in standard
assert "record=imaging-delaunay-hst-a100-runtime-old" not in size
assert "Source size source_pixels_784" in size
assert "source_pixels_784" not in standard
for article in (standard, size): # each size shows its own breakdown, once
breakdown = re.search(r'data-axis="breakdown".*?</details>', article, re.S)[0]
assert breakdown.count("data-metric='mapping'") == 1
Loading