"""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