f4c2545e8b
Replace the monolithic giant/analysis.py (predict-local + RolloutVsTruth
diagnostics) with a lean giant/analysis/ package that compares one
autoregressive `giant rollout` for a checkpoint against a held-out
miniCaloSim reference file, and generates publication-styled plots in
parallel on HTCondor.
Rollout output and a raw reference file share a world-frame physical
column subset under identical names, so the old ALR/local-frame decode
machinery is gone — everything is world-frame mm/MeV.
- sources.py: canonical LazyFrames, synthetic-termination-row filtering,
the secondary view (rollout generation>0 tracks vs reference sec_*_list).
- reduce.py: streaming primitives — a single hist1d group_by pass, per-event
scalars, edep-weighted depth/transverse profiles, species share, leakage.
- context.py/grouping.py: prep resolves fixed bin edges + energy/pdg/material
group sets once into shared.json, so each compute job is one pass, no range
scan (histogram efficiency).
- catalog.py: declarative PlotSpec registry — marginals x {overall,energy,pdg,
material}, per-event totals, shower profiles, species/leakage, secondaries.
- render.py: the only plotstyle/LaTeX importer; PDFs + gallery metadata.
- condor.py + `giant analyze` CLI (prep/compute-one/list/render/submit):
one job per plot, compute/render split (workers polars-only, no LaTeX).
Styling via ETPlot's plotstyle (added to the analysis extra). New tests cover
the reduce primitives, catalog id uniqueness + compute, condor submit, and a
guarded render smoke test. Delete the two predict-diagnostics notebooks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
93 lines
2.3 KiB
Python
93 lines
2.3 KiB
Python
"""Render smoke test — skipped where plotstyle / LaTeX is unavailable."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
pytest.importorskip("plotstyle")
|
|
|
|
from giant.analysis.reduced import Reduced # noqa: E402
|
|
|
|
|
|
def _try_render(reduced: list[Reduced], out: Path):
|
|
from giant.analysis.render import render_all
|
|
|
|
for r in reduced:
|
|
r.save(out / "reduced" / f"{r.id}.json")
|
|
return render_all(out / "reduced", out / "plots")
|
|
|
|
|
|
def test_render_one_of_each_kind(tmp_path: Path):
|
|
reduced = [
|
|
Reduced(
|
|
"m",
|
|
"marginals",
|
|
"overlay_hist",
|
|
"Overlay",
|
|
"x",
|
|
{
|
|
"edges": [0, 1, 2, 3],
|
|
"rollout": [1, 2, 3],
|
|
"reference": [3, 2, 1],
|
|
"log_y": False,
|
|
},
|
|
),
|
|
Reduced(
|
|
"g",
|
|
"marginals",
|
|
"grouped_hist",
|
|
"Grouped",
|
|
"x",
|
|
{
|
|
"edges": [0, 1, 2],
|
|
"groups": {"a": {"rollout": [1, 2], "reference": [2, 1]}},
|
|
"log_y": False,
|
|
},
|
|
),
|
|
Reduced(
|
|
"p",
|
|
"shower",
|
|
"profile",
|
|
"Profile",
|
|
"depth",
|
|
{
|
|
"edges": [0, 1, 2],
|
|
"rollout_mean": [1, 2],
|
|
"rollout_std": [0.1, 0.2],
|
|
"reference_mean": [1.1, 1.9],
|
|
"reference_std": [0.1, 0.1],
|
|
"ylabel": "e",
|
|
},
|
|
),
|
|
Reduced(
|
|
"b",
|
|
"species",
|
|
"bar",
|
|
"Bar",
|
|
"species",
|
|
{
|
|
"labels": ["e-", "gamma"],
|
|
"rollout": [0.6, 0.4],
|
|
"reference": [0.5, 0.5],
|
|
"ylabel": "frac",
|
|
},
|
|
),
|
|
Reduced(
|
|
"s",
|
|
"species",
|
|
"single_hist",
|
|
"Single",
|
|
"x",
|
|
{"edges": [0, 1, 2], "rollout": [5, 1], "log_y": True},
|
|
),
|
|
]
|
|
try:
|
|
pdfs = _try_render(reduced, tmp_path)
|
|
except RuntimeError as e: # LaTeX missing at render time
|
|
pytest.skip(f"LaTeX rendering unavailable: {e}")
|
|
assert len(pdfs) == len(reduced)
|
|
assert all(p.exists() for p in pdfs)
|
|
assert (tmp_path / "plots" / "metadata.yaml").exists()
|