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>
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
"""Tests for the HTCondor submit description + the compute_one round-trip."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from giant.analysis import (
|
|
Context,
|
|
SubmitConfig,
|
|
build_context,
|
|
catalog_ids,
|
|
compute_one,
|
|
prep,
|
|
write_submit,
|
|
)
|
|
from giant.analysis.reduced import Reduced
|
|
from tests.test_analysis_reduce import _reference_frame, _rollout_frame
|
|
|
|
|
|
def test_prep_and_compute_one_roundtrip(tmp_path: Path):
|
|
r, t = _rollout_frame(), _reference_frame()
|
|
ctx = build_context(
|
|
r, t, n_energy_bins=2, n_marginal_bins=8, top_k_pdg=3, sample_rows=1000
|
|
)
|
|
shared = tmp_path / "shared.json"
|
|
ctx.save(shared)
|
|
assert Context.load(shared).top_pdgs == ctx.top_pdgs
|
|
|
|
out = compute_one("marginal_edep", r, t, shared, tmp_path / "marginal_edep.json")
|
|
reduced = Reduced.load(out)
|
|
assert reduced.id == "marginal_edep"
|
|
assert len(reduced.payload["rollout"]) == len(reduced.payload["edges"]) - 1
|
|
|
|
|
|
def test_prep_writes_shared_json(tmp_path: Path):
|
|
r, t = _rollout_frame(), _reference_frame()
|
|
shared = prep(
|
|
r,
|
|
t,
|
|
tmp_path / "run",
|
|
n_energy_bins=2,
|
|
n_marginal_bins=8,
|
|
top_k_pdg=3,
|
|
sample_rows=1000,
|
|
)
|
|
assert shared.exists()
|
|
ctx = Context.load(shared)
|
|
assert set(ctx.var_ranges) == {"step_length", "edep", "delta_e", "post_E"}
|
|
|
|
|
|
def test_write_submit_description(tmp_path: Path):
|
|
cfg = SubmitConfig(
|
|
rollout=tmp_path / "r.parquet",
|
|
reference=tmp_path / "t.parquet",
|
|
out_dir=tmp_path / "run",
|
|
accounting_group="cms",
|
|
repo_dir=tmp_path,
|
|
)
|
|
sub = write_submit(cfg)
|
|
txt = sub.read_text()
|
|
assert "universe = docker" in txt
|
|
assert "docker_image = mschnepf/slc7-condocker" in txt
|
|
assert "requirements = TARGET.ProvidesETPResources" in txt
|
|
assert "accounting_group = cms" in txt
|
|
assert "queue plotid from" in txt
|
|
# one queue item per catalog id
|
|
ids = (cfg.out_dir / "plotids.txt").read_text().split()
|
|
assert ids == catalog_ids()
|
|
# wrapper is executable and self-contained
|
|
wrapper = cfg.out_dir / "run_compute.sh"
|
|
assert wrapper.exists() and (wrapper.stat().st_mode & 0o111)
|
|
assert "giant analyze compute-one" in wrapper.read_text()
|
|
|
|
|
|
def test_write_submit_remote_flag(tmp_path: Path):
|
|
cfg = SubmitConfig(
|
|
rollout=tmp_path / "r.parquet",
|
|
reference=tmp_path / "t.parquet",
|
|
out_dir=tmp_path / "run",
|
|
accounting_group="cms",
|
|
repo_dir=tmp_path,
|
|
remote=True,
|
|
)
|
|
txt = write_submit(cfg).read_text()
|
|
assert "+RemoteJob = True" in txt
|
|
assert "ProvidesETPResources" not in txt
|