From 1df03fd307508524626dbe00d0199fb65653ec95 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:50 -0400 Subject: [PATCH 01/23] folds: typing.Union for the SeedLike alias (Python 3.9) `SeedLike = int | str | Iterable[int | str]` is evaluated at import time, so `from __future__ import annotations` does not help and the package failed to import on Python 3.9 (requires-python >= 3.9). The alias is now a typing.Union. tests/test_compat.py checks every source file: no `A | B` between type expressions outside annotations, and the 3.9 grammar parses it. --- src/corenet/data/folds.py | 4 +- tests/test_compat.py | 91 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/test_compat.py diff --git a/src/corenet/data/folds.py b/src/corenet/data/folds.py index 885862a..b691c02 100644 --- a/src/corenet/data/folds.py +++ b/src/corenet/data/folds.py @@ -19,12 +19,14 @@ import hashlib from collections.abc import Iterable +from typing import Union import numpy as np _UINT64_32 = np.uint64(32) -SeedLike = int | str | Iterable[int | str] +# a runtime alias (not an annotation): typing.Union, so that the module imports on Python 3.9 +SeedLike = Union[int, str, Iterable[Union[int, str]]] def _str_to_entropy(text: str) -> list[np.uint64]: diff --git a/tests/test_compat.py b/tests/test_compat.py new file mode 100644 index 0000000..ee510ed --- /dev/null +++ b/tests/test_compat.py @@ -0,0 +1,91 @@ +"""The package imports on every Python of ``requires-python`` (>= 3.9): no ``X | Y`` type union is built at +run time (outside annotations, which ``from __future__ import annotations`` keeps as strings), and every +source file parses with the 3.9 grammar.""" + +from __future__ import annotations + +import ast +import typing +from pathlib import Path + +import pytest + +SRC = Path(__file__).resolve().parent.parent / "src" / "corenet" +SOURCES = sorted(SRC.rglob("*.py")) + + +def _statements(body): + """Statements evaluated at import time: module and class bodies, not function bodies; the value of an + annotated assignment, not its annotation.""" + for stmt in body: + if isinstance(stmt, (ast.FunctionDef, ast.AsyncFunctionDef)): + continue + if isinstance(stmt, ast.ClassDef): + yield from _statements(stmt.body) + elif isinstance(stmt, ast.AnnAssign): + if stmt.value is not None: + yield stmt.value + else: + yield stmt + + +def _type_like(node) -> bool: + """A name, attribute, subscript (``list[int]``), ``None`` or a ``|`` of those: a type expression.""" + if isinstance(node, (ast.Name, ast.Attribute, ast.Subscript)): + return True + if isinstance(node, ast.Constant) and node.value is None: + return True + return ( + isinstance(node, ast.BinOp) + and isinstance(node.op, ast.BitOr) + and _type_like(node.left) + and _type_like(node.right) + ) + + +def runtime_unions(path: Path) -> list[str]: + """``:`` of every ``A | B`` between type expressions evaluated at import time.""" + found = [] + for stmt in _statements(ast.parse(path.read_text()).body): + for node in ast.walk(stmt): + if ( + isinstance(node, ast.BinOp) + and isinstance(node.op, ast.BitOr) + and _type_like(node) + ): + found.append(f"{_label(path)}:{node.lineno}") + return sorted(set(found)) + + +def _label(path: Path) -> str: + return str(path.relative_to(SRC)) if SRC in path.parents else path.name + + +def test_detector_sees_a_runtime_union(tmp_path): + bad = tmp_path / "bad.py" + bad.write_text( + "from __future__ import annotations\nfrom collections.abc import Iterable\n" + "SeedLike = int | str | Iterable[int | str]\nx: int | None = None\n" + "def f(a: int | None) -> str | None:\n y: int | None = None\n return None\n" + ) + assert runtime_unions(bad) == ["bad.py:3"] # the annotations on lines 4-6 are not evaluated + + +@pytest.mark.parametrize("path", SOURCES, ids=[str(p.relative_to(SRC)) for p in SOURCES]) +def test_no_runtime_type_union(path): + assert runtime_unions(path) == [], ( + "type union evaluated at import time (fails on Python 3.9); use typing.Union" + ) + + +@pytest.mark.parametrize("path", SOURCES, ids=[str(p.relative_to(SRC)) for p in SOURCES]) +def test_parses_with_python39_grammar(path): + ast.parse(path.read_text(), filename=str(path), feature_version=(3, 9)) + + +def test_seed_alias_is_a_typing_union(): + from corenet.data.folds import SeedLike, Squares + + assert typing.get_origin(SeedLike) is typing.Union + assert set(typing.get_args(SeedLike)[:2]) == {int, str} + assert Squares("delphes_h5", "fold", 0)._seed == Squares(("delphes_h5", "fold", 0))._seed From adaf9e96743e446f52c46b072edde6317ed5feae Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:50 -0400 Subject: [PATCH 02/23] loader: read selector columns at the file dtype, cast to float32 when stacking Columns were cast to float32 before the selector sort, which ties values that differ beyond 24 bits (16777216 vs 16777217). They are now read at the file dtype (bool -> int8, unsigned -> int64 so that the negation of the sort key is exact) and cast to float32 only in H5Dataset._stack. The example files store float32, so their selection is unchanged (test_lexicographic_order_matches_old_key, test_hh4b_small, test_bbww_small). Test: test_selector_sorts_at_file_precision. --- src/corenet/data/h5.py | 24 ++++++++++++++++++------ tests/test_h5.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/corenet/data/h5.py b/src/corenet/data/h5.py index 56b5d46..30fab90 100644 --- a/src/corenet/data/h5.py +++ b/src/corenet/data/h5.py @@ -20,7 +20,8 @@ A collection's ``features`` are exactly the channels of its tensors. A selector reads the column it needs (its column and ``pt``) from the file on its own, whether or not it is a feature; such a column is used for the selection only (``columns_to_read``). A column listed under ``features`` is always a -network input, ``btag`` included. +network input, ``btag`` included. Columns are read at the file's dtype and sorted at that precision; +they are cast to float32 only when the input tensors are built. ds = H5Dataset("examples/data/bbww_small.h5", load_config("examples/bbww/bbww.yaml")) out = model(ds.inputs) @@ -111,11 +112,22 @@ def resolve_group(f: h5py.File, name: str) -> str: ) +def _sortable(a: np.ndarray) -> np.ndarray: + """A column as read from the file, in a dtype that sorts exactly and can be negated: floats and + signed integers unchanged, bool -> int8, unsigned integers -> int64.""" + if a.dtype.kind == "b": + return a.astype(np.int8) + if a.dtype.kind == "u": + return a.astype(np.int64) + return a + + def _read_collection( f: h5py.File, coll: Collection, columns: list[str] ) -> tuple[dict[str, np.ndarray], np.ndarray]: """(columns, present) of one collection, both shaped (N, slots in the file); ``columns`` are the - features plus the selector columns (``columns_to_read``).""" + features plus the selector columns (``columns_to_read``), at the file's dtype (``_sortable``) so that + the selectors sort at full precision; ``_stack`` casts to float32.""" group = f["INPUTS"][resolve_group(f, coll.name)] missing = [k for k in columns if k not in group] if missing: @@ -123,7 +135,7 @@ def _read_collection( f"collection {coll.name!r} (INPUTS/{group.name.split('/')[-1]}): missing columns {missing} " f"(features {coll.features}, selector columns {[c for c in columns if c not in coll.features]})" ) - feats = {k: np.atleast_2d(group[k][...].astype(np.float32).T).T for k in columns} + feats = {k: np.atleast_2d(_sortable(group[k][...]).T).T for k in columns} n, slots = feats[columns[0]].shape if coll.max > 1 and slots < coll.max: raise ValueError( @@ -273,13 +285,13 @@ def _stack( idx: np.ndarray, valid: np.ndarray, ) -> torch.Tensor: - """(N, len(features) + 1, n): features in configuration order, presence flag last, padding -1. - Columns read only for a selector are not stacked.""" + """(N, len(features) + 1, n): features in configuration order, presence flag last, padding -1; + float32 (the columns are cast here). Columns read only for a selector are not stacked.""" n, slots = idx.shape rows = np.arange(n)[:, None] x = np.full((n, len(coll.features) + 1, slots), -1.0, dtype=np.float32) for i, k in enumerate(coll.features): - x[:, i] = np.where(valid, feats[k][rows, idx], -1.0) + x[:, i] = np.where(valid, feats[k][rows, idx], -1.0).astype(np.float32) x[:, -1] = np.where(valid, 1.0, -1.0) return torch.from_numpy(x) diff --git a/tests/test_h5.py b/tests/test_h5.py index d2c8aec..cdbb35c 100644 --- a/tests/test_h5.py +++ b/tests/test_h5.py @@ -445,3 +445,45 @@ def test_missing_fold_column(tmp_path): del g["EVENT/event"] with pytest.raises(KeyError, match="no EVENT/event dataset"): H5Dataset(dst, spec, n_folds=5) + + +def test_selector_sorts_at_file_precision(tmp_path): + """Selector columns are compared at the file's dtype: an int64 column with 16777216 and 16777217 (equal + once cast to float32) selects the higher one; unsigned and bool columns sort by value too (no wrap-around + on negation). The input tensors stay float32.""" + from synthetic import write_synthetic + + path = write_synthetic(tmp_path / "s.h5", "hh4b", n=300) + with h5py.File(path, "a") as f: + mask = f["INPUTS/Source/MASK"][...] + pt = f["INPUTS/Source/pt"][...] + n, slots = mask.shape + assert mask[:, :2].all() # jets 0 and 1 are present in every event (>= 4 jets) + rank = np.zeros((n, slots), dtype=np.int64) + rank[:, 0], rank[:, 1] = 16777216, 16777217 + f.create_dataset("INPUTS/Source/rank", data=rank) + low = np.full((n, slots), 2**40, dtype=np.int64) + low[:, 0], low[:, 1] = 16777216, 16777217 + f.create_dataset("INPUTS/Source/low", data=low) + urank = np.zeros((n, slots), dtype=np.uint8) + urank[:, 1] = 7 # jet 0 has 0: -0 wraps to 0 and would be preferred by a wrapped negation + f.create_dataset("INPUTS/Source/urank", data=urank) + flag = np.zeros((n, slots), dtype=bool) + flag[:, 1] = True + f.create_dataset("INPUTS/Source/flag", data=flag) + for column, kind in (("rank", "int64"), ("urank", "uint8"), ("flag", "bool")): + cfg = _hh4b_cfg(["pt", "eta", "phi", "mass"]) + cfg["objects"]["b"] = f"jets {column} 4" + x = H5Dataset(path, parse_config(cfg)).inputs + assert x["b"].dtype == torch.float32 and x["b"].shape == (n, 5, 4) + assert np.array_equal(x["b"][:, 0, 0].numpy(), pt[:, 1]), ( + f"{kind} column: jet 1 has the highest value" + ) + if column == "rank": # 16777216 > 0: jet 0 is second + assert np.array_equal(x["b"][:, 0, 1].numpy(), pt[:, 0]) + cfg = _hh4b_cfg(["pt", "eta", "phi", "mass"]) + cfg["objects"]["b"] = "jets low 4 lowest" + x = H5Dataset(path, parse_config(cfg)).inputs + assert np.array_equal(x["b"][:, 0, 0].numpy(), pt[:, 0]) # the lowest: 16777216 is jet 0 + assert np.array_equal(x["b"][:, 0, 1].numpy(), pt[:, 1]) + # the b-jet selection of the example files is unchanged (float32 in the file): test_hh4b_small / test_bbww_small From 050030d693d1ec417a513af0eaafd66cdfd2b913 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:51 -0400 Subject: [PATCH 03/23] loader, validator: fold ids of EVENT/fold must be exactly 0..K-1 n_folds = len(np.unique(folds)) miscounted non-contiguous ids, so `--exclude-folds next` = (k + 1) % n_folds picked the wrong fold. The loader now raises a ValueError naming the ids; corenet-validate reports FAIL (WARN with --n-folds K, which ignores the column). Tests: test_fold_ids_must_be_0_to_k, test_broken_file[EVENT/fold: fold ids ...], test_fold_ids_not_contiguous_with_n_folds. --- docs/Dataset.md | 5 +++-- src/corenet/data/h5.py | 19 +++++++++++++------ src/corenet/validate.py | 18 +++++++++++++++--- tests/test_h5.py | 32 ++++++++++++++++++++++++++++++++ tests/test_validate.py | 20 ++++++++++++++++++++ 5 files changed, 83 insertions(+), 11 deletions(-) diff --git a/docs/Dataset.md b/docs/Dataset.md index 86aa270..498f066 100644 --- a/docs/Dataset.md +++ b/docs/Dataset.md @@ -67,8 +67,9 @@ A collection named `x` is read from `INPUTS/x`, matched case-insensitively, or f of the event description in order (`1` = signal in both examples). * **Weights.** `EVENT/weight` is the event weight (1 when absent). Each class is normalised during training, so only the relative weights within a class matter. Negative weights count as 0. -* **Folds.** The cross-validation fold of an event is `EVENT/fold` when the file has that column. - Without it, pass `--n-folds K` to `corenet-train` (and to `corenet-validate`): the fold is then +* **Folds.** The cross-validation fold of an event is `EVENT/fold` when the file has that column; the + ids of `K` folds must be exactly `0 .. K-1`. Without the column, pass `--n-folds K` to + `corenet-train` (and to `corenet-validate`): the fold is then `squares(event) % K`, a hash of the event number in `EVENT/event` (integers ≥ 0) with the Squares counter-based generator (`corenet.data.folds.fold_of`; `--fold-seed`, default 0, selects the hash key), so any subset of a sample gets the same folds and no random split is ever made. With diff --git a/src/corenet/data/h5.py b/src/corenet/data/h5.py index 30fab90..894a645 100644 --- a/src/corenet/data/h5.py +++ b/src/corenet/data/h5.py @@ -12,9 +12,9 @@ plus ``labels`` (``EVENT/label``, or ``CLASSIFICATIONS/EVENT/signal`` when absent), ``weights`` (``EVENT/weight``), ``folds`` and ``events`` (``EVENT/event``). The cross-validation fold of an event -is ``EVENT/fold`` by default; with ``n_folds`` it is ``fold_of(event, n_folds, fold_seed)`` = -``squares(event) % n_folds`` (``corenet.data.folds``) computed from the event numbers, and the file -needs no ``EVENT/fold`` column. No generator-level +is ``EVENT/fold`` by default, whose ids must be exactly 0..K-1 for K folds; with ``n_folds`` it is +``fold_of(event, n_folds, fold_seed)`` = ``squares(event) % n_folds`` (``corenet.data.folds``) +computed from the event numbers, and the file needs no ``EVENT/fold`` column. No generator-level information is read: the roles are chosen from reconstructed quantities only. A collection's ``features`` are exactly the channels of its tensors. A selector reads the column it @@ -231,8 +231,8 @@ def __init__( def _folds( self, f: h5py.File, n_folds: int | None ) -> tuple[torch.Tensor, int, str]: - """(fold of every event, number of folds, rule): ``EVENT/fold`` (n_folds = the number of distinct - values) or, with ``n_folds``, ``fold_of(EVENT/event, n_folds, self.fold_seed)``.""" + """(fold of every event, number of folds K, rule): with ``n_folds``, ``fold_of(EVENT/event, n_folds, + self.fold_seed)``; else ``EVENT/fold``, whose ids must be exactly 0..K-1.""" if n_folds is not None: rule = fold_rule(n_folds, self.fold_seed) if EVENT_KEY not in f: @@ -251,7 +251,14 @@ def _folds( f"to use fold = squares(event) % K from {EVENT_KEY}" ) folds = f[FOLD_KEY][...].astype(np.int64) - return torch.from_numpy(folds), len(np.unique(folds)), FOLD_RULE_COLUMN + ids = np.unique(folds) + if not np.array_equal(ids, np.arange(len(ids))): + shown = ids[:12].tolist() + (["..."] if len(ids) > 12 else []) + raise ValueError( + f"{self.path.name}: {FOLD_KEY} holds the fold ids {shown}; the ids of K folds must be exactly " + f"0..K-1 (--exclude-folds next = fold (k + 1) % K); renumber the column or pass --n-folds K" + ) + return torch.from_numpy(folds), len(ids), FOLD_RULE_COLUMN # ---------------------------------------------------------------- construction def _role_tensor( diff --git a/src/corenet/validate.py b/src/corenet/validate.py index d5f3a2c..426af9f 100644 --- a/src/corenet/validate.py +++ b/src/corenet/validate.py @@ -10,9 +10,9 @@ 2. Data (with ``--input``): every dataset the loader reads is looked up with the loader's own rules (``corenet.data.h5``: group aliases, used collections, computed event scalars, label keys) and its dtype and shape are checked; the labels must lie in 0..len(outputs), the weights must be finite, - the folds must exist for training (``EVENT/fold``, or ``--n-folds K`` for fold = squares(event) % K - from the event numbers, seed ``--fold-seed``; the report gives the fold source and the events per - fold); the present members + the folds must exist for training (``EVENT/fold`` with ids exactly 0..K-1, or ``--n-folds K`` for + fold = squares(event) % K from the event numbers, seed ``--fold-seed``; the report gives the fold + source and the events per fold); the present members must have finite features. Finally the actual loader (``H5Dataset``) reads the file and the network runs a forward pass on the first events, so a file that passes here also loads in corenet-train. @@ -411,6 +411,18 @@ def length(name, ds): ) elif length(loader.FOLD_KEY, fo): column = fo[...].astype(np.int64) + ids = np.unique(column) + if not np.array_equal(ids, np.arange(len(ids))): + shown = ids[:12].tolist() + (["..."] if len(ids) > 12 else []) + msg = ( + f"{loader.FOLD_KEY}: fold ids {shown} are not 0..K-1 (the ids of K folds must be " + "exactly 0..K-1; --exclude-folds next = fold (k + 1) % K): renumber the column" + ) + if n_folds is None: + report.fail(sec, msg + " or pass --n-folds K") + else: + report.warn(sec, msg + f"; --n-folds {n_folds} ignores the column") + column = None elif n_folds is None: report.fail( sec, diff --git a/tests/test_h5.py b/tests/test_h5.py index cdbb35c..4616145 100644 --- a/tests/test_h5.py +++ b/tests/test_h5.py @@ -3,6 +3,7 @@ from __future__ import annotations +import re from pathlib import Path import h5py @@ -447,6 +448,37 @@ def test_missing_fold_column(tmp_path): H5Dataset(dst, spec, n_folds=5) +def test_fold_ids_must_be_0_to_k(tmp_path): + """EVENT/fold ids must be exactly 0..K-1: with a gap K would be miscounted and `next` would pick the wrong + fold, so the loader refuses the column (--n-folds K still ignores it); contiguous ids give K and + `next` = (k + 1) % K.""" + from synthetic import write_synthetic + + from corenet.train import resolve_exclude_folds + + path = write_synthetic(tmp_path / "f.h5", "hh4b", n=300) + spec = load_config(repo / "examples/hh4b/hh4b.yaml") + with h5py.File(path, "a") as f: + event = f["EVENT/event"][...] + del f["EVENT/fold"] + f.create_dataset("EVENT/fold", data=event % 3) + ds = H5Dataset(path, spec) + assert ds.n_folds == 3 and resolve_exclude_folds(["next"], 2, ds.n_folds) == [0] + assert resolve_exclude_folds(["next"], 0, ds.n_folds) == [1] + for bad in ([0, 1, 3], [1, 2, 3], [0, 2, 4]): + with h5py.File(path, "a") as f: + del f["EVENT/fold"] + f.create_dataset("EVENT/fold", data=np.array(bad, dtype=np.int64)[event % 3]) + with pytest.raises( + ValueError, + match=re.escape( + f"EVENT/fold holds the fold ids {bad}; the ids of K folds must be exactly 0..K-1" + ), + ): + H5Dataset(path, spec) + assert H5Dataset(path, spec, n_folds=3).n_folds == 3 # the column is ignored + + def test_selector_sorts_at_file_precision(tmp_path): """Selector columns are compared at the file's dtype: an int64 column with 16777216 and 16777217 (equal once cast to float32) selects the higher one; unsigned and bool columns sort by value too (no wrap-around diff --git a/tests/test_validate.py b/tests/test_validate.py index cf26007..c4f5529 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -294,6 +294,13 @@ def _replace(f, name, data): lambda f: f.__delitem__("EVENT/fold"), "EVENT/fold not found: corenet-train needs a fold index", ), + ( + lambda f: _replace( + f, "EVENT/fold", np.where(f["EVENT/fold"][...] == 2, 7, f["EVENT/fold"][...]) + ), + "EVENT/fold: fold ids [0, 1, 3, 4, 7] are not 0..K-1 (the ids of K folds must be exactly 0..K-1; " + "--exclude-folds next = fold (k + 1) % K): renumber the column or pass --n-folds K", + ), ( lambda f: _replace(f, "EVENT/weight", np.full(400, np.nan, dtype=np.float32)), "EVENT/weight: 400 non-finite weights", @@ -404,3 +411,16 @@ def test_fold_report(tmp_path): "folds = squares(event) % 3, seed 0 (--n-folds): EVENT/event not found" in _errors(r) ) + + +def test_fold_ids_not_contiguous_with_n_folds(tmp_path): + """A column whose ids are not 0..K-1 is a FAIL by itself and a WARN with --n-folds (the column is ignored).""" + data = write_synthetic(tmp_path / "d.h5", "bbww", n=400) + with h5py.File(data, "a") as f: + _replace(f, "EVENT/fold", f["EVENT/fold"][...] + 1) + r = validate.validate(BBWW, data) + assert "EVENT/fold: fold ids [1, 2, 3, 4, 5] are not 0..K-1" in _errors(r) + r = validate.validate(BBWW, data, n_folds=5) + assert not r.errors + assert "fold ids [1, 2, 3, 4, 5] are not 0..K-1" in "\n".join(r.warnings) + assert "--n-folds 5 ignores the column" in "\n".join(r.warnings) From 31b33bf37e6c169b241b2725368cdea8d3f4543d Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:51 -0400 Subject: [PATCH 04/23] loader: folds are needed only to select a fold A file with neither EVENT/fold nor --n-folds used to fail in H5Dataset, which broke `corenet-evaluate --fold -1` and corenet-export on such files (Dataset.md: the fold is needed for training). The file now loads without folds (has_folds False, every fold -1, n_folds 0, fold_rule "none"); fold_indices, corenet-train and corenet-evaluate with a fold >= 0 stop with a message naming --n-folds K / --fold -1. Tests: test_missing_fold_column, test_file_without_folds (train fails, evaluate --fold -1 and export succeed), test_n_folds_rule. --- docs/Dataset.md | 4 ++- src/corenet/data/h5.py | 42 +++++++++++++++++++-------- src/corenet/evaluate.py | 10 +++++-- src/corenet/train.py | 14 ++++++--- tests/test_h5.py | 17 +++++++++-- tests/test_train.py | 63 ++++++++++++++++++++++++++++++++++++++++- 6 files changed, 127 insertions(+), 23 deletions(-) diff --git a/docs/Dataset.md b/docs/Dataset.md index 498f066..02dfad9 100644 --- a/docs/Dataset.md +++ b/docs/Dataset.md @@ -77,7 +77,9 @@ A collection named `x` is read from `INPUTS/x`, matched case-insensitively, or f `squares(event) % n_folds`), the number of folds and the seed are stored in the checkpoint, so `corenet-evaluate` applies the same rule to any file. `corenet-train --fold k` holds out fold `k` for testing and `--exclude-folds j` uses fold `j` for validation (`--exclude-folds next`: fold - `(k + 1) % n_folds`). + `(k + 1) % n_folds`). Only selecting a fold needs the folds: `corenet-evaluate --fold -1` and + `corenet-export` also work on a file with neither `EVENT/fold` nor `--n-folds` (the events then + carry fold -1 in the prediction file). * **Event identifier.** `EVENT/event` is copied to the prediction files and is the input of the `squares(event) % n_folds` rule. diff --git a/src/corenet/data/h5.py b/src/corenet/data/h5.py index 894a645..29f7f8b 100644 --- a/src/corenet/data/h5.py +++ b/src/corenet/data/h5.py @@ -14,7 +14,9 @@ (``EVENT/weight``), ``folds`` and ``events`` (``EVENT/event``). The cross-validation fold of an event is ``EVENT/fold`` by default, whose ids must be exactly 0..K-1 for K folds; with ``n_folds`` it is ``fold_of(event, n_folds, fold_seed)`` = ``squares(event) % n_folds`` (``corenet.data.folds``) -computed from the event numbers, and the file needs no ``EVENT/fold`` column. No generator-level +computed from the event numbers, and the file needs no ``EVENT/fold`` column. A file with neither +loads without folds (``has_folds`` False, every fold -1): evaluating or exporting on every event works, +selecting a fold (``fold_indices``: training, evaluating one fold) raises. No generator-level information is read: the roles are chosen from reconstructed quantities only. A collection's ``features`` are exactly the channels of its tensors. A selector reads the column it @@ -65,10 +67,12 @@ "CLASSIFICATIONS/EVENT/signal", ) # first one present is used WEIGHT_KEY, FOLD_KEY, EVENT_KEY = "EVENT/weight", "EVENT/fold", "EVENT/event" -FOLD_RULE_EVENT, FOLD_RULE_COLUMN = ( +FOLD_RULE_EVENT, FOLD_RULE_COLUMN, FOLD_RULE_NONE = ( "squares(event) % n_folds", "EVENT/fold", -) # H5Dataset.fold_rule + "none", +) # H5Dataset.fold_rule; "none": the file has no EVENT/fold and no n_folds was given +NO_FOLD = -1 # the fold of every event of a file loaded without folds # ------------------------------------------------------------------ what the loader reads (shared with corenet-validate) @@ -180,7 +184,7 @@ def __init__( fold_seed: int = FOLD_SEED, ): """``n_folds``: use fold = squares(event) % n_folds (``fold_of``, seed ``fold_seed``) instead of the - ``EVENT/fold`` column.""" + ``EVENT/fold`` column. Without both, the file loads without folds (``has_folds`` is False).""" if rest_order not in ("pt", "selector"): raise ValueError( f"rest_order must be 'pt' or 'selector', got {rest_order!r}" @@ -225,14 +229,28 @@ def __init__( else torch.arange(n, dtype=torch.int64) ) self.fold_seed = int(fold_seed) - self.folds, self.n_folds, self.fold_rule = self._folds(f, n_folds) + self.folds, self.n_folds, self.fold_rule = self._folds(f, n_folds, n) self.inputs = inputs + @property + def has_folds(self) -> bool: + """False when the file has no ``EVENT/fold`` and no ``n_folds`` was given: every fold is NO_FOLD.""" + return self.fold_rule != FOLD_RULE_NONE + + def require_folds(self, what: str = "selecting a fold") -> None: + """Raise KeyError with the remedy when the file was loaded without folds.""" + if not self.has_folds: + raise KeyError( + f"{self.path.name}: no {FOLD_KEY} dataset; {what} needs the fold of every event: pass --n-folds K " + f"(H5Dataset(n_folds=K)) to use fold = squares(event) % K from {EVENT_KEY}" + ) + def _folds( - self, f: h5py.File, n_folds: int | None + self, f: h5py.File, n_folds: int | None, n: int ) -> tuple[torch.Tensor, int, str]: """(fold of every event, number of folds K, rule): with ``n_folds``, ``fold_of(EVENT/event, n_folds, - self.fold_seed)``; else ``EVENT/fold``, whose ids must be exactly 0..K-1.""" + self.fold_seed)``; else ``EVENT/fold``, whose ids must be exactly 0..K-1; else (no column) every fold + is NO_FOLD, K = 0 and the rule is FOLD_RULE_NONE.""" if n_folds is not None: rule = fold_rule(n_folds, self.fold_seed) if EVENT_KEY not in f: @@ -246,10 +264,7 @@ def _folds( folds = fold_of(f[EVENT_KEY][...], n_folds, self.fold_seed) return torch.from_numpy(folds), n_folds, FOLD_RULE_EVENT if FOLD_KEY not in f: - raise KeyError( - f"{self.path.name}: no {FOLD_KEY} dataset; pass --n-folds K (H5Dataset(n_folds=K)) " - f"to use fold = squares(event) % K from {EVENT_KEY}" - ) + return torch.full((n,), NO_FOLD, dtype=torch.int64), 0, FOLD_RULE_NONE folds = f[FOLD_KEY][...].astype(np.int64) ids = np.unique(folds) if not np.array_equal(ids, np.arange(len(ids))): @@ -356,7 +371,8 @@ def __getitem__(self, idx): } def fold_indices(self, fold: int) -> tuple[np.ndarray, np.ndarray]: - """(train_idx, val_idx) holding out ``fold``.""" + """(train_idx, val_idx) holding out ``fold``; raises KeyError on a file loaded without folds.""" + self.require_folds(f"holding out fold {fold}") val = (self.folds == fold).numpy() return np.flatnonzero(~val), np.flatnonzero(val) @@ -367,8 +383,10 @@ def fold_indices(self, fold: int) -> tuple[np.ndarray, np.ndarray]: "FOLD_KEY", "FOLD_RULE_COLUMN", "FOLD_RULE_EVENT", + "FOLD_RULE_NONE", "GROUP_ALIASES", "LABEL_KEYS", + "NO_FOLD", "WEIGHT_KEY", "H5Dataset", "columns_to_read", diff --git a/src/corenet/evaluate.py b/src/corenet/evaluate.py index d327fc9..92a5427 100644 --- a/src/corenet/evaluate.py +++ b/src/corenet/evaluate.py @@ -7,7 +7,8 @@ Events: by default the fold held out when the checkpoint was trained (``--fold -1`` = every event of the file), with the checkpoint's fold rule: ``EVENT/fold`` of the file, or fold = squares(event) % n_folds with the checkpoint's seed when the model was trained with ``--n-folds`` (``--n-folds K`` and -``--fold-seed`` override). The output file (layout in +``--fold-seed`` override). A file without ``EVENT/fold`` is evaluated with ``--fold -1`` (or +``--n-folds K``); its events then carry fold -1 in the output. The output file (layout in docs/Dataset.md) holds the class probabilities, the view (candidate) probabilities of every multi-candidate hypothesis, the auxiliary head probabilities, the event labels / weights and, for the main output, the ROC curve; the AUCs are printed and written as JSON next to it (``.json``). @@ -30,7 +31,7 @@ import torch import torch.nn.functional as F -from .data.h5 import H5Dataset +from .data.h5 import FOLD_KEY, H5Dataset from .models.config import NetworkSpec from .models.network import CoReNet @@ -246,6 +247,11 @@ def main(argv=None): args.input, spec, rest_order=rest_order, n_folds=n_folds, fold_seed=fold_seed ) fold = args.fold if args.fold is not None else meta.get("fold", -1) + if fold is not None and fold >= 0 and not ds.has_folds: + raise SystemExit( + f"{args.input}: no {FOLD_KEY} dataset, so fold {fold} cannot be selected: pass --fold -1 to evaluate " + "every event, or --n-folds K to use fold = squares(event) % K from EVENT/event" + ) idx = ( np.arange(len(ds)) if fold is None or fold < 0 diff --git a/src/corenet/train.py b/src/corenet/train.py index 0405754..ad9822b 100644 --- a/src/corenet/train.py +++ b/src/corenet/train.py @@ -22,9 +22,10 @@ binary cross entropy of its head against ``label == class index of o``. The view (candidate selection) scores are not supervised. -Folds: ``EVENT/fold`` of the file, or ``--n-folds K`` for fold = squares(event) % K from the event -numbers (``corenet.data.folds.fold_of``, seed ``--fold-seed``, 0 = the rule of the example files); -``--exclude-folds next`` is the fold (k + 1) % n_folds of held-out fold k. +Folds: ``EVENT/fold`` of the file (ids exactly 0..K-1), or ``--n-folds K`` for fold = squares(event) % K +from the event numbers (``corenet.data.folds.fold_of``, seed ``--fold-seed``, 0 = the rule of the +example files); ``--exclude-folds next`` is the fold (k + 1) % K of held-out fold k. Training needs one +of the two. For each held-out fold k this writes, in ``--output-dir``: model_fold{k}.pkl checkpoint: state dict, configuration, classes and metadata @@ -46,7 +47,7 @@ from .checkpoint import save_checkpoint from .data.folds import FOLD_SEED -from .data.h5 import H5Dataset +from .data.h5 import FOLD_KEY, H5Dataset from .evaluate import Batches, count_parameters, predict, write_predictions from .models.config import ConfigError, NetworkSpec, parse_config, read_config_dict from .models.network import CoReNet @@ -663,6 +664,11 @@ def main(argv=None): n_folds=args.n_folds, fold_seed=args.fold_seed, ) + if not ds.has_folds: + raise SystemExit( + f"{args.input}: no {FOLD_KEY} dataset; training needs the fold of every event: pass --n-folds K " + "to use fold = squares(event) % K from EVENT/event" + ) logging.info( f"{args.input}: {len(ds):,} events, {ds.n_folds} folds ({ds.fold_rule}), device={device}, recipe " + ", ".join(f"{k}={getattr(args, k)}" for k in RECIPE_DEFAULTS) diff --git a/tests/test_h5.py b/tests/test_h5.py index 4616145..40ce24e 100644 --- a/tests/test_h5.py +++ b/tests/test_h5.py @@ -418,8 +418,10 @@ def test_fold_rule(): def test_missing_fold_column(tmp_path): - """Without EVENT/fold the loader asks for --n-folds; with it the folds come from EVENT/event.""" + """Without EVENT/fold (and without n_folds) the file loads without folds: every fold is -1 and selecting a + fold asks for --n-folds; with n_folds the folds come from EVENT/event.""" from corenet.data.folds import fold_of + from corenet.data.h5 import FOLD_RULE_NONE, NO_FOLD src = _need(DATA / "hh4b_small.h5") spec = load_config(repo / "examples/hh4b/hh4b.yaml") @@ -438,9 +440,18 @@ def test_missing_fold_column(tmp_path): ): g.create_dataset(key, data=f[key][:500]) event = f["EVENT/event"][:500] - with pytest.raises(KeyError, match="no EVENT/fold dataset; pass --n-folds"): - H5Dataset(dst, spec) + ds0 = H5Dataset(dst, spec) + assert not ds0.has_folds and ds0.n_folds == 0 and ds0.fold_rule == FOLD_RULE_NONE + assert len(ds0) == 500 and (ds0.folds.numpy() == NO_FOLD).all() + assert ds0[3]["fold"] == NO_FOLD and ds0.inputs["b"].shape == (500, 5, 4) + with pytest.raises( + KeyError, match="no EVENT/fold dataset; holding out fold 0 needs .* pass --n-folds K" + ): + ds0.fold_indices(0) + with pytest.raises(KeyError, match="no EVENT/fold dataset; training needs"): + ds0.require_folds("training") ds = H5Dataset(dst, spec, n_folds=5) + assert ds.has_folds assert ds.n_folds == 5 and (ds.folds.numpy() == fold_of(event, 5)).all() with h5py.File(dst, "a") as g: del g["EVENT/event"] diff --git a/tests/test_train.py b/tests/test_train.py index 8d02438..129430e 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -445,6 +445,65 @@ def test_finetune_lr_and_batch_size() -> None: assert train.finetune_batch(0, 1024, 4) == (4, 1) +def test_file_without_folds() -> None: + """A file with neither EVENT/fold nor --n-folds: training stops with a clear message, corenet-evaluate + needs --fold -1 (every event; the output carries fold -1) and corenet-export works.""" + from corenet import export + from corenet.data.h5 import FOLD_RULE_NONE, NO_FOLD + + with tempfile.TemporaryDirectory(prefix="corenet_nofold_") as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "hh4b_all.h5", "hh4b") + _train(data, tmp / "m", epochs=1) + ckpt = tmp / "m" / "model_fold0.pkl" + nofold = tmp / "nofold.h5" + shutil.copy(data, nofold) + with h5py.File(nofold, "a") as f: + del f["EVENT/fold"] + with pytest.raises( + SystemExit, match="no EVENT/fold dataset; training needs the fold of every event: pass --n-folds K" + ): + _train(nofold, tmp / "nofold_train", epochs=1) + assert not (tmp / "nofold_train").exists() + with pytest.raises( + SystemExit, match="no EVENT/fold dataset, so fold 0 cannot be selected: pass --fold -1" + ): + evaluate.main( + ["--checkpoint", str(ckpt), "--input", str(nofold), "--output", str(tmp / "e0.h5")] + ) + metrics = evaluate.main( + [ + "--checkpoint", + str(ckpt), + "--input", + str(nofold), + "--output", + str(tmp / "eall.h5"), + "--fold", + "-1", + ] + ) + assert metrics["n_events"] == 2000 and 0.0 <= metrics["auc"]["main"] <= 1.0 + with h5py.File(tmp / "eall.h5", "r") as f: + assert f.attrs["fold"] == -1 and f.attrs["n_folds"] == 0 + assert f.attrs["fold_rule"] == FOLD_RULE_NONE + assert (f["EVENT/fold"][...] == NO_FOLD).all() and len(f["EVENT/event"]) == 2000 + meta = export.main( + [ + "--checkpoint", + str(ckpt), + "--input", + str(nofold), + "--output-dir", + str(tmp / "export"), + "--n-events", + "256", + ] + ) + assert set(meta["files"]) == {"torchscript", "onnx"} + assert (tmp / "export" / "model_fold0.pt").exists() + + def test_finetune_recipe_from_config() -> None: """The three fine-tuning keys in the trainer: section, and their validation.""" cfg = yaml.safe_load(HH4B.read_text()) @@ -591,7 +650,9 @@ def test_n_folds_rule() -> None: and meta["fold_rule"] == FOLD_RULE_COLUMN == "EVENT/fold" ) assert meta["exclude_folds"] == [0] - with pytest.raises(KeyError, match="no EVENT/fold dataset"): + with pytest.raises( + SystemExit, match="no EVENT/fold dataset, so fold 4 cannot be selected: pass --fold -1" + ): evaluate.main( [ "--checkpoint", From 46c42029d4c0f7034c31d26694b3f8b5baa6899e Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:52 -0400 Subject: [PATCH 05/23] train: ghost batches of the fine-tuning stage divide the batch size GhostBatchNorm1d splits a batch with view(nGB, bs // nGB, ...), so --finetune-batch-size 300 with the schedule capped at 16 ghost batches failed in the reshape. finetune_batch now takes the largest number <= the schedule cap that divides the batch size with >= MIN_GHOST_BATCH_SIZE events per ghost batch (ghost_batches); powers of two are unchanged, 0 stays 0. Test: test_finetune_batch_size_divisor (300 -> 15 / 30 ghost batches, a training run). --- docs/Options.md | 2 +- src/corenet/train.py | 22 ++++++++++++++++++---- tests/test_train.py | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/docs/Options.md b/docs/Options.md index 87e4423..a722c9d 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -34,7 +34,7 @@ Changing one of these gives a different network: validate the file with `corenet | `freeze_epoch` | `--freeze-epoch` | 15 | start of the fine-tuning stage: from this epoch on only the layers named by `finetune_layers` are trained (a value ≥ `epochs` disables this) | | `finetune_layers` | `--finetune-layers PREFIX [PREFIX ...]` | `head_main.`, `head_reduce.`, `aux_heads.` (the output layers) | parameter-name prefixes that stay trainable from `freeze_epoch` on; `none` (the word, alone; `[]` in the file) freezes nothing | | `finetune_lr` | `--finetune-lr` | unset | learning rate set at `freeze_epoch`; the `lr_milestones` after it multiply this value by `lr_gamma`; unset keeps the schedule | -| `finetune_batch_size` | `--finetune-batch-size` | unset | batch size from `freeze_epoch` on (the ghost batches of the stage are kept, capped so that none has fewer than 8 events); unset keeps the schedule | +| `finetune_batch_size` | `--finetune-batch-size` | unset | batch size from `freeze_epoch` on; the ghost batches of the stage are kept when they divide it, else the largest smaller number that does, so that every ghost batch has at least 8 events; unset keeps the schedule | | `class_norm` | `--class-norm` / `--no-class-norm` | true | give every class the same total weight in training | | `seed` | `--seed` | 42 | random seed; fold `k` uses `seed + k` | | `early_stop_patience` | `--early-stop-patience` | 0 | stop when the validation AUC (on the `--exclude-folds` fold) has not improved for this many epochs, and keep the weights of the best epoch; 0 trains every epoch | diff --git a/src/corenet/train.py b/src/corenet/train.py index ad9822b..2bfa681 100644 --- a/src/corenet/train.py +++ b/src/corenet/train.py @@ -8,7 +8,8 @@ * Adam, learning rate ``lr`` (1e-2), MultiStepLR with ``lr_milestones`` (epochs 15..24) and ``lr_gamma`` (0.25): the learning rate is multiplied by 0.25 after each of those epochs; * ``epochs`` (20) epochs; batch size ``batch_size_init`` (1024) at epoch 0, doubled at epochs - 1, 3, 6 and 10, with (64, 16, 4, 1, 0) ghost batches; + 1, 3, 6 and 10, with (64, 16, 4, 1, 0) ghost batches (a batch is split into equal ghost batches, + so their number must divide the batch size); * the input normalisation of every embedder is frozen from the training set before epoch 0; * at epoch ``freeze_epoch`` (15) the fine-tuning stage starts: every parameter whose name does not start with one of the ``finetune_layers`` prefixes (the output heads) is frozen; ``finetune_lr`` @@ -97,14 +98,27 @@ def batch_schedule(epoch: int, bs_init: int) -> tuple[int, int]: return bs, min(n_gb, max(1, bs // MIN_GHOST_BATCH_SIZE)) # no-op for bs_init >= 512 +def ghost_batches(bs: int, cap: int) -> int: + """The largest number of ghost batches <= ``cap`` that divides the batch size ``bs`` into ghost batches of + at least MIN_GHOST_BATCH_SIZE events (the GBN layers split a batch into equal parts); 1 when no such + divisor exists, 0 when ``cap`` is 0 (running statistics).""" + if cap <= 0: + return 0 + for n in range(min(cap, bs // MIN_GHOST_BATCH_SIZE), 1, -1): + if bs % n == 0: + return n + return 1 + + def finetune_batch(epoch: int, bs_init: int, finetune_batch_size: int | None): - """(batch size, ghost batches) of the fine-tuning stage: ``finetune_batch_size`` when set (ghost batches - capped so that none has fewer than MIN_GHOST_BATCH_SIZE events, 0 stays 0), else the schedule.""" + """(batch size, ghost batches) of the fine-tuning stage: ``finetune_batch_size`` when set, with the + schedule's ghost batches reduced to the largest divisor of the batch size that keeps every ghost batch + at >= MIN_GHOST_BATCH_SIZE events (``ghost_batches``; 0 stays 0), else the schedule.""" bs, n_gb = batch_schedule(epoch, bs_init) if finetune_batch_size is None: return bs, n_gb bs = finetune_batch_size - return bs, min(n_gb, max(1, bs // MIN_GHOST_BATCH_SIZE)) + return bs, ghost_batches(bs, n_gb) def freeze_heads(model: CoReNet, prefixes=HEAD_PREFIXES) -> int: diff --git a/tests/test_train.py b/tests/test_train.py index 129430e..5705b5f 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -445,6 +445,33 @@ def test_finetune_lr_and_batch_size() -> None: assert train.finetune_batch(0, 1024, 4) == (4, 1) +def test_finetune_batch_size_divisor() -> None: + """The ghost batches of the fine-tuning stage divide the batch size (the GBN layers split a batch into + equal ghost batches): 300 events get 15 (epochs 1-2, cap 16) or 30 (epoch 0, cap 64) ghost batches of + >= 8 events, powers of two keep the schedule, and training with --finetune-batch-size 300 runs.""" + assert train.ghost_batches(300, 16) == 15 and train.ghost_batches(300, 64) == 30 + assert train.ghost_batches(300, 4) == 4 and train.ghost_batches(300, 1) == 1 + assert train.ghost_batches(300, 0) == 0 and train.ghost_batches(7, 64) == 1 + assert train.ghost_batches(301, 16) == 7 # 301 = 7 * 43 + assert train.finetune_batch(1, 1024, 300) == (300, 15) + assert train.finetune_batch(0, 1024, 300) == (300, 30) + assert train.finetune_batch(3, 1024, 300) == (300, 4) + assert train.finetune_batch(10, 1024, 300) == (300, 0) + for epoch, cap in ((0, 64), (1, 16), (3, 4), (6, 1), (10, 0)): + for bs in (64, 128, 256, 512, 1024, 2048, 4096): + old = min(cap, max(1, bs // train.MIN_GHOST_BATCH_SIZE)) if cap else 0 + assert train.finetune_batch(epoch, 1024, bs) == (bs, old), (epoch, bs) + assert bs % max(old, 1) == 0 + with tempfile.TemporaryDirectory(prefix="corenet_ft_") as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "hh4b_all.h5", "hh4b") + h = _train(data, tmp / "m", "--finetune-batch-size", "300") + e0, e1 = h["history"] + assert e0["batch_size"] == 128 and e0["ghost_batches"] == 16 + assert e1["batch_size"] == 300 and e1["ghost_batches"] == 15 + assert np.isfinite(e1["train_loss"]) and 0.0 <= e1["val_auc"] <= 1.0 + + def test_file_without_folds() -> None: """A file with neither EVENT/fold nor --n-folds: training stops with a clear message, corenet-evaluate needs --fold -1 (every event; the output carries fold -1) and corenet-export works.""" From fa881d66d7da7b92252546712dac637c801d8896 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:52 -0400 Subject: [PATCH 06/23] train: finetune_layers must match at least one trainable parameter Prefixes matching nothing froze every parameter at the freeze epoch and the next backward failed. check_finetune_layers raises a ConfigError before the first epoch (and in freeze_heads) naming the prefixes and the prefixes that exist; a single unmatched prefix among matching ones stays allowed, as the default head_reduce. / aux_heads. match nothing in the HH -> 4b network. Test: test_finetune_layers_must_match. --- src/corenet/train.py | 26 ++++++++++++++++++++++++-- tests/test_train.py | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/corenet/train.py b/src/corenet/train.py index 2bfa681..2f95275 100644 --- a/src/corenet/train.py +++ b/src/corenet/train.py @@ -121,15 +121,35 @@ def finetune_batch(epoch: int, bs_init: int, finetune_batch_size: int | None): return bs, ghost_batches(bs, n_gb) +def check_finetune_layers(model: CoReNet, prefixes) -> None: + """At least one ``finetune_layers`` prefix must match a trainable parameter name; otherwise the fine-tuning + stage would freeze everything. Raises ConfigError naming the prefixes and the prefixes that exist. A single + prefix that matches nothing is allowed: the default ``head_reduce.`` and ``aux_heads.`` exist only in + networks with several combined pixels or auxiliary heads.""" + names = [n for n, p in model.named_parameters() if p.requires_grad] + if not any(n.startswith(p) for p in prefixes for n in names): + valid = sorted({n.split(".")[0] + "." for n in names}) + raise ConfigError( + f"finetune_layers: {list(prefixes)} match no trainable parameter (the fine-tuning stage would train " + f"nothing); parameter names start with {valid}, e.g. {names[:3]}; '{NO_FINETUNE_LAYERS}' freezes nothing" + ) + + def freeze_heads(model: CoReNet, prefixes=HEAD_PREFIXES) -> int: """Freeze every parameter whose name does not start with one of ``prefixes`` (default: the output heads head_main, head_reduce, aux_heads); parameters that are non-trainable by construction stay so. - Returns the number of trainable parameters.""" + Returns the number of trainable parameters; raises ConfigError when none is left.""" prefixes = tuple(prefixes) + check_finetune_layers(model, prefixes) # names the prefixes that match nothing for name, param in model.named_parameters(): if not name.startswith(prefixes): param.requires_grad = False - return count_trainable(model) + n = count_trainable(model) + if n == 0: + raise ConfigError( + f"finetune_layers {list(prefixes)}: no trainable parameter is left for the fine-tuning stage" + ) + return n def count_trainable(model: torch.nn.Module) -> int: @@ -268,6 +288,8 @@ def train_fold( logging.info( f"{args.config}: classes {spec.classes}, {count_parameters(model):,} parameters" ) + if args.finetune_layers: + check_finetune_layers(model, args.finetune_layers) data = Batches(ds, device) w_dev = weights.to(device) aux, head_weights = aux_targets(spec), dict(spec.training.head_weights or {}) diff --git a/tests/test_train.py b/tests/test_train.py index 5705b5f..c5e1441 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -472,6 +472,33 @@ def test_finetune_batch_size_divisor() -> None: assert np.isfinite(e1["train_loss"]) and 0.0 <= e1["val_auc"] <= 1.0 +def test_finetune_layers_must_match() -> None: + """finetune_layers prefixes that match no parameter at all would freeze everything: an error naming them + and the prefixes that exist, raised before the first epoch. One unmatched prefix among matching ones is + allowed (the default `head_reduce.` / `aux_heads.` match nothing in the HH -> 4b network).""" + with tempfile.TemporaryDirectory(prefix="corenet_ft_") as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "hh4b_all.h5", "hh4b") + with pytest.raises( + ConfigError, + match=r"finetune_layers: \['nosuch\.'\] match no trainable parameter.*'head_main\.'.*'none' freezes nothing", + ): + _train(data, tmp / "bad", "--finetune-layers", "nosuch.") + assert not (tmp / "bad" / "history_fold0.json").exists() + h = _train(data, tmp / "mixed", "--finetune-layers", "head_main.", "nosuch.") + assert h["finetune_trainable_parameters"] == 18 # head_main of the 4b network + model = CoReNet(load_config(HH4B), device="cpu") + train.check_finetune_layers(model, train.HEAD_PREFIXES) + train.check_finetune_layers(model, ["head_main.", "nosuch."]) + with pytest.raises( + ConfigError, match=r"\['nosuch\.', 'typo'\] match no trainable parameter" + ): + train.check_finetune_layers(model, ["nosuch.", "typo"]) + with pytest.raises(ConfigError, match="nosuch"): + train.freeze_heads(model, ["nosuch."]) + assert train.count_trainable(model) > 0 # nothing was frozen by the failed call + + def test_file_without_folds() -> None: """A file with neither EVENT/fold nor --n-folds: training stops with a clear message, corenet-evaluate needs --fold -1 (every event; the output carries fold -1) and corenet-export works.""" From 9e6fa2b8d050423b748b41697fd3db7feca895fa Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:52 -0400 Subject: [PATCH 07/23] train: early stopping needs a validation AUC With --early-stop-patience, an empty validation set (--fold 0 --exclude-folds 0) silently disabled early stopping, and a validation fold with a single class crashed in the log line (best_auc None). corenet-train now stops with a message at startup when the validation set is empty and at the first epoch without a finite validation AUC, naming the class counts of the validation folds. Without early stopping both cases run as before. Test: test_early_stopping_needs_validation. --- docs/Options.md | 2 +- src/corenet/train.py | 23 ++++++++++++++++++++--- tests/test_train.py | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/docs/Options.md b/docs/Options.md index a722c9d..e9fc4c2 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -37,7 +37,7 @@ Changing one of these gives a different network: validate the file with `corenet | `finetune_batch_size` | `--finetune-batch-size` | unset | batch size from `freeze_epoch` on; the ghost batches of the stage are kept when they divide it, else the largest smaller number that does, so that every ghost batch has at least 8 events; unset keeps the schedule | | `class_norm` | `--class-norm` / `--no-class-norm` | true | give every class the same total weight in training | | `seed` | `--seed` | 42 | random seed; fold `k` uses `seed + k` | -| `early_stop_patience` | `--early-stop-patience` | 0 | stop when the validation AUC (on the `--exclude-folds` fold) has not improved for this many epochs, and keep the weights of the best epoch; 0 trains every epoch | +| `early_stop_patience` | `--early-stop-patience` | 0 | stop when the validation AUC (on the `--exclude-folds` fold) has not improved for this many epochs, and keep the weights of the best epoch; 0 trains every epoch. The validation fold must differ from the held-out fold and hold events of class 1 and of another class, otherwise the run stops with an error | | `rest_order` | `--rest-order` | `pt` | order of the jets taken by a `rest` line: `pt`, or `selector` to keep the order of the previous candidate line on the same collection (e.g. `b: jets btag 4`) | Write floating-point numbers with a decimal point (`0.005` or `5.0e-3`): YAML reads `5e-3` as a string, diff --git a/src/corenet/train.py b/src/corenet/train.py index 2f95275..8655829 100644 --- a/src/corenet/train.py +++ b/src/corenet/train.py @@ -26,7 +26,8 @@ Folds: ``EVENT/fold`` of the file (ids exactly 0..K-1), or ``--n-folds K`` for fold = squares(event) % K from the event numbers (``corenet.data.folds.fold_of``, seed ``--fold-seed``, 0 = the rule of the example files); ``--exclude-folds next`` is the fold (k + 1) % K of held-out fold k. Training needs one -of the two. +of the two. ``--early-stop-patience`` needs a validation set with events of class 1 and of another +class; an empty validation set or a missing validation AUC stops the run with an error. For each held-out fold k this writes, in ``--output-dir``: model_fold{k}.pkl checkpoint: state dict, configuration, classes and metadata @@ -283,6 +284,12 @@ def train_fold( logging.info( f"fold {fold}: {len(train_idx):,} training / {len(val_idx):,} validation / {len(test_idx):,} held-out events" ) + if args.early_stop_patience and not len(val_idx): + raise SystemExit( + f"fold {fold}: --early-stop-patience {args.early_stop_patience} needs validation events, but " + f"--exclude-folds {exclude_folds} leaves none (held-out fold {fold}; folds 0..{ds.n_folds - 1}): " + "exclude a fold other than the held-out one" + ) model = CoReNet(spec, device=str(device)).to(device) logging.info( @@ -417,9 +424,19 @@ def metadata(epoch: int) -> dict: else "" ) ) - if args.early_stop_patience and len(val_idx): + if args.early_stop_patience: auc = entry.get("val_auc") - if auc is not None and (best_auc is None or auc > best_auc): + if auc is None or not np.isfinite(auc): + val_label = labels[val_idx] + counts = { + c: int((val_label == i).sum()) for i, c in enumerate(spec.classes) + } + raise SystemExit( + f"fold {fold}: epoch {epoch}: no validation AUC, so --early-stop-patience cannot be applied: " + f"the validation folds {exclude_folds} hold {counts} events (positive-weight events of " + f"class 1 `{spec.classes[1]}` and of another class are needed)" + ) + if best_auc is None or auc > best_auc: best_auc, best_epoch, bad = auc, epoch, 0 best_state = { k: v.detach().clone() for k, v in model.state_dict().items() diff --git a/tests/test_train.py b/tests/test_train.py index c5e1441..ec565cf 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -7,12 +7,15 @@ 4. the checkpoint is self-contained and corenet-evaluate reproduces the training-time predictions, 5. the `trainer:` section of the configuration sets the recipe and the command line overrides it, 6. the fine-tuning stage (finetune_layers / finetune_lr / finetune_batch_size) and its defaults, - 7. the fold rule (--n-folds, --exclude-folds next) and its record in checkpoint and predictions. + 7. the fold rule (--n-folds, --exclude-folds next) and its record in checkpoint and predictions, + 8. the guards: ghost batches divide the fine-tuning batch size, finetune_layers prefixes must match, + early stopping needs a validation AUC, a file without folds trains not but evaluates and exports. """ from __future__ import annotations import json +import shutil import tempfile from pathlib import Path @@ -499,6 +502,36 @@ def test_finetune_layers_must_match() -> None: assert train.count_trainable(model) > 0 # nothing was frozen by the failed call +def test_early_stopping_needs_validation() -> None: + """--early-stop-patience stops with an error when the validation set is empty (--exclude-folds names the + held-out fold) or has no validation AUC (one class in the validation fold); without it both runs proceed.""" + with tempfile.TemporaryDirectory(prefix="corenet_es_") as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "hh4b_all.h5", "hh4b") + with pytest.raises( + SystemExit, + match=r"--early-stop-patience 1 needs validation events, but --exclude-folds \[0\] leaves none", + ): + _train(data, tmp / "empty", "--exclude-folds", "0", "--early-stop-patience", "1", epochs=1) + h = _train(data, tmp / "empty_ok", "--exclude-folds", "0", epochs=1) + assert h["n_val"] == 0 and "val_loss" not in h["history"][0] + one = tmp / "oneclass.h5" + shutil.copy(data, one) + with h5py.File(one, "a") as f: + label, fold = f["EVENT/label"][...], f["EVENT/fold"][...] + label[fold == 1] = 0 + del f["EVENT/label"] + f.create_dataset("EVENT/label", data=label) + with pytest.raises( + SystemExit, + match=r"epoch 0: no validation AUC, so --early-stop-patience cannot be applied: the validation folds \[1\] hold \{'rest': \d+, 'signal': 0\}", + ): + _train(one, tmp / "oneclass", "--early-stop-patience", "1", epochs=1) + h = _train(one, tmp / "oneclass_ok", epochs=1) + assert h["n_val"] > 0 and "val_auc" not in h["history"][0] + assert np.isfinite(h["history"][0]["val_loss"]) + + def test_file_without_folds() -> None: """A file with neither EVENT/fold nor --n-folds: training stops with a clear message, corenet-evaluate needs --fold -1 (every event; the output carries fold -1) and corenet-export works.""" From 887f4d4e6c3dbae323aa384d81d496b8a6c50e3d Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:11:53 -0400 Subject: [PATCH 08/23] network: extra features of the context role reach the context objects Non-kinematic features of a role used only as `context:` (e.g. btag on `other` in hh4b) were reported by _extras but never fed to the network: _Context.embed had 4 input channels and _prepare_context built the objects from kinematics and the flag only. The context objects now carry 4 + E channels, E = the extra features of the context role; an object of another leaf gets an extra it shares from its own tensor and -1 (the padding value) for one it lacks; the pair features stay kinematic. Without extras the network is unchanged: 1,508 / 3,832 parameters, embed input 4, reference parity. Docs: EventInfo.md, README.md. Test: test_context_role_extras_reach_the_network. --- README.md | 2 +- docs/EventInfo.md | 5 ++-- src/corenet/models/network.py | 46 +++++++++++++++++++++++++++++------ tests/test_h5.py | 40 ++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 082ef44..02d2fb4 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ combine: [HH] `jets` is the jet collection: `max: 12` is the number of jet slots read per event, and the input file must have at least that many. The listed `features` are the inputs of the network: these columns of the input -file, and only these, are fed to it. \ +file, and only these, are fed to it, for the `b` jets and for the `other` jets alike. \ `jets btag 4` selects the four jets with the highest `btag` (alternatively `jets pt 4` would select the four leading jets): any column of the jets in the file can be used this way, and `jets mass 2 lowest` would take the two jets with the lowest value instead. The selector reads its column from the file for this selection only; it diff --git a/docs/EventInfo.md b/docs/EventInfo.md index 9487f3b..c7c7ec2 100644 --- a/docs/EventInfo.md +++ b/docs/EventInfo.md @@ -37,7 +37,8 @@ objects: * `jets`: the jet collection, with up to 12 jets per event. The listed features are the inputs of the network: exactly these columns of the input file ([Dataset.md](./Dataset.md)) are fed to it, `pt`, - `eta`, `phi` and `mass` as the kinematics and any other feature as an additional input. + `eta`, `phi` and `mass` as the kinematics and any other feature as an additional input. This holds + for every line taken from the collection, also one used only as `context:` (`other` below). * `b: jets btag 4`: the four jets most likely to be b jets, taken from the jet collection. The `btag` rule reads the `btag` column of the file for this choice only; it need not be a feature. (Listing `btag` under `features` would make it one more input of the network.) @@ -118,7 +119,7 @@ written as: | `W_lep: [lepton, met]` | the leptonic W, formed from the lepton and the missing momentum | `context: ` inside a hypothesis lets its first particles (the Higgs candidates above) also see -the jets of that name, that is, the whole event. +the jets of that name, that is, the whole event, with all the `features` of their collection. Nothing has to be declared about symmetries or combinatorics: products of the same kind are interchangeable (the two b of a Higgs, the two Higgs bosons of HH) and a jet is never used twice in one diff --git a/src/corenet/models/network.py b/src/corenet/models/network.py index 32b17ba..85cb4d7 100644 --- a/src/corenet/models/network.py +++ b/src/corenet/models/network.py @@ -10,7 +10,9 @@ 2. features log(1+pt), eta, dphi-to-parent, log(1+m) for every child slot; the top node drops phi; event scalars whose name contains ``nSelJets`` enter as log(nSelJets - (min_jets - 1)) - 3. embedding GBN embed (+ event scalars for leaves) -> conv, per role / node + 3. embedding GBN embed (+ event scalars for leaves) -> conv, per role / node; the ``context`` + objects are embedded from their kinematics, a flag and the context role's extra + (non-kinematic) features 4. reinforce bottom-up ResNetBlock per composite node (a node reused by several hypotheses is computed once); ``context`` attention after the first level; ``attention`` entries as soon as both nodes exist, with the pair @@ -115,13 +117,15 @@ def setGhostBatches(self, n): class _Context(nn.Module): - """``context: ``: the objects self-attend, then the first-level candidates attend to them.""" + """``context: ``: the objects self-attend, then the first-level candidates attend to them. + ``n_extra``: the number of extra (non-kinematic) features of the context role, which every object + carries after its flag (``CoReNet._prepare_context``); 0 for a role with kinematic features only.""" - def __init__(self, d, heads, phase_symmetric, gate, kv, device): + def __init__(self, d, heads, phase_symmetric, gate, kv, device, n_extra=0): super().__init__() self.embed = _Embed( - 4, d, phase_symmetric, "attention jet", device - ) # log pt, eta, log m, flag + 4 + n_extra, d, phase_symmetric, "attention jet", device + ) # log pt, eta, log m, flag (+ the context role's extra features) self.pair = _Embed( 3, d, phase_symmetric, "M(a,b), dPhi(a,b)", device ) # log(1+M), dphi, pair-type flag @@ -258,6 +262,7 @@ def __init__(self, spec: NetworkSpec, device="cpu"): tr.attention_gate, tr.kv_projection, device, + n_extra=len(self._extras(hs.context)), ) for h, hs in spec.hypotheses.items() if hs.context @@ -615,15 +620,21 @@ def _prepare_hypothesis( hs = self.spec.hypotheses[h] if hs.context: prep["context"] = self._prepare_context( - h, T, hs.context, leaf_kin, leaf_present, kin, kinP + h, T, hs.context, leaf_kin, leaf_extra, leaf_present, kin, kinP ) return prep - def _prepare_context(self, h, T, crole, leaf_kin, leaf_present, kin, kinP): + def _prepare_context( + self, h, T, crole, leaf_kin, leaf_extra, leaf_present, kin, kinP + ): """Objects = this hypothesis' leaves (jet roles, lepton, MET; flag 2) + the context role (its own flag); pair matrices object-object (flag 0) and first-level-candidate-object (flag 1), with masks. ``crole`` is the context role (e.g. ``other``: the jets not assigned to any decay product); ``o`` (n, 5, S) the - S objects the candidates may look at; ``d`` (n, 4, P) the P candidates of the first-level node.""" + S objects the candidates may look at; ``d`` (n, 4, P) the P candidates of the first-level node. + ``feats`` (n, 4 + E, S) is the embedding input of the objects: log pt, eta, log m, flag, then the E extra + (non-kinematic) features of the context role in its feature order. An object of another leaf carries the + same E channels: an extra its own collection also has is taken from its tensor, one it lacks is -1 (the + padding value); the pair features are kinematic only and unchanged.""" first = self.levels[h][0] # every leaf of the hypothesis (jet roles and single-object collections such as lepton / MET), flag 2 leaf_roles = [ @@ -674,6 +685,25 @@ def _prepare_context(self, h, T, crole, leaf_kin, leaf_present, kin, kinP): torch.isinf(of) | torch.isnan(of), torch.full_like(of, -1.0), of ) of = torch.cat((of[:, :2], of[:, 3:]), 1) # log pt, eta, log m, flag + extras = self._extras(crole) + if extras: # (n, E, S): the context role's extra features for every object, -1 where a leaf lacks one + cols = [] + for r in [*leaf_roles, crole]: + have = self._extras(r) + for e in extras: + cols.append( + leaf_extra[r][:, have.index(e) : have.index(e) + 1, :] + if e in have + else torch.full_like(leaf_kin[r][:, 0:1, :], -1.0) + ) + ex = torch.cat( + [ + torch.cat(cols[i * len(extras) : (i + 1) * len(extras)], 1) + for i in range(len(leaf_roles) + 1) + ], + 2, + ) + of = torch.cat([of, ex], 1) return { "feats": of, "mask": mask, diff --git a/tests/test_h5.py b/tests/test_h5.py index 40ce24e..c30ee1c 100644 --- a/tests/test_h5.py +++ b/tests/test_h5.py @@ -530,3 +530,43 @@ def test_selector_sorts_at_file_precision(tmp_path): assert np.array_equal(x["b"][:, 0, 0].numpy(), pt[:, 0]) # the lowest: 16777216 is jet 0 assert np.array_equal(x["b"][:, 0, 1].numpy(), pt[:, 1]) # the b-jet selection of the example files is unchanged (float32 in the file): test_hh4b_small / test_bbww_small + + +def test_context_role_extras_reach_the_network(): + """An extra feature (btag) of the jets also enters the context objects: the context embedder has 4 + 1 + input channels, the output depends on the btag of the `other` jets (which the network sees as context only), + and without the extra the embedder has 4 channels and the parameter count is the reference 1,508.""" + from corenet.models.network import CoReNet + + path = _need(DATA / "hh4b_small.h5") + spec4, spec5 = ( + parse_config(_hh4b_cfg(["pt", "eta", "phi", "mass"])), + parse_config(_hh4b_cfg(["pt", "eta", "phi", "mass", "btag"])), + ) + m4, m5 = CoReNet(spec4, device="cpu"), CoReNet(spec5, device="cpu") + assert m4._extras("other") == [] and m5._extras("other") == ["btag"] + assert m4.context["HH"].embed.embed.features == 4 + assert m5.context["HH"].embed.embed.features == 5 + n4, n5 = (sum(p.numel() for p in m.parameters()) for m in (m4, m5)) + assert n4 == 1508 and n5 > n4, (n4, n5) + x5 = H5Dataset(path, spec5).inputs + batch = {k: v[:512].clone() for k, v in x5.items()} + m5.train() + m5.updateMeanStd(batch) + m5.initMeanStd() + m5.eval() + m5.setGhostBatches(0) + with torch.no_grad(): + ref = m5(batch) + flipped = {k: v.clone() for k, v in batch.items()} + present = flipped["other"][:, -1] > 0 + assert present.any() + flipped["other"][:, 4][present] = 1.0 - flipped["other"][:, 4][present] # btag of the other jets + assert torch.equal(flipped["b"], batch["b"]) and torch.equal(flipped["event"], batch["event"]) + with torch.no_grad(): + out = m5(flipped) + again = m5(batch) + assert torch.isfinite(out["logits"]).all() + assert not torch.equal(out["logits"], ref["logits"]), "the btag of the other jets is not used" + assert not torch.equal(out["views"]["HH"], ref["views"]["HH"]) + assert torch.equal(again["logits"], ref["logits"]) From befdcaa51f9716879dcd2e1c30024f34e666e7bf Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:48:28 -0400 Subject: [PATCH 09/23] train: the regular batch schedule picks a ghost-batch count that divides the batch size Any --batch-size-init works now, not only powers of two; the schedule is unchanged for powers of two. --- src/corenet/train.py | 2 +- tests/test_train.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/corenet/train.py b/src/corenet/train.py index 8655829..8a11732 100644 --- a/src/corenet/train.py +++ b/src/corenet/train.py @@ -96,7 +96,7 @@ def batch_schedule(epoch: int, bs_init: int) -> tuple[int, int]: ) bs = bs_init << stage n_gb = (64, 16, 4, 1, 0)[stage] - return bs, min(n_gb, max(1, bs // MIN_GHOST_BATCH_SIZE)) # no-op for bs_init >= 512 + return bs, ghost_batches(bs, n_gb) # equals the stage's count for any power-of-two batch size >= 512 def ghost_batches(bs: int, cap: int) -> int: diff --git a/tests/test_train.py b/tests/test_train.py index ec565cf..db5ce91 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -179,6 +179,27 @@ def check_freeze(config: Path, expected_params: int) -> None: assert 0 < n_trainable < expected_params +def test_batch_schedule_divides_any_batch_size() -> None: + """The ghost-batch count of the regular schedule divides the batch size for any --batch-size-init.""" + assert [train.batch_schedule(e, 300) for e in (0, 1, 3, 6, 10)] == [ + (300, 30), + (600, 15), + (1200, 4), + (2400, 1), + (4800, 0), + ] + for bs_init in (64, 100, 300, 1000, 1500): + for e in range(12): + bs, n_gb = train.batch_schedule(e, bs_init) + assert n_gb == 0 or (bs % n_gb == 0 and bs // n_gb >= train.MIN_GHOST_BATCH_SIZE), (bs_init, e, bs, n_gb) + for k in range(6, 13): # powers of two: unchanged from the original schedule + bs_init = 1 << k + for e in range(12): + bs, n_gb = train.batch_schedule(e, bs_init) + stage = 0 if e == 0 else 1 if e < 3 else 2 if e < 6 else 3 if e < 10 else 4 + assert n_gb == min((64, 16, 4, 1, 0)[stage], max(1, bs // train.MIN_GHOST_BATCH_SIZE)) + + def test_batch_schedule() -> None: assert [train.batch_schedule(e, 1024) for e in (0, 1, 3, 6, 10)] == [ (1024, 64), From 4ec1aa8db2240bee783cf21a4df9bfd46958d9aa Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:52:27 -0400 Subject: [PATCH 10/23] docs: Zenodo DOI of the training samples (10.5281/zenodo.23567532) --- README.md | 2 +- docs/BBWW.md | 2 +- docs/HH4b.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 02d2fb4..8c6a68f 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ need not be a feature, and a feature named `btag` would be one more network inpu file holds all jets of the event, and the b jets are chosen when it is loaded. For more details on specifying the event decay, check [docs/EventInfo.md](docs/EventInfo.md), and for the input file itself, check [docs/Dataset.md](docs/Dataset.md). The full-statistics files (454,261 HH → bb̄bb̄ events, 292,285 HH → bb̄WW events) are distributed -separately ([DOI / URL to be added]); download them into `examples/data/` as `hh4b_all.h5` and +separately on Zenodo ([doi:10.5281/zenodo.23567532](https://doi.org/10.5281/zenodo.23567532)); download them into `examples/data/` as `hh4b_all.h5` and `bbww_all.h5`. ## Usage diff --git a/docs/BBWW.md b/docs/BBWW.md index b65b4e7..b10b190 100644 --- a/docs/BBWW.md +++ b/docs/BBWW.md @@ -11,7 +11,7 @@ with its own score. `examples/data/bbww_small.h5` (20,000 events: 1,198 HH, 18,802 tt̄; 10.2 MB) is a random subsample of `examples/data/bbww_all.h5` (292,285 events: 17,511 HH, 274,774 tt̄; 149 MB), which is distributed -separately ([DOI / URL to be added]); download it into `examples/data/`. The layout +separately on Zenodo ([doi:10.5281/zenodo.23567532](https://doi.org/10.5281/zenodo.23567532)); download it into `examples/data/`. The layout ([Dataset.md](./Dataset.md)): | path | shape | meaning | diff --git a/docs/HH4b.md b/docs/HH4b.md index c9b233e..0ae191f 100644 --- a/docs/HH4b.md +++ b/docs/HH4b.md @@ -9,7 +9,7 @@ and export. Every command is run from the repository root in the pixi environmen The repository ships `examples/data/hh4b_small.h5` (20,000 events, 8.1 MB), a random subsample of the full file `examples/data/hh4b_all.h5` (454,261 events: 417,978 multijet, 36,283 HH; 184 MB). The full -file is distributed separately ([Zenodo DOI to be added]); download it into `examples/data/`. Both +file is distributed separately on Zenodo ([doi:10.5281/zenodo.23567532](https://doi.org/10.5281/zenodo.23567532)); download it into `examples/data/`. Both files have the same layout ([Dataset.md](./Dataset.md)): | path | shape | dtype | meaning | From 349425365c36737210a1789a2a04439ffb77f60b Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:12:42 -0400 Subject: [PATCH 11/23] H5Dataset: record the file slot of every role slot (selected) corenet-report compares the candidate assignments with TARGETS in file-slot space. --- src/corenet/data/h5.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/corenet/data/h5.py b/src/corenet/data/h5.py index 29f7f8b..9c38dfe 100644 --- a/src/corenet/data/h5.py +++ b/src/corenet/data/h5.py @@ -11,7 +11,9 @@ inputs["event"] (N, len(spec.event)) event scalars in the configured order plus ``labels`` (``EVENT/label``, or ``CLASSIFICATIONS/EVENT/signal`` when absent), ``weights`` -(``EVENT/weight``), ``folds`` and ``events`` (``EVENT/event``). The cross-validation fold of an event +(``EVENT/weight``), ``folds`` and ``events`` (``EVENT/event``), and ``selected`` (role -> (N, n) int64: +the slot of the file each role slot was taken from, -1 for a padded slot; ``corenet-report`` uses it to +compare the candidates with ``TARGETS``). The cross-validation fold of an event is ``EVENT/fold`` by default, whose ids must be exactly 0..K-1 for K folds; with ``n_folds`` it is ``fold_of(event, n_folds, fold_seed)`` = ``squares(event) % n_folds`` (``corenet.data.folds``) computed from the event numbers, and the file needs no ``EVENT/fold`` column. A file with neither @@ -196,6 +198,9 @@ def __init__( self._last_keys: dict[ str, tuple[np.ndarray, ...] ] = {} # per collection: sort keys of the last explicit selector + self.selected: dict[ + str, np.ndarray + ] = {} # per role: (N, n) file slot of every role slot, -1 when padded inputs: dict[str, torch.Tensor] = {} with h5py.File(path, "r") as f: @@ -298,6 +303,7 @@ def _role_tensor( rows = np.arange(len(present))[:, None] for j in range(role.n): # mark the chosen members as consumed taken[rows[:, 0], idx[:, j]] |= valid[:, j] + self.selected[role.name] = np.where(valid, idx, -1).astype(np.int64) return self._stack(coll, feats, idx, valid) @staticmethod From ca6127c4a7758c110c5598a4daf51cb948d8a953 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:12:42 -0400 Subject: [PATCH 12/23] Add corenet-report: one self-contained HTML results page per run Run summary, training curves, ROC/AUC/scores (test, validation and training folds when corenet-evaluate --fold -1 output is present), confusion matrix and auxiliary heads, view probabilities and pairing accuracy against TARGETS, the inputs as the network embeds them, the raw inputs, the event weights, weight profiles, and the list of what could not be produced. matplotlib becomes a dependency (pixi: matplotlib-base). --- pixi.toml | 1 + pyproject.toml | 2 + src/corenet/report.py | 1298 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1301 insertions(+) create mode 100644 src/corenet/report.py diff --git a/pixi.toml b/pixi.toml index adcf7e5..d3429e2 100644 --- a/pixi.toml +++ b/pixi.toml @@ -17,6 +17,7 @@ numpy = "*" h5py = "*" pyyaml = "*" scikit-learn = "*" +matplotlib-base = "*" pytest = "*" onnx = "*" onnxruntime = "*" diff --git a/pyproject.toml b/pyproject.toml index 9bfa8b8..0bb615a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ dependencies = [ "h5py>=3.0", "pyyaml>=5.4", "scikit-learn>=1.0", + "matplotlib>=3.5", ] keywords = [ "particle-physics", @@ -49,6 +50,7 @@ corenet-train = "corenet.train:main" corenet-evaluate = "corenet.evaluate:cli" corenet-export = "corenet.export:cli" corenet-validate = "corenet.validate:cli" +corenet-report = "corenet.report:cli" [tool.setuptools.packages.find] where = ["src"] diff --git a/src/corenet/report.py b/src/corenet/report.py new file mode 100644 index 0000000..ff35c6b --- /dev/null +++ b/src/corenet/report.py @@ -0,0 +1,1298 @@ +""" +corenet-report: one self-contained HTML page with the results and the input checks of a run directory. + + corenet-report --run-dir runs/hh4b --input examples/data/hh4b_all.h5 --output runs/hh4b/report.html + +Per fold k the run directory is read for ``history_fold{k}.json``, ``model_fold{k}.pkl``, +``predictions_fold{k}.h5`` (the held-out fold) and, when present, ``eval_fold{k}.h5`` written by +``corenet-evaluate`` (with ``--fold -1`` it holds every event of the file, which gives the training and +validation folds their own curves). The input file provides the events, labels, weights, folds and, when +present, the generator-level ``TARGETS``. + +Sections: run summary, training curves, classification (ROC, AUC, scores, confusion matrix, auxiliary +heads), hypotheses and pairing (view probabilities, pairing accuracy against ``TARGETS``), the inputs +as the network embeds them, the raw inputs, the event weights, further checks, and the list of what +could not be produced for the run. Every figure is embedded as PNG; the page needs no other file. +""" + +# ruff: noqa: RUF001 +from __future__ import annotations + +import argparse +import base64 +import datetime +import html +import io +import json +import logging +import re +import subprocess +import sys +import traceback +from dataclasses import dataclass, field +from pathlib import Path + +import h5py +import matplotlib +import numpy as np +import torch +import yaml + +matplotlib.use("Agg") +import matplotlib.pyplot as plt # noqa: E402 + +from . import __version__ # noqa: E402 +from .checkpoint import fold_rule_of, load_checkpoint # noqa: E402 +from .data.h5 import ( # noqa: E402 + FOLD_RULE_EVENT, + H5Dataset, + event_source, + resolve_group, +) +from .models.config import NetworkSpec, parse_config, read_config_dict # noqa: E402 +from .models.network import CoReNet # noqa: E402 + +SECTIONS = [ + ("summary", "Run summary"), + ("training", "Training curves"), + ("classification", "Classification"), + ("hypotheses", "Hypotheses and pairing"), + ("inputs", "Inputs as the network sees them"), + ("raw", "Raw inputs"), + ("weights", "Weights"), + ("other", "Other checks"), + ("gaps", "Not produced"), +] +SPLITS = ("test", "validation", "train") +SPLIT_STYLE = {"test": "-", "train": "--", "validation": "-."} +ROC_GRID = np.unique(np.concatenate([np.logspace(-4, 0, 300), np.linspace(0, 1, 300)])) +VIEW_THRESHOLDS = (0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95) +NBINS = 40 + +plt.rcParams.update( + { + "font.size": 8, + "axes.labelsize": 9, + "axes.titlesize": 9, + "legend.fontsize": 7, + "figure.dpi": 100, + "axes.spines.top": False, + "axes.spines.right": False, + } +) + + +# ----------------------------------------------------------------------------- small helpers +def esc(x) -> str: + return html.escape(str(x)) + + +def fmt(x, nd: int = 4) -> str: + """A number for a table cell; '-' for None / NaN.""" + if x is None: + return "-" + if isinstance(x, (bool, np.bool_)): + return str(bool(x)) + if isinstance(x, (int, np.integer)): + return f"{int(x):,}" + try: + xf = float(x) + except (TypeError, ValueError): + return esc(x) + if not np.isfinite(xf): + return "-" + return f"{xf:.{nd}f}" + + +def mean_sd(values) -> str: + """'mean ± sd' over the finite entries (sd with ddof=1; '-' for fewer than two).""" + v = np.array([float(x) for x in values if x is not None], dtype=float) + v = v[np.isfinite(v)] + if len(v) == 0: + return "-" + if len(v) == 1: + return f"{v[0]:.4f}" + return f"{v.mean():.4f} ± {v.std(ddof=1):.4f}" + + +def table(header: list[str], rows: list[list], caption: str = "") -> str: + head = "".join(f"{esc(h)}" for h in header) + body = "".join( + "" + "".join(f"{c if isinstance(c, str) else fmt(c)}" for c in r) + "" + for r in rows + ) + cap = f"{esc(caption)}" if caption else "" + return f"{cap}{head}{body}
" + + +def figure(fig, caption: str = "", dpi: int = 100) -> str: + """The figure as an inline PNG (the figure is closed).""" + buf = io.BytesIO() + try: + fig.tight_layout() + except Exception: # a figure that cannot be laid out is still saved + pass + fig.savefig(buf, format="png", dpi=dpi) + plt.close(fig) + data = base64.b64encode(buf.getvalue()).decode("ascii") + return ( + f'
{esc(caption)}' + f"
{esc(caption)}
" + ) + + +def note(text: str) -> str: + return f'

{esc(text)}

' + + +def class_color(i: int) -> str: + return "0.45" if i == 0 else f"C{(i - 1) % 10}" + + +def shared_bins(arrays, n: int = NBINS) -> np.ndarray: + """Bin edges over the 0.1-99.9 percentiles of every array; unit bins for integer-valued data.""" + vals = [np.asarray(a, dtype=float) for a in arrays if a is not None and len(a)] + vals = [v[np.isfinite(v)] for v in vals] + vals = [v for v in vals if len(v)] + if not vals: + return np.linspace(0, 1, n + 1) + allv = np.concatenate(vals) + lo, hi = np.percentile(allv, [0.1, 99.9]) + if np.all(np.mod(allv, 1) == 0) and hi - lo <= 60: + return np.arange(np.floor(lo) - 0.5, np.ceil(hi) + 1.5, 1.0) + if lo == hi: + lo, hi = lo - 1, hi + 1 + return np.linspace(lo, hi, n + 1) + + +def hist_panel(ax, series, bins, xlabel: str, logy: bool = False) -> None: + """``series``: (label, values, weights, line style dict); weighted densities as step histograms.""" + for lab, v, w, st in series: + v, w = np.asarray(v, dtype=float), np.asarray(w, dtype=float) + ok = np.isfinite(v) & np.isfinite(w) + if not ok.any() or w[ok].sum() <= 0: + continue + ax.hist( + v[ok], bins=bins, weights=w[ok], density=True, histtype="step", label=lab, **st + ) + ax.set_xlabel(xlabel) + ax.set_ylabel("density") + if logy: + ax.set_yscale("log") + + +def grid_figure(n_panels: int, per_row: int = 4, w: float = 2.6, h: float = 2.1): + rows = max(1, int(np.ceil(n_panels / per_row))) + cols = min(per_row, max(1, n_panels)) + fig, axes = plt.subplots(rows, cols, figsize=(w * cols, h * rows), squeeze=False) + flat = axes.ravel() + for ax in flat[n_panels:]: + ax.axis("off") + return fig, flat + + +def mean_curve(curves, grid=ROC_GRID): + """(mean, sd) of the TPR of several (fpr, tpr) curves on ``grid`` (sd None for one curve).""" + tprs = np.array([np.interp(grid, f, t) for f, t in curves]) + return tprs.mean(0), (tprs.std(0, ddof=1) if len(tprs) > 1 else None) + + +def roc_points(y: np.ndarray, s: np.ndarray, w: np.ndarray): + from sklearn.metrics import roc_curve + + f, t, _ = roc_curve(y, s, sample_weight=w) + return f, t + + +def auc_of(y: np.ndarray, s: np.ndarray, w: np.ndarray): + from sklearn.metrics import roc_auc_score + + if y.all() or not y.any() or w.sum() <= 0: + return None + return float(roc_auc_score(y, s, sample_weight=w)) + + +def norm_name(s: str) -> str: + return re.sub(r"[^a-z0-9]", "", s.lower()) + + +# ----------------------------------------------------------------------------- run files +@dataclass +class Split: + index: np.ndarray # rows of the input file + label: np.ndarray + weight: np.ndarray + probs: np.ndarray + views: dict[str, np.ndarray] + heads: dict[str, np.ndarray] + source: str + + +@dataclass +class FoldData: + fold: int + history: dict | None = None + checkpoint: Path | None = None + checkpoint_meta: dict = field(default_factory=dict) + splits: dict[str, Split] = field(default_factory=dict) + n_parameters: int | None = None + + @property + def exclude_folds(self) -> list[int] | None: + for src in (self.history, self.checkpoint_meta): + if src and src.get("exclude_folds") is not None: + return [int(e) for e in src["exclude_folds"]] + return None + + @property + def best_epoch(self) -> int | None: + if not self.history: + return None + if self.history.get("best_epoch") is not None: + return int(self.history["best_epoch"]) + aucs = [(e.get("val_auc"), e["epoch"]) for e in self.history.get("history", [])] + aucs = [(a, ep) for a, ep in aucs if a is not None and np.isfinite(a)] + return max(aucs)[1] if aucs else None + + +def read_prediction_file(path: Path): + """(fold attribute, Split without a source) of a prediction file.""" + with h5py.File(path, "r") as f: + views = {h: f["views"][h][...] for h in f["views"]} if "views" in f else {} + heads = {k: f["heads"][k][...] for k in f["heads"]} if "heads" in f else {} + split = Split( + f["EVENT/index"][...].astype(np.int64), + f["EVENT/label"][...].astype(np.int64), + f["EVENT/weight"][...].astype(np.float64), + f["class_probabilities"][...].astype(np.float64), + views, + heads, + path.name, + ) + fold = int(f.attrs.get("fold", -1)) + n_par = f.attrs.get("n_parameters") + return fold, split, (int(n_par) if n_par is not None else None) + + +def sub_split(s: Split, sel: np.ndarray, source: str) -> Split: + return Split( + s.index[sel], + s.label[sel], + s.weight[sel], + s.probs[sel], + {k: v[sel] for k, v in s.views.items()}, + {k: v[sel] for k, v in s.heads.items()}, + source, + ) + + +def discover_folds(run_dir: Path, wanted: list[int] | None) -> list[int]: + folds = set() + for pattern in ("history_fold*.json", "model_fold*.pkl", "predictions_fold*.h5", "eval_fold*.h5"): + for p in run_dir.glob(pattern): + m = re.fullmatch(r"(?:history|model|predictions|eval)_fold(\d+)\.(?:json|pkl|h5)", p.name) + if m: + folds.add(int(m.group(1))) + if wanted is not None: + return sorted(wanted) + return sorted(folds) + + +# ----------------------------------------------------------------------------- the report +class Report: + def __init__(self, args): + self.args = args + self.run_dir = Path(args.run_dir) + self.input = Path(args.input) + self.gaps: list[str] = [] + self.generated = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + self.folds: list[FoldData] = [] + self.config: dict | None = None + self.config_source = "" + self.spec: NetworkSpec | None = None + self.model: CoReNet | None = None + self.ds: H5Dataset | None = None + self.rng = np.random.default_rng(0) + + # ---------------------------------------------------------------- loading + def load(self) -> None: + a = self.args + if not self.run_dir.is_dir(): + raise SystemExit(f"{self.run_dir}: not a directory") + fold_ids = discover_folds(self.run_dir, a.folds) + if not fold_ids: + raise SystemExit(f"{self.run_dir}: no history_fold*.json, model_fold*.pkl or predictions_fold*.h5") + for k in fold_ids: + fd = FoldData(k) + hp = self.run_dir / f"history_fold{k}.json" + if hp.is_file(): + fd.history = json.loads(hp.read_text()) + cp = self.run_dir / f"model_fold{k}.pkl" + if cp.is_file(): + fd.checkpoint = cp + self.folds.append(fd) + + # configuration and network: --config, else the first checkpoint, else the history's config path + first_ckpt = next((fd for fd in self.folds if fd.checkpoint), None) + if first_ckpt is not None: + self.model, self.spec, ckpt = load_checkpoint(first_ckpt.checkpoint, a.config, "cpu") + self.config = read_config_dict(a.config) if a.config else ckpt["config"] + self.config_source = a.config or f"{first_ckpt.checkpoint.name} (stored configuration)" + else: + cfg_path = a.config + if cfg_path is None: + for fd in self.folds: + if fd.history and fd.history.get("config") and Path(fd.history["config"]).is_file(): + cfg_path = fd.history["config"] + break + if cfg_path is None: + raise SystemExit( + f"{self.run_dir}: no checkpoint and no readable configuration; pass --config" + ) + self.config = read_config_dict(cfg_path) + self.spec = parse_config(self.config) + self.model = CoReNet(self.spec, device="cpu") + self.model.eval() + self.config_source = str(cfg_path) + self.gaps.append("no checkpoint in the run directory: the network was built from the configuration without trained weights (parameter count only)") + for fd in self.folds: + if fd.checkpoint: + meta = torch.load(fd.checkpoint, map_location="cpu", weights_only=False).get("metadata", {}) + fd.checkpoint_meta = dict(meta) + + # the dataset, with the fold rule of the run + meta = first_ckpt.checkpoint_meta if first_ckpt else {} + hist = next((fd.history for fd in self.folds if fd.history), None) or {} + n_folds, fold_seed = fold_rule_of(meta) if meta else (None, 0) + if not meta and hist.get("fold_rule") == FOLD_RULE_EVENT: + n_folds, fold_seed = hist.get("n_folds"), int(hist.get("fold_seed", 0)) + if a.n_folds is not None: + n_folds = a.n_folds + if a.fold_seed is not None: + fold_seed = a.fold_seed + rest_order = a.rest_order or meta.get("rest_order") or (hist.get("recipe") or {}).get("rest_order", "pt") + self.ds = H5Dataset(self.input, self.spec, rest_order=rest_order, n_folds=n_folds, fold_seed=fold_seed) + self.labels = self.ds.labels.numpy() + self.weights = self.ds.weights.numpy().astype(np.float64) + self.fold_of = self.ds.folds.numpy() + logging.info(f"{self.input}: {len(self.ds):,} events, folds {self.ds.fold_rule}, classes {self.spec.classes}") + + # predictions: predictions_fold{k}.h5 (held-out fold) and eval_fold{k}.h5 (any fold, or every event) + for fd in self.folds: + k = fd.fold + for name in (f"predictions_fold{k}.h5", f"eval_fold{k}.h5"): + p = self.run_dir / name + if not p.is_file(): + continue + fold_attr, split, n_par = read_prediction_file(p) + if n_par is not None and fd.n_parameters is None: + fd.n_parameters = n_par + if split.index.max(initial=-1) >= len(self.ds): + self.gaps.append(f"{name}: event indices exceed the input file ({len(self.ds):,} events); the file does not belong to this input") + continue + if fold_attr == k: + fd.splits.setdefault("test", sub_split(split, np.ones(len(split.index), bool), name)) + continue + if fold_attr >= 0: + self.gaps.append(f"{name}: evaluated fold {fold_attr}, not the held-out fold {k} nor every event; ignored") + continue + folds_of_rows = self.fold_of[split.index] + test = folds_of_rows == k + val = np.isin(folds_of_rows, fd.exclude_folds or []) + train = ~test & ~val + fd.splits.setdefault("test", sub_split(split, test, name)) + if fd.exclude_folds: + if val.any(): + fd.splits["validation"] = sub_split(split, val, name) + else: + self.gaps.append(f"fold {k}: the validation folds are unknown (no history / checkpoint metadata); every event outside fold {k} in {name} counts as training") + if train.any(): + fd.splits["train"] = sub_split(split, train, name) + if "test" not in fd.splits: + self.gaps.append(f"fold {k}: no predictions_fold{k}.h5 or eval_fold{k}.h5: no ROC, scores or view probabilities for this fold") + if "train" not in fd.splits: + self.gaps.append(f"fold {k}: no predictions on the training folds (run corenet-evaluate with --fold -1 and keep eval_fold{k}.h5 in the run directory): no overtraining check for this fold") + if fd.history is None: + self.gaps.append(f"fold {k}: no history_fold{k}.json: no training curves for this fold") + if fd.n_parameters is None and self.model is not None: + fd.n_parameters = int(sum(p.numel() for p in self.model.parameters())) + + # ---------------------------------------------------------------- shared data + @property + def classes(self) -> list[str]: + return self.spec.classes + + def class_series(self, values, labels, weights, style=None): + """(class name, values, clipped weights, style) per class present in ``labels``.""" + out = [] + for i, c in enumerate(self.classes): + sel = labels == i + if not sel.any(): + continue + st = {"color": class_color(i), "lw": 1.3} + st.update(style or {}) + out.append((c, values[sel], np.clip(weights[sel], 0, None), st)) + return out + + def splits_of(self, name: str): + return [(fd, fd.splits[name]) for fd in self.folds if name in fd.splits] + + def selected_subset(self, n_max: int) -> np.ndarray: + n = len(self.ds) + if n_max and n > n_max: + return np.sort(self.rng.choice(n, n_max, replace=False)) + return np.arange(n) + + # ---------------------------------------------------------------- sections + def section_summary(self) -> str: + parts = [] + rows = [ + ["input file", esc(self.input)], + ["events", f"{len(self.ds):,}"], + ["classes", esc(", ".join(f"{i} = {c}" for i, c in enumerate(self.classes)))], + ["folds", f"{self.ds.n_folds} ({esc(self.ds.fold_rule)})"], + ["configuration", esc(self.config_source)], + ["run directory", esc(self.run_dir)], + ["package", esc(f"corenet {__version__}" + (f", git {git_hash()}" if git_hash() else ""))], + ["generated", esc(self.generated)], + ] + parts.append(table(["", ""], rows, "Run")) + cfg_text = yaml.safe_dump(self.config, sort_keys=False, allow_unicode=True) + parts.append(f"
Configuration ({esc(self.config_source)})
{esc(cfg_text)}
") + + # events per class + rows = [] + for i, c in enumerate(self.classes): + sel = self.labels == i + rows.append([c, int(sel.sum()), float(self.weights[sel].sum()), int((self.weights[sel] < 0).sum())]) + parts.append(table(["class", "events", "sum of weights", "negative weights"], rows, "Events per class in the input file")) + + # recipe + hist = next((fd.history for fd in self.folds if fd.history), None) + meta = next((fd.checkpoint_meta for fd in self.folds if fd.checkpoint_meta), None) + recipe = (hist or {}).get("recipe") or {k: v for k, v in (meta or {}).items() if k not in ("fold", "epoch", "exclude_folds", "input", "n_folds", "fold_rule", "fold_seed", "finetune_trainable_parameters")} + if recipe: + parts.append(table(["setting", "value"], [[k, esc(v)] for k, v in recipe.items()], "Training recipe")) + else: + parts.append(note("No training recipe recorded (no history or checkpoint).")) + self.gaps.append("training recipe: no history_fold*.json or model_fold*.pkl") + + # per-fold table + rows = [] + wall_recorded = False + for fd in self.folds: + k = fd.fold + h = fd.history or {} + entries = h.get("history", []) + n_test = int((self.fold_of == k).sum()) + n_train = h.get("n_train") + n_val = h.get("n_val") + if n_train is None: + excl = fd.exclude_folds or [] + n_val = int(np.isin(self.fold_of, excl).sum()) + n_train = len(self.ds) - n_test - n_val + wall = None + for key in ("wall_time_s", "seconds", "time"): + if entries and key in entries[-1]: + wall = entries[-1][key] + wall_recorded = True + rows.append( + [ + k, + esc(fd.exclude_folds if fd.exclude_folds is not None else "-"), + n_train, + n_val, + n_test, + len(entries) if entries else "-", + fmt(fd.best_epoch) if fd.best_epoch is not None else "-", + fmt(h.get("stopped_after_epoch")) if h.get("stopped_after_epoch") is not None else "-", + fd.n_parameters if fd.n_parameters is not None else "-", + fmt(h.get("finetune_trainable_parameters")) if h.get("finetune_trainable_parameters") is not None else "-", + fmt(wall, 0) if wall is not None else "-", + esc(", ".join(sorted(fd.splits))) or "-", + ] + ) + parts.append( + table( + ["fold", "validation folds", "training events", "validation events", "test events", "epochs run", "best epoch", "stopped after", "parameters", "fine-tuned parameters", "wall time [s]", "predictions"], + rows, + "Folds", + ) + ) + if not wall_recorded: + parts.append(note("Wall time: not recorded in the history files.")) + self.gaps.append("wall time: corenet-train does not record it in history_fold*.json") + if any(fd.history and fd.history.get("early_stop_patience") for fd in self.folds): + parts.append(note("Best epoch: the epoch with the highest validation AUC; its weights are the ones in the checkpoint (early stopping). 'Stopped after' is the epoch at which training stopped, '-' when every epoch was run.")) + else: + parts.append(note("Best epoch: the epoch with the highest validation AUC in the history; without early stopping the checkpoint holds the weights after the last epoch.")) + return "".join(parts) + + def section_training(self) -> str: + with_hist = [fd for fd in self.folds if fd.history and fd.history.get("history")] + if not with_hist: + self.gaps.append("training curves: no history_fold*.json with epochs") + return note("No history file with epochs: no training curves.") + keys = [("train_loss", "training loss"), ("val_loss", "validation loss"), ("val_auc", "validation AUC")] + fig, axes = plt.subplots(1, 3, figsize=(9.6, 2.9)) + any_val = False + for i, (key, lab) in enumerate(keys): + ax = axes[i] + for j, fd in enumerate(with_hist): + entries = fd.history["history"] + ep = [e["epoch"] for e in entries if e.get(key) is not None] + val = [e[key] for e in entries if e.get(key) is not None] + if not ep: + continue + any_val |= key != "train_loss" + ax.plot(ep, val, "-", color=f"C{j % 10}", lw=1.2, label=f"fold {fd.fold}") + best = fd.best_epoch + if best is not None and best in ep: + ax.plot([best], [val[ep.index(best)]], "*", color=f"C{j % 10}", ms=9) + ax.set_xlabel("epoch") + ax.set_ylabel(lab) + ax.grid(alpha=0.25, lw=0.5) + axes[0].legend(frameon=False) + out = figure(fig, "Training loss, validation loss and validation AUC per epoch, one line per fold; the star marks the best epoch (highest validation AUC).") + if not any_val: + self.gaps.append("validation curves: the histories have no validation entries (train with --exclude-folds)") + out += note("No validation fold in the histories: validation loss and AUC are empty.") + rows = [] + for fd in with_hist: + e = fd.history["history"][-1] + rows.append([fd.fold, e["epoch"], e.get("batch_size"), fmt(e.get("lr"), 6), e.get("train_loss"), e.get("val_loss"), e.get("val_auc")]) + out += table(["fold", "last epoch", "batch size", "learning rate", "training loss", "validation loss", "validation AUC"], rows, "Last epoch of every fold") + return out + + # ---- classification + def _main_curves(self): + """{split: [(fold, fpr, tpr, auc)]} of the main score (class 1 against the rest).""" + out = {} + for name in SPLITS: + for fd, s in self.splits_of(name): + y, sc, w = s.label == 1, s.probs[:, 1], np.clip(s.weight, 0, None) + if y.all() or not y.any(): + continue + f, t = roc_points(y, sc, w) + out.setdefault(name, []).append((fd.fold, f, t, auc_of(y, sc, w))) + return out + + def section_classification(self) -> str: + if not any("test" in fd.splits for fd in self.folds): + self.gaps.append("classification: no prediction file for any fold") + return note("No prediction file: no ROC curves, AUC table or score distributions.") + parts = [] + curves = self._main_curves() + if not curves: + self.gaps.append("ROC curves: the predicted events have only one class (no signal or no background)") + parts.append(note("The predicted events hold a single class: no ROC curve.")) + else: + fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.4)) + colors = {"test": "C0", "train": "C3", "validation": "C2"} + for name in SPLITS: + if name not in curves: + continue + cs = curves[name] + mu, sd = mean_curve([(f, t) for _, f, t, _ in cs]) + aucs = [c[3] for c in cs] + lab = f"{name} ({len(cs)} fold{'s' if len(cs) > 1 else ''}) AUC {mean_sd(aucs)}" + for ax in (a, b): + if name == "test": + for _, f, t, _ in cs: + ax.plot(f, t, color=colors[name], lw=0.6, alpha=0.35) + ax.plot(ROC_GRID, mu, color=colors[name], ls=SPLIT_STYLE[name], lw=1.5, label=lab if ax is a else None) + if sd is not None: + ax.fill_between(ROC_GRID, mu - sd, mu + sd, color=colors[name], alpha=0.2, lw=0) + a.plot([0, 1], [0, 1], "k:", lw=0.8) + a.set_xlabel("background efficiency") + a.set_ylabel("signal efficiency") + a.set_xlim(0, 1) + a.set_ylim(0, 1.02) + a.legend(loc="lower right", frameon=False) + a.set_title("(a)", loc="left") + b.set_xscale("log") + b.set_xlim(1e-4, 1) + b.set_ylim(0, 1.02) + b.set_xlabel("background efficiency (log)") + b.set_title("(b)", loc="left") + b.grid(alpha=0.25, which="both", lw=0.5) + parts.append(figure(fig, f"ROC of the main score P({self.classes[1]}) (class 1 against every other class, weighted): thin lines are the test folds, thick lines the mean over folds with the ± 1 sd band; dashed = training folds, dash-dotted = validation fold, where predictions exist.")) + # AUC table + rows = [] + folds = sorted({c[0] for cs in curves.values() for c in cs}) + for k in folds: + row = [k] + for name in SPLITS: + v = next((c[3] for c in curves.get(name, []) if c[0] == k), None) + row.append(fmt(v) if v is not None else "-") + rows.append(row) + rows.append(["mean ± sd"] + [mean_sd([c[3] for c in curves.get(name, [])]) for name in SPLITS]) + parts.append(table(["fold", "test", "validation", "train"], rows, "AUC of the main score (sd over folds, ddof = 1)")) + for name in ("validation", "train"): + if name not in curves: + parts.append(note(f"No predictions on the {name} folds (corenet-evaluate --fold -1 provides them).")) + + # score distributions + parts.append(self._score_figure()) + # multi-class + if len(self.classes) > 2: + parts.append(self._confusion_figure()) + parts.append(self._ovr_and_heads_figure()) + elif any(s.heads for fd in self.folds for s in fd.splits.values()): + parts.append(self._ovr_and_heads_figure()) + return "".join(parts) + + def _score_figure(self) -> str: + test = self.splits_of("test") + if not test: + return "" + bins = np.linspace(0, 1, 41) + fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.2)) + for name in ("test", "train"): + sp = self.splits_of(name) + if not sp: + continue + lab = np.concatenate([s.label for _, s in sp]) + sc = np.concatenate([s.probs[:, 1] for _, s in sp]) + w = np.concatenate([s.weight for _, s in sp]) + series = self.class_series(sc, lab, w, {"ls": SPLIT_STYLE[name]}) + series = [(f"{c} ({name})", v, ww, st) for c, v, ww, st in series] + hist_panel(a, series, bins, f"P({self.classes[1]})") + hist_panel(b, series, bins, f"P({self.classes[1]})", logy=True) + a.legend(frameon=False) + a.set_title("(a) linear", loc="left") + b.set_title("(b) log", loc="left") + cap = "Main score per class on the test folds (solid), weighted densities" + if self.splits_of("train"): + cap += "; dashed: the same on the training folds (overtraining check)" + return figure(fig, cap + ".") + + def _confusion_figure(self) -> str: + test = self.splits_of("test") + n = len(self.classes) + cm = np.zeros((n, n)) + for _, s in test: + pred = s.probs.argmax(1) + w = np.clip(s.weight, 0, None) + for i in range(n): + for j in range(n): + cm[i, j] += w[(s.label == i) & (pred == j)].sum() + present = [i for i in range(n) if cm[i].sum() > 0] + if not present: + return note("Confusion matrix: no test events.") + norm = cm / np.where(cm.sum(1, keepdims=True) > 0, cm.sum(1, keepdims=True), 1) + fig, ax = plt.subplots(figsize=(1.2 * n + 2.2, 1.0 * n + 1.6)) + im = ax.imshow(norm[present], cmap="Blues", vmin=0, vmax=1) + for a, i in enumerate(present): + for j in range(n): + ax.text(j, a, f"{norm[i, j]:.3f}", ha="center", va="center", color="white" if norm[i, j] > 0.6 else "black", fontsize=8) + ax.set_xticks(range(n)) + ax.set_xticklabels(self.classes) + ax.set_yticks(range(len(present))) + ax.set_yticklabels([self.classes[i] for i in present]) + ax.set_xlabel("predicted class (argmax)") + ax.set_ylabel("true class") + fig.colorbar(im, ax=ax, fraction=0.046) + return figure(fig, "Confusion matrix at the argmax of the class probabilities on the test folds, weighted, each true class normalised to 1.") + + def _ovr_and_heads_figure(self) -> str: + test = self.splits_of("test") + parts = [] + n = len(self.classes) + has_heads = any(s.heads for _, s in test) + fig, axes = plt.subplots(1, 2 if has_heads else 1, figsize=(7.8 if has_heads else 4.0, 3.4), squeeze=False) + ax = axes[0, 0] + rows = [] + for i, c in enumerate(self.classes): + cs = [(fd.fold, *roc_points(s.label == i, s.probs[:, i], np.clip(s.weight, 0, None)), auc_of(s.label == i, s.probs[:, i], np.clip(s.weight, 0, None))) for fd, s in test if (s.label == i).any() and not (s.label == i).all()] + if not cs: + continue + mu, sd = mean_curve([(f, t) for _, f, t, _ in cs]) + ax.plot(ROC_GRID, mu, color=class_color(i), lw=1.4, label=f"{c} vs rest AUC {mean_sd([x[3] for x in cs])}") + if sd is not None: + ax.fill_between(ROC_GRID, mu - sd, mu + sd, color=class_color(i), alpha=0.2, lw=0) + rows.append([f"P({c}) vs label = {c}", mean_sd([x[3] for x in cs])]) + ax.plot([0, 1], [0, 1], "k:", lw=0.8) + ax.set_xlabel("efficiency of the other classes") + ax.set_ylabel("efficiency of the class") + ax.set_title("(a) one class against the rest", loc="left") + ax.legend(loc="lower right", frameon=False) + if has_heads: + ax = axes[0, 1] + for name in sorted({k for _, s in test for k in s.heads}): + i = self.classes.index(name) if name in self.classes else None + if i is None: + continue + cs = [(fd.fold, *roc_points(s.label == i, s.heads[name], np.clip(s.weight, 0, None)), auc_of(s.label == i, s.heads[name], np.clip(s.weight, 0, None))) for fd, s in test if name in s.heads and (s.label == i).any() and not (s.label == i).all()] + if not cs: + continue + mu, sd = mean_curve([(f, t) for _, f, t, _ in cs]) + ax.plot(ROC_GRID, mu, color=class_color(i), lw=1.4, label=f"head {name} AUC {mean_sd([x[3] for x in cs])}") + if sd is not None: + ax.fill_between(ROC_GRID, mu - sd, mu + sd, color=class_color(i), alpha=0.2, lw=0) + rows.append([f"head {name} vs label = {name}", mean_sd([x[3] for x in cs])]) + ax.plot([0, 1], [0, 1], "k:", lw=0.8) + ax.set_xlabel("efficiency of the other classes") + ax.set_ylabel("efficiency of the class") + ax.set_title("(b) auxiliary heads", loc="left") + ax.legend(loc="lower right", frameon=False) + parts.append(figure(fig, "Test folds, mean over folds with the ± 1 sd band: (a) every class scored by its own probability against all other classes" + ("; (b) the auxiliary head of every further output against its class." if has_heads else "."))) + parts.append(table(["score", "AUC (mean ± sd over test folds)"], rows, "One-against-the-rest and auxiliary-head AUC")) + return "".join(parts) + + # ---- hypotheses and pairing + def section_hypotheses(self) -> str: + test = self.splits_of("test") + hyps = sorted({h for _, s in test for h in s.views}) + parts = [] + if not hyps: + if test: + parts.append(note("Every hypothesis has a single candidate: no view probabilities.")) + else: + self.gaps.append("hypotheses: no prediction file") + parts.append(note("No prediction file: no view probabilities.")) + return "".join(parts) + fig, axes = grid_figure(len(hyps), per_row=3, w=3.2, h=2.6) + for ax, h in zip(axes, hyps): + V = next(s.views[h].shape[1] for _, s in test if h in s.views) + bins = np.linspace(1.0 / V, 1.0, 31) + for name in ("test", "train"): + sp = [(fd, s) for fd, s in self.splits_of(name) if h in s.views] + if not sp: + continue + mx = np.concatenate([s.views[h].max(1) for _, s in sp]) + lab = np.concatenate([s.label for _, s in sp]) + w = np.concatenate([s.weight for _, s in sp]) + series = [(f"{c} ({name})", v, ww, st) for c, v, ww, st in self.class_series(mx, lab, w, {"ls": SPLIT_STYLE[name]})] + hist_panel(ax, series, bins, f"max view probability, {h} ({V} views)") + ax.legend(frameon=False) + parts.append(figure(fig, "Highest view probability per event and class on the test folds (dashed: training folds when available). The views of a hypothesis are its candidate assignments, e.g. the pairings of the b jets into two Higgs bosons.")) + # argmax view shares + rows = [] + for h in hyps: + V = next(s.views[h].shape[1] for _, s in test if h in s.views) + names = self._view_names(h, V) + for i, c in enumerate(self.classes): + counts = np.zeros(V) + for _, s in test: + if h not in s.views: + continue + sel = s.label == i + if not sel.any(): + continue + am = s.views[h][sel].argmax(1) + w = np.clip(s.weight[sel], 0, None) + counts += np.bincount(am, weights=w, minlength=V)[:V] + if counts.sum() > 0: + rows.append([h, c] + [fmt(x) for x in counts / counts.sum()]) + if rows: + parts.append(table(["hypothesis", "class"] + names, [r for r in rows if r[0] == h], f"Weighted share of the argmax view, test folds: {h}")) + parts.append(self._pairing_accuracy(test, hyps)) + return "".join(parts) + + def _view_names(self, h: str, V: int) -> list[str]: + T = self.model.tables.get(h) + if T is None or len(T.views) != V: + return [f"view {v}" for v in range(V)] + names = [] + for view in T.views: + names.append("|".join("".join(str(slot) for _, slot in child) for child in view)) + return names + + def _targets(self) -> dict[str, dict[str, np.ndarray]]: + out = {} + with h5py.File(self.input, "r") as f: + if "TARGETS" not in f: + return out + for g in f["TARGETS"]: + grp = f["TARGETS"][g] + if not isinstance(grp, h5py.Group): + continue + leaves = {k: grp[k][...].astype(np.int64) for k in grp if isinstance(grp[k], h5py.Dataset) and grp[k].dtype.kind in "iu" and grp[k].ndim == 1 and len(grp[k]) == len(self.ds)} + if leaves: + out[g] = leaves + return out + + def _view_assignments(self, h: str, v: int) -> dict[str, tuple]: + """{declared node: assignment (tuples of (role, slot))} of view ``v`` of hypothesis ``h``.""" + T = self.model.tables[h] + out = {} + + def rec(declared, canonical, cand): + nt = T.nodes[canonical] + out[declared] = nt.candidates[cand] + for j, c in enumerate(self.spec.nodes[declared].children): + if c in self.model.leaves: + continue + rec(c, T.aliases.get(c, c), int(nt.child_index[cand, j])) + + rec(h, h, int(T.view_index[v])) + return out + + def _pairing_accuracy(self, test, hyps) -> str: + targets = self._targets() + if not targets: + self.gaps.append("pairing accuracy: the input file has no TARGETS group (generator-matched jets)") + return note("No TARGETS in the input file: the pairing accuracy against the generator matching cannot be computed.") + parts = [] + sel = self.ds.selected + for h in hyps: + V = next(s.views[h].shape[1] for _, s in test if h in s.views) + T = self.model.tables.get(h) + if T is None or len(T.views) != V: + continue + declared = self.spec.nodes_in(h) + matched = {g: n for g in targets for n in declared if norm_name(g) == norm_name(n)} + if not matched: + self.gaps.append(f"pairing accuracy of {h}: no TARGETS group named like one of its nodes ({sorted(declared)}; TARGETS has {sorted(targets)})") + parts.append(note(f"{h}: no TARGETS group matches a node of the hypothesis ({', '.join(sorted(declared))}); TARGETS groups: {', '.join(sorted(targets))}.")) + continue + # truth: per matched node the sorted file slots of its generator-matched jets, and which roles it uses + n = len(self.ds) + correct = np.ones((V, n), bool) + complete = np.ones(n, bool) + contained = np.ones(n, bool) + usable = [] + for g, node in matched.items(): + truth = np.stack(list(targets[g].values()), 1) # (n, k) file slots + truth_sorted = np.sort(truth, 1) + assignments = [self._view_assignments(h, v).get(node) for v in range(V)] + pairs = [[(r, s) for r, s in a if r in sel] if a is not None else None for a in assignments] + if any(p is None or len(p) != truth.shape[1] for p in pairs): + continue # the group lists a different number of jets than the node has candidates + usable.append((g, node)) + complete &= (truth >= 0).all(1) + roles = sorted({r for p in pairs for r, _ in p}) + pool = np.concatenate([sel[r] for r in roles], 1) # (n, slots) file slots of the roles + for col in range(truth.shape[1]): + contained &= (pool == truth[:, col : col + 1]).any(1) + for v, p in enumerate(pairs): + view_slots = np.sort(np.stack([sel[r][:, slot] for r, slot in p], 1), 1) + correct[v] &= (view_slots == truth_sorted).all(1) + if not usable: + parts.append(note(f"{h}: the matched TARGETS groups ({', '.join(matched)}) list a different number of jets than the nodes they name.")) + continue + if all(np.array_equal(correct[0], correct[v]) for v in range(1, V)): + parts.append(note(f"{h}: the TARGETS groups {', '.join(g for g, _ in usable)} do not distinguish the {V} views (every view assigns their jets the same way): no pairing accuracy.")) + self.gaps.append(f"pairing accuracy of {h}: the TARGETS groups do not distinguish its views") + continue + rows = [] + per_fold = [] + thr_rows = {} + for fd, s in test: + if h not in s.views: + continue + idx = s.index + comp, cont = complete[idx], contained[idx] & complete[idx] + am = s.views[h].argmax(1) + mx = s.views[h].max(1) + ok = correct[am, idx] + acc_m = ok[comp].mean() if comp.any() else np.nan + acc_c = ok[cont].mean() if cont.any() else np.nan + per_fold.append((acc_m, acc_c)) + rows.append([fd.fold, int(comp.sum()), int(cont.sum()), fmt(acc_m), fmt(acc_c)]) + thr = [1.0 / V] + [t for t in VIEW_THRESHOLDS if t > 1.0 / V + 1e-9] + thr_rows[fd.fold] = [(t, ok[cont & (mx > t)].mean() if (cont & (mx > t)).any() else np.nan, int((cont & (mx > t)).sum())) for t in thr] + if not rows: + continue + rows.append(["mean ± sd", "", "", mean_sd([a for a, _ in per_fold]), mean_sd([c for _, c in per_fold])]) + parts.append(table(["fold", "events with complete truth", "of which contained", "accuracy (complete)", "accuracy (contained)"], rows, f"Pairing accuracy of the argmax view of {h} against TARGETS {', '.join(g for g, _ in usable)} (random: 1/{V} = {1.0 / V:.3f})")) + fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.2)) + thr = [t for t, _, _ in next(iter(thr_rows.values()))] + accs = np.array([[acc for _, acc, _ in thr_rows[k]] for k in thr_rows]) + ns = np.array([[nn for _, _, nn in thr_rows[k]] for k in thr_rows]).sum(0) + x = np.arange(len(thr)) + for j, k in enumerate(thr_rows): + a.plot(x, 100 * accs[j], "-", color=f"C{j % 10}", lw=0.8, alpha=0.5, label=f"fold {k}") + mu = np.nanmean(accs, 0) + a.plot(x, 100 * mu, "o-", color="k", lw=1.4, ms=4, label="mean over folds") + for xi, (m, nn) in enumerate(zip(mu, ns)): + a.annotate(f"N = {nn:,}", (xi, 100 * m), textcoords="offset points", xytext=(0, 7), ha="center", fontsize=6) + a.axhline(100.0 / V, color="k", ls="--", lw=0.8) + a.set_xticks(x) + a.set_xticklabels([f"> {t:.2f}" for t in thr]) + a.set_xlabel(f"max view probability of {h}") + a.set_ylabel("pairing accuracy [%]") + a.set_ylim(0, 105) + a.legend(frameon=False) + a.grid(alpha=0.25, lw=0.5) + a.set_title("(a) accuracy above a confidence threshold", loc="left") + # binned accuracy + edges = np.linspace(1.0 / V, 1.0, 11) + for j, (fd, s) in enumerate([(fd, s) for fd, s in test if h in s.views]): + idx = s.index + cont = contained[idx] & complete[idx] + am, mx = s.views[h].argmax(1), s.views[h].max(1) + ok = correct[am, idx] + which = np.clip(np.digitize(mx, edges) - 1, 0, len(edges) - 2) + acc = [ok[cont & (which == b)].mean() if (cont & (which == b)).any() else np.nan for b in range(len(edges) - 1)] + b.plot(0.5 * (edges[1:] + edges[:-1]), 100 * np.array(acc), "o-", color=f"C{j % 10}", lw=1.0, ms=3, label=f"fold {fd.fold}") + b.plot([1.0 / V, 1], [100.0 / V, 100], "k:", lw=0.8, label="perfect calibration") + b.set_xlabel(f"max view probability of {h}") + b.set_ylabel("pairing accuracy [%]") + b.set_ylim(0, 105) + b.legend(frameon=False) + b.grid(alpha=0.25, lw=0.5) + b.set_title("(b) accuracy per probability bin", loc="left") + parts.append(figure(fig, f"Pairing accuracy of {h} on contained events of the test folds (all generator-matched jets among the candidates): (a) for events whose highest view probability exceeds a threshold, N summed over folds, dashed = random; (b) in bins of the highest view probability, dotted = accuracy equal to the probability.")) + return "".join(parts) + + # ---- inputs as the network sees them + def _node_phi_label(self, h: str, node: str) -> str: + T = self.model.tables[h] + parents = [(pn, j) for pn in self.model.levels[h] for j, c in enumerate(T.nodes[pn].children) if c == node] + pnodes = {pn for pn, _ in parents} + if len(pnodes) == 1: + pnode = next(iter(pnodes)) + P = T.nodes[node].n + allidx = torch.cat([T.nodes[pnode].child_index[:, j] for _, j in parents]) + if allidx.numel() == P and allidx.unique().numel() == P: + return f"Δφ to {pnode}" + return "φ" + + def collect_network_inputs(self, idx: np.ndarray, chunk: int = 16384) -> dict: + """{key: (feature names, values (m, F), labels (m,), weights (m,))} of every tensor the network + embeds, over the events ``idx`` and all present candidates.""" + spec, model = self.spec, self.model + acc: dict[str, tuple] = {} + + def add(key, names, x, present, rows): + x = x.detach().cpu().numpy() + n, F, P = x.shape + pres = np.ones((n, P), bool) if present is None else present.detach().cpu().numpy().astype(bool) + vals = x.transpose(0, 2, 1)[pres] + lab = np.broadcast_to(self.labels[rows][:, None], (n, P))[pres] + w = np.broadcast_to(self.weights[rows][:, None], (n, P))[pres] + e = acc.setdefault(key, (list(names), [], [], [])) + e[1].append(vals) + e[2].append(lab) + e[3].append(w) + + def event_name(name): + return f"log({name} - {spec.min_jets - 1})" if "nSelJets" in name else name + + with torch.no_grad(): + for start in range(0, len(idx), chunk): + rows = idx[start : start + chunk] + sel = torch.as_tensor(rows) + inputs = {k: v[sel] for k, v in self.ds.inputs.items()} + prep = model._prepare(inputs) + if prep["event"] is not None: + add("event scalars", [event_name(n) for n in spec.event], prep["event"], None, rows) + seen = set() + for h, T in model.tables.items(): + hp = prep["hyp"][h] + for node in model.levels[h]: + if node in seen: + continue + seen.add(node) + nt = T.nodes[node] + for j, child in enumerate(nt.children): + names = ["log(1+pT)", "η", f"Δφ to {node}", "log(1+m)"] + if child in model.leaves: + names += model._extras(child) + add(f"{node} ← {child}", names, hp["slot_feats"][node][j], hp["slot_present"][node][j], rows) + if node in model.tops: + names = ["log(1+pT)", "η", "log(1+m)"] + else: + owner = spec.owner.get(node, h) + owner = owner if node in model.levels.get(owner, []) else h + names = ["log(1+pT)", "η", self._node_phi_label(owner, node), "log(1+m)"] + add(f"{node} candidates", names, prep["embed_in"][node], prep["present"][node], rows) + if "context" in hp: + c = hp["context"] + add(f"{h} context: {spec.hypotheses[h].context} and the candidates' jets", ["log(1+pT)", "η", "log(1+m)", "flag (2 = candidate jet, 1 = context jet)"], c["feats"], ~c["mask"], rows) + for key, r in prep["relations"].items(): + add(f"relation {key.replace('|', ' - ')}", ["log(1+M)", "ΔR", "Δφ"], r, None, rows) + return {k: (names, np.concatenate(v), np.concatenate(l), np.concatenate(w)) for k, (names, v, l, w) in acc.items()} + + def section_inputs(self) -> str: + idx = self.selected_subset(self.args.max_events) + data = self.collect_network_inputs(idx) + parts = [note(f"Distributions of the quantities the network embeds, computed from the input file by the loader and the network's own preparation step, over {len(idx):,} events" + (" (a random subsample; --max-events)" if len(idx) < len(self.ds) else "") + f" and all present candidates; weighted by the event weight (clipped at 0), each class normalised to unit area. Jet features: log(1+pT), η" + (" (reflected so that the leading jet of the first role has η ≥ 0)" if self.spec.training.reflect_eta else "") + ", Δφ to the parent candidate, log(1+m).")] + for key, (names, vals, lab, w) in data.items(): + fig, axes = grid_figure(len(names), per_row=6) + for ax, j, name in zip(axes, range(len(names)), names): + series = self.class_series(vals[:, j], lab, w) + hist_panel(ax, series, shared_bins([v for _, v, _, _ in series]), name) + axes[0].legend(frameon=False) + parts.append(figure(fig, f"{key}: {', '.join(names)}.")) + return "".join(parts) + + # ---- raw inputs + def section_raw(self) -> str: + ds, spec = self.ds, self.spec + idx = self.selected_subset(self.args.max_events) + lab, w = self.labels[idx], self.weights[idx] + parts = [note(f"The features of the input file for the members each role selected (per slot), the single objects and the event scalars, before any transformation; {len(idx):,} events" + (" (random subsample)" if len(idx) < len(ds) else "") + ", weighted, each class normalised to unit area. A column read for the selection only (e.g. btag) is shown for the selected jets as well.")] + extra_cols = {} + with h5py.File(self.input, "r") as f: + for role in spec.roles.values(): + coll = spec.collections[role.collection] + cols = [c for c in role.columns if c not in coll.features] + if cols: + group = f["INPUTS"][resolve_group(f, coll.name)] + extra_cols[role.name] = {c: np.atleast_2d(group[c][...].astype(np.float32).T).T for c in cols if c in group} + for role in spec.roles.values(): + coll = spec.collections[role.collection] + x = ds.inputs[role.name][idx].numpy() # (n, F+1, slots) + present = x[:, -1] > 0 + feats = list(coll.features) + extra = extra_cols.get(role.name, {}) + n_slots = x.shape[2] + names = feats + list(extra) + fig, axes = plt.subplots(len(names), n_slots, figsize=(2.3 * n_slots, 1.9 * len(names)), squeeze=False) + for i, name in enumerate(names): + if name in feats: + col = x[:, feats.index(name)] + else: + slots = ds.selected[role.name][idx] + col = np.where(slots >= 0, extra[name][idx[:, None], np.clip(slots, 0, None)], np.nan) + bins = shared_bins([col[present]]) + for s in range(n_slots): + ax = axes[i, s] + ok = present[:, s] + series = self.class_series(col[ok, s], lab[ok], w[ok]) + hist_panel(ax, series, bins, f"{name} [{role.name} slot {s}]") + axes[0, 0].legend(frameon=False) + sel_text = f"{role.collection} {role.selector} {role.n}" + (" lowest" if role.ascending else "") + parts.append(figure(fig, f"Role {role.name} ({sel_text}): rows = features, columns = slots in selection order; empty slots are left out.", dpi=90)) + singles = [c for c in spec.collections.values() if c.max == 1 and c.name in ds.inputs] + for c in singles: + x = ds.inputs[c.name][idx].numpy() + present = x[:, -1, 0] > 0 + fig, axes = grid_figure(len(c.features), per_row=6) + for ax, j, name in zip(axes, range(len(c.features)), c.features): + series = self.class_series(x[present, j, 0], lab[present], w[present]) + hist_panel(ax, series, shared_bins([v for _, v, _, _ in series]), f"{name} [{c.name}]") + axes[0].legend(frameon=False) + parts.append(figure(fig, f"Single object {c.name}: {', '.join(c.features)}.")) + if spec.event: + ev = ds.inputs["event"][idx].numpy() + fig, axes = grid_figure(len(spec.event), per_row=6) + for ax, j, name in zip(axes, range(len(spec.event)), spec.event): + kind, where = event_source(spec, name) + series = self.class_series(ev[:, j], lab, w) + hist_panel(ax, series, shared_bins([v for _, v, _, _ in series]), f"{name} ({'computed from ' + where if kind == 'computed' else where})") + axes[0].legend(frameon=False) + parts.append(figure(fig, "Event scalars as read or computed by the loader.")) + if not spec.roles and not singles and not spec.event: + parts.append(note("The configuration declares no roles, single objects or event scalars.")) + return "".join(parts) + + # ---- weights + def section_weights(self) -> str: + lab, w = self.labels, self.weights + parts = [] + fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.2)) + series = [] + for i, c in enumerate(self.classes): + sel = lab == i + if sel.any(): + series.append((c, w[sel], np.ones(int(sel.sum())), {"color": class_color(i), "lw": 1.3})) + bins = shared_bins([v for _, v, _, _ in series], 60) + for lab_c, v, ww, st in series: + a.hist(v, bins=bins, histtype="step", label=lab_c, **st) + a.set_yscale("log") + a.set_xlabel("event weight (as in the file)") + a.set_ylabel("events") + a.legend(frameon=False) + a.set_title("(a) raw weights", loc="left") + normed = w.copy() + for i in range(len(self.classes)): + sel = lab == i + tot = np.clip(w[sel], 0, None).sum() + if tot > 0: + normed[sel] = np.clip(w[sel], 0, None) / tot + series = [(c, normed[lab == i], np.ones(int((lab == i).sum())), {"color": class_color(i), "lw": 1.3}) for i, c in enumerate(self.classes) if (lab == i).any()] + bins = shared_bins([v for _, v, _, _ in series], 60) + for lab_c, v, ww, st in series: + b.hist(v, bins=bins, histtype="step", label=lab_c, **st) + b.set_yscale("log") + b.set_xlabel("class-normalised weight (clipped at 0, class sum = 1)") + b.set_ylabel("events") + b.set_title("(b) as training uses them", loc="left") + parts.append(figure(fig, "Event weights per class over the whole input file: (a) as stored; (b) clipped at 0 and divided by the class sum, which is how the training loss weights an event (the training normalises over its own training events of every fold).")) + rows = [] + for i, c in enumerate(self.classes): + sel = lab == i + if not sel.any(): + continue + ws = w[sel] + s1, s2 = ws.sum(), (ws**2).sum() + neff = s1**2 / s2 if s2 > 0 else 0.0 + rows.append([c, int(sel.sum()), float(s1), float(ws.min()), float(ws.max()), float(ws.mean()), float(ws.std()), fmt(neff, 1), fmt(neff / sel.sum(), 4), int((ws < 0).sum()), fmt(abs(ws[ws < 0].sum()) / s1 if s1 > 0 else np.nan)]) + parts.append(table(["class", "events", "sum", "min", "max", "mean", "sd", "effective events (sum w)^2 / sum w^2", "effective / events", "negative weights", "|negative sum| / sum"], rows, "Weight statistics per class (whole file)")) + folds = sorted(np.unique(self.fold_of).tolist()) + rows = [] + for k in folds: + fsel = self.fold_of == k + row = [k, int(fsel.sum())] + for i, c in enumerate(self.classes): + sel = fsel & (lab == i) + tot = w[lab == i].sum() + row += [int(sel.sum()), float(w[sel].sum()), fmt(w[sel].sum() / tot if tot else np.nan, 3), int((w[sel] < 0).sum())] + rows.append(row) + header = ["fold", "events"] + [f"{c}: {q}" for c in self.classes for q in ("events", "sum", "share", "negative")] + parts.append(table(header, rows, "Events and weights per fold and class (closure: every fold should carry about 1/n_folds of each class)")) + rows = [] + for fd in self.folds: + k = fd.fold + excl = fd.exclude_folds or [] + train = ~np.isin(self.fold_of, [k, *excl]) + row = [k, esc(excl) if excl else "-"] + for i, c in enumerate(self.classes): + sel = train & (lab == i) + tot = np.clip(w[sel], 0, None).sum() + row += [int(sel.sum()), float(tot), int((w[sel] < 0).sum())] + rows.append(row) + header = ["held-out fold", "validation folds"] + [f"{c}: {q}" for c in self.classes for q in ("training events", "training sum", "negative (count as 0)")] + parts.append(table(header, rows, "Training set of every fold: the weights of every class are normalised to 1 over these events")) + return "".join(parts) + + # ---- other checks + def section_other(self) -> str: + ds, spec = self.ds, self.spec + parts = [] + idx = self.selected_subset(self.args.max_events) + lab, w = self.labels[idx], self.weights[idx] + profiles = [] + first_role = next(iter(spec.roles.values()), None) + if first_role is not None: + x = ds.inputs[first_role.name][idx].numpy() + feats = list(spec.collections[first_role.collection].features) + if "pt" in feats: + pt = x[:, feats.index("pt")] + present = x[:, -1] > 0 + for s in (0, first_role.n - 1): + if s < pt.shape[1]: + profiles.append((f"pT of {first_role.name} slot {s} [GeV]", np.where(present[:, s], pt[:, s], np.nan))) + for j, name in enumerate(spec.event): + if "nSelJets" in name: + profiles.append((name, ds.inputs["event"][idx].numpy()[:, j])) + if not profiles: + parts.append(note("No jet role or jet multiplicity in the configuration: no weight profiles.")) + return "".join(parts) + fig, axes = grid_figure(len(profiles), per_row=3, w=3.2, h=2.6) + for ax, (name, x) in zip(axes, profiles): + ok = np.isfinite(x) + bins = shared_bins([x[ok]], 20) + centres = 0.5 * (bins[1:] + bins[:-1]) + for i, c in enumerate(self.classes): + sel = ok & (lab == i) + if not sel.any(): + continue + which = np.clip(np.digitize(x[sel], bins) - 1, 0, len(bins) - 2) + means = np.array([w[sel][which == b].mean() if (which == b).any() else np.nan for b in range(len(bins) - 1)]) + sems = np.array([w[sel][which == b].std() / np.sqrt((which == b).sum()) if (which == b).sum() > 1 else np.nan for b in range(len(bins) - 1)]) + ax.errorbar(centres, means, sems, fmt="o-", color=class_color(i), ms=3, lw=1.0, capsize=2, label=c) + ax.set_xlabel(name) + ax.set_ylabel("mean event weight") + ax.grid(alpha=0.25, lw=0.5) + axes[0].legend(frameon=False) + parts.append(figure(fig, "Mean event weight (as stored) per class in bins of the leading and the last candidate jet pT of the first role and of the jet multiplicity; error bars are the standard error of the mean.")) + return "".join(parts) + + def section_gaps(self) -> str: + if not self.gaps: + return "

Everything requested could be produced for this run.

" + items = "".join(f"
  • {esc(g)}
  • " for g in dict.fromkeys(self.gaps)) + return f"
      {items}
    " + + # ---------------------------------------------------------------- page + def render(self) -> str: + bodies = {} + order = [s for s in SECTIONS if s[0] != "gaps"] + for key, title in order: + try: + bodies[key] = getattr(self, f"section_{key}")() + except Exception as e: # a section that fails is reported, not fatal + logging.error(f"section '{title}' failed:\n{traceback.format_exc()}") + self.gaps.append(f"section '{title}' could not be produced: {type(e).__name__}: {e}") + bodies[key] = f'

    This section could not be produced: {esc(type(e).__name__)}: {esc(e)}

    ' + plt.close("all") + bodies["gaps"] = self.section_gaps() + toc = "".join(f'
  • {i + 1}. {esc(t)}
  • ' for i, (k, t) in enumerate(SECTIONS)) + sections = "".join(f'

    {i + 1}. {esc(t)}

    {bodies[k]}
    ' for i, (k, t) in enumerate(SECTIONS)) + cmd = esc(" ".join(sys.argv)) + return f""" +CoReNet report: {esc(self.run_dir)} + +

    CoReNet report

    +

    run directory {esc(self.run_dir)} | input {esc(self.input)} | generated {esc(self.generated)} | corenet {esc(__version__)}
    command: {cmd}

    + +{sections} +

    Weighted quantities use the event weights of the input file clipped at 0, as the training does. Mean ± sd are over folds with ddof = 1.

    + +""" + + +_GIT_HASH: str | None = None + + +def git_hash() -> str: + """Short git hash of the package checkout, '' when not in a git repository.""" + global _GIT_HASH + if _GIT_HASH is None: + try: + out = subprocess.run( + ["git", "-C", str(Path(__file__).resolve().parent), "rev-parse", "--short", "HEAD"], + capture_output=True, + text=True, + timeout=5, + ) + _GIT_HASH = out.stdout.strip() if out.returncode == 0 else "" + except Exception: + _GIT_HASH = "" + return _GIT_HASH + + +# ----------------------------------------------------------------------------- command line +def build_parser() -> argparse.ArgumentParser: + p = argparse.ArgumentParser( + prog="corenet-report", + description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + p.add_argument("--run-dir", required=True, help="directory written by corenet-train (and corenet-evaluate)") + p.add_argument("--input", required=True, help="the HDF5 file the run was trained on") + p.add_argument("--output", default=None, help="HTML file to write [/report.html]") + p.add_argument("--config", default=None, help="configuration file [the one stored in the checkpoint]") + p.add_argument("--folds", type=int, nargs="*", default=None, help="folds to include [every fold found in the run directory]") + p.add_argument("--max-events", type=int, default=500000, help="events of the input file used for the input and weight distributions (random subsample above this) [500000]; 0 = all") + p.add_argument("--n-folds", type=int, default=None, help="fold = squares(event) %% K instead of EVENT/fold [the run's rule]") + p.add_argument("--fold-seed", type=int, default=None, help="seed of that rule [the run's]") + p.add_argument("--rest-order", choices=["pt", "selector"], default=None, help="ordering of the 'rest' selector [the run's]") + return p + + +def main(argv=None) -> Path: + args = build_parser().parse_args(argv) + logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") + report = Report(args) + report.load() + page = report.render() + out = Path(args.output) if args.output else report.run_dir / "report.html" + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(page, encoding="utf-8") + logging.info(f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB, {len(report.gaps)} items not produced)") + for g in dict.fromkeys(report.gaps): + logging.info(f"not produced: {g}") + return out + + +def cli(): + main() + + +if __name__ == "__main__": + cli() From 41195a30e98e44aced4e4dee140fe45890393d11 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:12:42 -0400 Subject: [PATCH 13/23] tests: corenet-report on 2-epoch synthetic runs (TARGETS, gaps, multi-class) --- tests/test_report.py | 138 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 tests/test_report.py diff --git a/tests/test_report.py b/tests/test_report.py new file mode 100644 index 0000000..653f783 --- /dev/null +++ b/tests/test_report.py @@ -0,0 +1,138 @@ +"""corenet-report on 2-epoch synthetic trainings (CPU): the HTML file exists, is small, holds every section, +renders the pairing accuracy when the file has TARGETS and the overtraining check when corenet-evaluate +predictions of every event exist, and lists the gaps when they do not.""" + +from __future__ import annotations + +import tempfile +from pathlib import Path + +import h5py +import numpy as np +from synthetic import write_synthetic +from test_train import BBWW, HH4B, _train + +from corenet import evaluate, report + +HEADINGS = [t for _, t in report.SECTIONS] +MAX_BYTES = 4_000_000 + + +def _add_targets(path: Path) -> None: + """TARGETS/h1/{b1,b2} and TARGETS/h2/{b1,b2}: four distinct present jet slots for signal events, -1 otherwise.""" + rng = np.random.default_rng(1) + with h5py.File(path, "a") as f: + label = f["EVENT/label"][...] + n_present = f["INPUTS/Source/MASK"][...].sum(1) + cols = {k: np.full(len(label), -1, dtype=np.int64) for k in ("h1/b1", "h1/b2", "h2/b1", "h2/b2")} + for i in np.flatnonzero(label == 1): + slots = rng.choice(int(n_present[i]), 4, replace=False) + for k, s in zip(cols, slots): + cols[k][i] = s + for k, v in cols.items(): + f.create_dataset(f"TARGETS/{k}", data=v) + + +def _evaluate_all(out_dir: Path, data: Path) -> None: + evaluate.main( + [ + "--checkpoint", + str(out_dir / "model_fold0.pkl"), + "--input", + str(data), + "--output", + str(out_dir / "eval_fold0.h5"), + "--fold", + "-1", + ] + ) + + +def _report(out_dir: Path, data: Path, *extra: str) -> str: + out = report.main( + ["--run-dir", str(out_dir), "--input", str(data), "--output", str(out_dir / "report.html"), *extra] + ) + assert out.is_file(), out + assert out.stat().st_size < MAX_BYTES, out.stat().st_size + page = out.read_text(encoding="utf-8") + for heading in HEADINGS: + assert heading in page, f"section '{heading}' missing" + assert "could not be produced" not in page, "a section failed" + assert "data:image/png;base64," in page + return page + + +def test_report_with_targets_and_all_events() -> None: + with tempfile.TemporaryDirectory() as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "hh4b_all.h5", "hh4b") + _add_targets(data) + out_dir = tmp / "run" + _train(data, out_dir) + _evaluate_all(out_dir, data) + page = _report(out_dir, data) + assert "Pairing accuracy of the argmax view of HH" in page + assert "no TARGETS" not in page + assert "no predictions on the training folds" not in page + assert "overtraining check" in page + assert "AUC of the main score" in page + assert "H1 ← b" in page and "HH context" in page and "event scalars" in page + assert "Role b (jets btag 4)" in page and "Single object" not in page + + +def test_report_without_targets_and_train_predictions() -> None: + with tempfile.TemporaryDirectory() as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "hh4b_all.h5", "hh4b") + out_dir = tmp / "run" + _train(data, out_dir) + page = _report(out_dir, data, "--max-events", "500") + assert "no TARGETS" in page + assert "no predictions on the training folds" in page + assert "random subsample" in page + + +def test_report_bbww_multiclass() -> None: + from corenet import train + + with tempfile.TemporaryDirectory() as tmp: + tmp = Path(tmp) + data = write_synthetic(tmp / "bbww_all.h5", "bbww") + out_dir = tmp / "run" + train.main( + [ + "--config", + str(BBWW), + "--input", + str(data), + "--output-dir", + str(out_dir), + "--fold", + "0", + "--exclude-folds", + "1", + "--epochs", + "2", + "--batch-size-init", + "128", + "--freeze-epoch", + "1", + "--device", + "cpu", + ] + ) + _evaluate_all(out_dir, data) + page = _report(out_dir, data) + assert "Confusion matrix" in page + assert "head ttbar" in page + assert "Weighted share of the argmax view, test folds: tt" in page + assert "Single object lepton" in page and "Single object met" in page + assert "relation lepton - met" in page + + +def test_report_needs_a_run_directory() -> None: + import pytest + + with tempfile.TemporaryDirectory() as tmp: + with pytest.raises(SystemExit): + report.main(["--run-dir", tmp, "--input", str(HH4B), "--output", str(Path(tmp) / "r.html")]) From b606c99d34ef4fd884d4ab8f1260ee59eceeb803 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:12:42 -0400 Subject: [PATCH 14/23] docs: Report.md, README Report subsection, report step in the HH4b and bbWW guides --- README.md | 29 ++++++++++++++-- docs/BBWW.md | 9 ++++- docs/HH4b.md | 14 ++++++++ docs/Report.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 docs/Report.md diff --git a/README.md b/README.md index 8c6a68f..f178464 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ pixi shell # activate; or prefix every command with `pixi pixi itself is a single static binary (`curl -fsSL https://pixi.sh/install.sh | sh`) that needs no root access, so the same commands work on a laptop and on a cluster front end. -This installs the command-line tools `corenet-validate`, `corenet-train`, `corenet-evaluate` and -`corenet-export` (each has `--help`), and the Python package `corenet`. The unit tests run with +This installs the command-line tools `corenet-validate`, `corenet-train`, `corenet-evaluate`, +`corenet-export` and `corenet-report` (each has `--help`), and the Python package `corenet`. The unit tests run with `pytest tests`. ## Dependencies @@ -35,6 +35,7 @@ This installs the command-line tools `corenet-validate`, `corenet-train`, `coren | h5py | 3.0 | input and prediction files | | PyYAML | 5.4 | configuration files | | scikit-learn | 1.0 | AUC / ROC in `corenet-evaluate` | +| matplotlib | 3.5 | figures of `corenet-report` | | onnx, onnxruntime | 1.14, 1.15 | `corenet-export` (optional extra `export`) | | pytest | 7 | tests (optional extra `test`) | @@ -62,9 +63,12 @@ corenet-evaluate --checkpoint runs/hh4b/model_fold0.pkl --input examples/data/hh # 4. export to TorchScript and ONNX, and check the exported models against PyTorch corenet-export --checkpoint runs/hh4b/model_fold0.pkl --input examples/data/hh4b_small.h5 \ --output-dir runs/hh4b/export + +# 5. one HTML page with the training curves, ROC curves, pairings and input checks of the run +corenet-report --run-dir runs/hh4b --input examples/data/hh4b_small.h5 --output runs/hh4b/report.html ``` -The same four commands with `bbww` in place of `hh4b` run the HH → bb̄WW example. +The same five commands with `bbww` in place of `hh4b` run the HH → bb̄WW example. [docs/HH4b.md](docs/HH4b.md) walks through the HH → bb̄bb̄ example step by step; [docs/BBWW.md](docs/BBWW.md) does the same for HH → bb̄WW against tt̄. @@ -222,6 +226,25 @@ and `event` (N, 2); for HH → bb̄WW `b` (N, 5, 2), `q` (N, 5, 2), `lepton` (N, | `views_` | (N, V) | probability of every pairing of a hypothesis with several pairings | | `head_` | (N,) | the extra binary score of every output after the first | +### Report + +```bash +corenet-report --run-dir runs/bbww --input examples/data/bbww_all.h5 --output runs/bbww/report.html +``` + +* `--folds 0 1`: report these folds only (default: every fold found in the run directory). +* `--max-events 500000`: events of the input file used for the input and weight distributions (random subsample above it; `0` = all). +* `--config my_config.yaml`: event description to use instead of the one stored in the checkpoint. + +To see the training and validation folds in the ROC and score figures (overtraining check), first write the +predictions of every event with `corenet-evaluate ... --output runs/bbww/eval_fold0.h5 --fold -1`. + +Output: + +| file | content | +|---|---| +| `report.html` | self-contained page: run summary, training curves, ROC / AUC / score distributions, view probabilities and pairing accuracy against `TARGETS`, the inputs as the network embeds them, the raw inputs, the event weights, and the list of what could not be produced ([docs/Report.md](docs/Report.md)) | + ```python import onnxruntime as ort from corenet import load_config diff --git a/docs/BBWW.md b/docs/BBWW.md index b10b190..ef71361 100644 --- a/docs/BBWW.md +++ b/docs/BBWW.md @@ -127,7 +127,14 @@ corenet-evaluate --checkpoint runs/bbww_full/model_fold0.pkl --input examples/da --output runs/bbww_full/eval_fold0.h5 ``` +```bash +corenet-report --run-dir runs/bbww_full --input examples/data/bbww_all.h5 --output runs/bbww_full/report.html +``` + +writes the results page of the run ([Report.md](./Report.md)). + The commands, their options and their output files are the same as in the [HH → bb̄bb̄ guide](./HH4b.md). The prediction file additionally holds `views/tt` (the two tt̄ pairings) and `heads/ttbar` (the tt̄ score), and `class_probabilities` has three columns (rest, -signal, ttbar). The exported model takes `b`, `q`, `lepton`, `met` and `event`. +signal, ttbar). The exported model takes `b`, `q`, `lepton`, `met` and `event`. The report adds the +confusion matrix of the three classes, the ROC curve of every class against the rest and of the tt̄ score. diff --git a/docs/HH4b.md b/docs/HH4b.md index 0ae191f..bc5b8fb 100644 --- a/docs/HH4b.md +++ b/docs/HH4b.md @@ -174,6 +174,20 @@ exported model takes the jets already assigned (`b`, `other`) and the event quan of the b jets has to be reproduced wherever the model is deployed; see Exporting in the [README](../README.md). +## Report + +```bash +corenet-evaluate --checkpoint runs/hh4b_full/model_fold0.pkl --input examples/data/hh4b_all.h5 \ + --output runs/hh4b_full/eval_fold0.h5 --fold -1 +corenet-report --run-dir runs/hh4b_full --input examples/data/hh4b_all.h5 --output runs/hh4b_full/report.html +``` + +writes one HTML page with the training curves, the ROC curves and AUC per fold, the signal-score +distributions on the test and training folds, the probabilities of the three pairings and their +accuracy against `TARGETS`, the inputs as the network embeds them, the raw inputs and the event weights +([Report.md](./Report.md)). The first command is optional: it gives the training and validation folds +their own curves. + ## Changing things | to change | where | example | diff --git a/docs/Report.md b/docs/Report.md new file mode 100644 index 0000000..194b3d1 --- /dev/null +++ b/docs/Report.md @@ -0,0 +1,90 @@ +# Results Report + +`corenet-report` writes one HTML file with the results of a training and the checks of its inputs. The +page holds every figure and table itself and opens in any browser, offline. + +## Running + +1. Train (`corenet-train`) and, to also see the training and validation folds in the report, evaluate every + event of the file into the same directory: + + ```bash + corenet-evaluate --checkpoint runs/hh4b/model_fold0.pkl --input examples/data/hh4b_all.h5 \ + --output runs/hh4b/eval_fold0.h5 --fold -1 + ``` + +2. Write the report: + + ```bash + corenet-report --run-dir runs/hh4b --input examples/data/hh4b_all.h5 --output runs/hh4b/report.html + ``` + +* `--run-dir runs/hh4b`: the directory written by `corenet-train` (and `corenet-evaluate`). +* `--input examples/data/hh4b_all.h5`: the file the run was trained on. +* `--output runs/hh4b/report.html`: the page to write (default: `report.html` in the run directory). +* `--folds 0 1`: report these folds only (default: every fold found in the directory). +* `--config my_config.yaml`: use this event description instead of the one stored in the checkpoint. +* `--max-events 500000`: at most this many events of the input file for the input and weight + distributions, a random subsample above it; `0` uses every event. +* `--n-folds 5`, `--fold-seed 0`, `--rest-order pt`: the fold rule and the ordering of `rest` jets + (default: as recorded in the run). + +On a machine without a GPU, prefix the command with `CONDA_OVERRIDE_CUDA=12.0`; the report runs on the CPU. + +## Input files + +Per fold `k`, in `--run-dir`: + +| file | content | needed for | +|---|---|---| +| `history_fold{k}.json` | training settings and per-epoch history | run summary, training curves | +| `model_fold{k}.pkl` | checkpoint | event description, parameter count, the inputs as the network sees them | +| `predictions_fold{k}.h5` | predictions on the held-out fold | ROC, AUC, scores, view probabilities, pairing accuracy | +| `eval_fold{k}.h5` | `corenet-evaluate` output; with `--fold -1` every event of the file | the training and validation folds in the ROC, AUC and score figures (overtraining check) | + +A fold with some of these files missing is reported with what is there; the last section of the page lists +what could not be produced and why. + +## Output + +| file | content | +|---|---| +| `report.html` | the page, figures embedded as PNG | + +## Sections of the page + +1. **Run summary**: the event description (collapsed), the input file, the classes and their event counts + and weights, the training settings, and per fold the validation folds, the events of the training, + validation and test sets, the epochs run, the best epoch, the parameter count and which prediction + files were found. +2. **Training curves**: training loss, validation loss and validation AUC per epoch, one line per fold, + the best epoch marked; the values of the last epoch in a table. +3. **Classification**: the ROC curve of the signal score (signal against every other class) per fold and + the mean over folds with its spread, on a linear and a logarithmic background-efficiency axis; the AUC + per fold and split with mean ± sd; the signal-score distributions of every class on the test folds, + overlaid with the training folds when `eval_fold{k}.h5` holds them; for more than two classes the + confusion matrix at the most probable class, the ROC curve of every class against the rest, and the + ROC curve of every auxiliary score (`heads/`). +4. **Hypotheses and pairing**: for every hypothesis with several candidate assignments (for HH → bb̄bb̄ the + three pairings of the four b jets into two Higgs bosons), the distribution of the highest view + probability per class and the share of each assignment; when the input file has `TARGETS` naming the + generator-matched jets of a particle of the decay chain (`TARGETS/h1/{b1,b2}`, `TARGETS/h2/{b1,b2}`), + the fraction of events in which the most probable assignment is the generator one, per fold, for the + events whose matched jets are all among the candidates, and the same fraction as a function of the + view probability. +5. **Inputs as the network sees them**: the quantities the network embeds, per class: for every decay + product of every particle its log(1+pT), η, Δφ to the parent candidate and log(1+m) (plus any further + feature, e.g. `isE`, `isM`), for every particle candidate its own kinematics, the jets of the `context`, + the `relations` pairs (log(1+M), ΔR, Δφ) and the event scalars (`nSelJets` as log(nSelJets − (min_jets − 1))). +6. **Raw inputs**: the columns of the input file for the jets each role selected, slot by slot (including a + column read for the selection only, such as `btag`), the single objects and the event scalars, per class. +7. **Weights**: the event weights per class as stored and as the training uses them (clipped at 0, every + class summing to 1), weight statistics with the effective number of events and the negative weights, the + events and weights per fold and class, and the training set of every fold. +8. **Other checks**: the mean event weight as a function of the leading and the last candidate jet pT and + of the jet multiplicity, per class. +9. **Not produced**: everything the run did not provide (no `TARGETS`, no predictions on the training + folds, no history, ...) and the reason. + +Weighted distributions use the event weights of the file clipped at 0, as the training does; each class is +normalised to unit area. Mean ± sd are over folds. From 489834f4f8563eac03528eeb2fb39f1806a28533 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:13:32 -0400 Subject: [PATCH 15/23] report: compare interchangeable sibling nodes (H1/H2) as a set in the pairing accuracy --- src/corenet/report.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/corenet/report.py b/src/corenet/report.py index ff35c6b..be401ca 100644 --- a/src/corenet/report.py +++ b/src/corenet/report.py @@ -847,15 +847,17 @@ def _pairing_accuracy(self, test, hyps) -> str: self.gaps.append(f"pairing accuracy of {h}: no TARGETS group named like one of its nodes ({sorted(declared)}; TARGETS has {sorted(targets)})") parts.append(note(f"{h}: no TARGETS group matches a node of the hypothesis ({', '.join(sorted(declared))}); TARGETS groups: {', '.join(sorted(targets))}.")) continue - # truth: per matched node the sorted file slots of its generator-matched jets, and which roles it uses + # per matched node: the sorted file slots of its generator-matched jets (truth) and of its + # candidate under every view; sibling nodes that are interchangeable (H1 / H2) are compared as + # a set, so that swapping them does not count as a wrong assignment n = len(self.ds) correct = np.ones((V, n), bool) complete = np.ones(n, bool) contained = np.ones(n, bool) usable = [] + truth_of, views_of = {}, {} for g, node in matched.items(): truth = np.stack(list(targets[g].values()), 1) # (n, k) file slots - truth_sorted = np.sort(truth, 1) assignments = [self._view_assignments(h, v).get(node) for v in range(V)] pairs = [[(r, s) for r, s in a if r in sel] if a is not None else None for a in assignments] if any(p is None or len(p) != truth.shape[1] for p in pairs): @@ -866,9 +868,30 @@ def _pairing_accuracy(self, test, hyps) -> str: pool = np.concatenate([sel[r] for r in roles], 1) # (n, slots) file slots of the roles for col in range(truth.shape[1]): contained &= (pool == truth[:, col : col + 1]).any(1) - for v, p in enumerate(pairs): - view_slots = np.sort(np.stack([sel[r][:, slot] for r, slot in p], 1), 1) - correct[v] &= (view_slots == truth_sorted).all(1) + truth_of[node] = np.sort(truth, 1) + views_of[node] = [np.sort(np.stack([sel[r][:, slot] for r, slot in p], 1), 1) for p in pairs] + # groups of interchangeable siblings that are all matched + grouped, groups = set(), [] + for parent in declared: + nt = T.nodes.get(T.aliases.get(parent, parent)) + kids = self.spec.nodes[parent].children if parent in self.spec.nodes else [] + if nt is not None and nt.symmetric_children and len(kids) > 1 and all(k in truth_of for k in kids): + groups.append(list(kids)) + grouped.update(kids) + + def key(slots): # one integer per sorted slot tuple + base = 1 << 16 + return sum((slots[:, j].astype(np.int64) + 1) * base**j for j in range(slots.shape[1])) + + for node in truth_of: + if node in grouped: + continue + for v in range(V): + correct[v] &= (views_of[node][v] == truth_of[node]).all(1) + for kids in groups: + t = np.sort(np.stack([key(truth_of[k]) for k in kids], 1), 1) + for v in range(V): + correct[v] &= (np.sort(np.stack([key(views_of[k][v]) for k in kids], 1), 1) == t).all(1) if not usable: parts.append(note(f"{h}: the matched TARGETS groups ({', '.join(matched)}) list a different number of jets than the nodes they name.")) continue From 6d4542a4f307a86f1e96d3539092462035287175 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:24:02 -0400 Subject: [PATCH 16/23] pixi.lock: re-solved after adding matplotlib-base (job 49597275) --- pixi.lock | 1023 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 994 insertions(+), 29 deletions(-) diff --git a/pixi.lock b/pixi.lock index b4bde6c..67d99ab 100644 --- a/pixi.lock +++ b/pixi.lock @@ -26,8 +26,12 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/aws-c-s3-0.13.1-h7508075_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/aws-c-sdkutils-0.2.7-h01ee8f8_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/aws-checksums-0.2.10-h01ee8f8_5.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-1.2.1-h505cf86_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-bin-1.2.1-h9908984_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hda65f42_10.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.34.8-hebe6cf0_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/cairo-1.18.6-h3c89d7e_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/contourpy-1.4.0-py313h2551ef2_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-crt-tools-12.9.86-ha770c72_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-cudart-12.9.79-h5888daf_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-cuobjdump-12.9.82-hffce074_1.conda @@ -39,16 +43,28 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-nvvm-tools-12.9.86-h4bc722e_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cudnn-9.10.2.21-hbcb9cd8_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/fmt-12.1.0-h76c4fd7_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/fontconfig-2.18.3-h4db4eae_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/fonttools-4.67.0-py313h6cd9899_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/freetype-2.14.3-ha770c72_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/fribidi-1.0.17-h7cc23a3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/gmp-6.3.0-hfd2156b_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/gmpy2-2.3.2-py313ha4a6282_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/graphite2-1.3.15-h54a6638_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/h5py-3.16.0-nompi_py313hce4e9db_105.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/hdf5-2.2.0-nompi_hc529623_100.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/icu-78.3-py310h44b86e0_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.3-h7cc23a3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/kiwisolver-1.5.1-py313h2551ef2_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/krb5-1.22.2-hbc21106_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/lcms2-2.19.1-h9073bf1_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.46.1-default_hbd61a6d_102.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/lerc-4.2.0-hdb68285_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libabseil-20260526.0-cxx17_h0dc7533_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libaec-1.1.5-h088129d_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libblas-3.11.0-11_h5875eb1_mkl.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlicommon-1.2.1-h39a168f_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlidec-1.2.1-ha411449_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlienc-1.2.1-h018ffa1_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcap-2.78-h084b8d7_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.11.0-11_hfef963f_mkl.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcublas-12.9.2.10-h676940d_0.conda @@ -61,15 +77,22 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/libcurl-8.21.0-hcf29cc6_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcusolver-11.7.5.82-h676940d_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcusparse-12.5.10.65-hecca717_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libdeflate-1.25-hd45a770_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20260512-pl5321h373387f_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libev-4.33-h280c20c_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.8.5-hd2095e1_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libffi-3.7.0-h81df57d_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libfreetype-2.14.3-ha770c72_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libfreetype6-2.14.3-h5e6c136_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-16.2.0-ha9f2e26_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-16.2.0-h69a702a_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-16.2.0-h69a702a_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-16.2.0-h6b99dfc_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libglib-2.90.0-h569388d_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libharfbuzz-14.6.0-h23af247_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libhwloc-2.15.0-default_hd7c4d0c_1001.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libiconv-1.18-h0cb94f2_3.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libjpeg-turbo-3.2.0-hb03c661_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.11.0-11_h5e43f62_mkl.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/liblzma-5.8.3-hb03c661_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libmagma-2.10.0-ha7672b3_0.conda @@ -78,21 +101,28 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/libnl-3.11.0-hb03c661_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libnvjitlink-12.9.86-hecca717_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libonnx-1.23.2-hd8ccbc4_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libpng-1.6.59-h922cc85_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libprotobuf-7.35.1-h622638d_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libpython-3.13.16-hdc7f604_101_cp313.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.53.4-h0737f62_103.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libraqm-0.11.0-h6406941_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.54.1-h13e7031_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.1-h6154650_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-16.2.0-h934c35e_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-16.2.0-hdf11a46_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libsystemd0-262-h26e0ef7_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libtiff-4.7.2-hcc2c06a_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libtorch-2.13.0-cuda129_mkl_h546cc0b_304.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libudev1-262-h26e0ef7_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.42.4-hcfc3c73_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libuv-1.52.1-h280c20c_1.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-16-2.15.4-hbdfff7e_0.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.15.4-ha7a5771_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libwebp-base-1.6.0-hd42ef1d_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxcb-1.17.0-hb83e432_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-16-2.15.4-hf3af7cc_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.15.4-h7df9aa5_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.2-h25fd6f3_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/llvm-openmp-23.1.3-h7148c6a_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/markupsafe-3.0.4-py313h6cd9899_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/matplotlib-base-3.11.2-py313he85fb2c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/mkl-2026.1.0-hd2095e1_245.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/ml_dtypes-0.5.4-np2py313h38606b7_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/mpc-1.4.0-ha2cb11d_1.conda @@ -103,13 +133,19 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/onednn-3.13.3-omp_h64ed1e9_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/onnx-1.23.2-py313hf19c63c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/onnxruntime-1.30.0-py313h77ceba0_202_cuda129.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/openjpeg-2.5.4-heb1ab33_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/openssl-3.6.5-h781a0a9_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/optree-0.20.0-py313h6bdb861_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pcre2-10.47-h8b3dc9c_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pillow-13.0.0-py313h3b26573_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pixman-0.46.4-h54a6638_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/protobuf-7.35.1-py313hf4667e8_3.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-h7cc23a3_1004.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.13.16-hf47f18c_101_cp313.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pytorch-2.13.0-cuda129_mkl_py313_h571fb29_304.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pytorch-gpu-2.13.0-cuda129_mkl_h0d04637_304.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pyyaml-6.0.3-py313h3dea7bd_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/qhull-2020.2-h434a139_5.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rdma-core-65.0-h7b4f2e6_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/readline-8.3-hd6e31c0_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/s2n-1.7.6-h7e3ee7f_0.conda @@ -119,7 +155,15 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/tbb-2023.1.0-haa8c3ee_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h1df4ec4_4.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/triton-3.7.1-cuda129py313h246eb7c_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libice-1.1.2-h280c20c_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libsm-1.2.6-h0d788c3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libx11-1.8.14-hb83e432_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxau-1.0.12-h7cc23a3_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxdmcp-1.1.5-h7cc23a3_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxext-1.3.7-h7cc23a3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrender-0.9.13-h7cc23a3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/yaml-0.2.5-hebe6cf0_3.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/zlib-ng-2.3.3-hce19668_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.7-hb78ec9c_7.conda - conda: https://conda.anaconda.org/conda-forge/noarch/ca-certificates-2026.7.22-hbd8a1cb_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cached-property-2.0.1-pyhcf101f3_0.conda @@ -129,13 +173,21 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/cpython-3.13.16-py313hd8ed1ab_101.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cuda-cudart_linux-64-12.9.79-h3f2d84a_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cuda-version-12.9-h4f385c5_3.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/cycler-0.12.1-pyhcf101f3_2.conda - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-4.0.12-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-dejavu-sans-mono-2.37-hab24e00_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-inconsolata-3.000-h77eed37_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-source-code-pro-2.038-h77eed37_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-ubuntu-0.83-h77eed37_3.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/fonts-conda-ecosystem-1-0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/fonts-conda-forge-1-hc364b38_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fsspec-2026.9.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/joblib-1.6.0-pyhcf101f3_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/mpmath-1.4.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/munkres-1.1.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/narwhals-2.27.0-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/networkx-3.7-pyhc364b38_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda @@ -145,10 +197,14 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-11-hc364b38_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pybind11-global-3.0.4-pyh648e204_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pyparsing-3.3.3-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytest-9.1.1-pyhc364b38_2.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-3.0.0-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-flatbuffers-25.12.19-pyh9d96877_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2026.5-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python_abi-3.13-9_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.17.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sympy-1.14.0-pyh2585a3b_106.conda - conda: https://conda.anaconda.org/conda-forge/noarch/threadpoolctl-3.7.0-pyhc455866_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.4.1-pyhcf101f3_0.conda @@ -173,8 +229,12 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/aws-c-s3-0.13.1-h7508075_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/aws-c-sdkutils-0.2.7-h01ee8f8_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/aws-checksums-0.2.10-h01ee8f8_5.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-1.2.1-h505cf86_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-bin-1.2.1-h9908984_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hda65f42_10.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.34.8-hebe6cf0_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/cairo-1.18.6-h3c89d7e_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/contourpy-1.4.0-py313h2551ef2_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-crt-tools-12.9.86-ha770c72_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-cudart-12.9.79-h5888daf_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-cuobjdump-12.9.82-hffce074_1.conda @@ -186,16 +246,28 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-nvvm-tools-12.9.86-h4bc722e_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cudnn-9.10.2.21-hbcb9cd8_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/fmt-12.1.0-h76c4fd7_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/fontconfig-2.18.3-h4db4eae_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/fonttools-4.67.0-py313h6cd9899_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/freetype-2.14.3-ha770c72_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/fribidi-1.0.17-h7cc23a3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/gmp-6.3.0-hfd2156b_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/gmpy2-2.3.2-py313ha4a6282_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/graphite2-1.3.15-h54a6638_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/h5py-3.16.0-nompi_py313hce4e9db_105.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/hdf5-2.2.0-nompi_hc529623_100.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/icu-78.3-py310h44b86e0_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.3-h7cc23a3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/kiwisolver-1.5.1-py313h2551ef2_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/krb5-1.22.2-hbc21106_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/lcms2-2.19.1-h9073bf1_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.46.1-default_hbd61a6d_102.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/lerc-4.2.0-hdb68285_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libabseil-20260526.0-cxx17_h0dc7533_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libaec-1.1.5-h088129d_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libblas-3.11.0-11_h5875eb1_mkl.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlicommon-1.2.1-h39a168f_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlidec-1.2.1-ha411449_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlienc-1.2.1-h018ffa1_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcap-2.78-h084b8d7_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.11.0-11_hfef963f_mkl.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcublas-12.9.2.10-h676940d_0.conda @@ -208,15 +280,22 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/libcurl-8.21.0-hcf29cc6_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcusolver-11.7.5.82-h676940d_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libcusparse-12.5.10.65-hecca717_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libdeflate-1.25-hd45a770_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20260512-pl5321h373387f_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libev-4.33-h280c20c_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.8.5-hd2095e1_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libffi-3.7.0-h81df57d_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libfreetype-2.14.3-ha770c72_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libfreetype6-2.14.3-h5e6c136_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-16.2.0-ha9f2e26_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-16.2.0-h69a702a_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-16.2.0-h69a702a_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-16.2.0-h6b99dfc_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libglib-2.90.0-h569388d_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libharfbuzz-14.6.0-h23af247_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libhwloc-2.15.0-default_hd7c4d0c_1001.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libiconv-1.18-h0cb94f2_3.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libjpeg-turbo-3.2.0-hb03c661_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.11.0-11_h5e43f62_mkl.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/liblzma-5.8.3-hb03c661_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libmagma-2.10.0-ha7672b3_0.conda @@ -225,21 +304,28 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/libnl-3.11.0-hb03c661_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libnvjitlink-12.9.86-hecca717_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libonnx-1.23.2-hd8ccbc4_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libpng-1.6.59-h922cc85_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libprotobuf-7.35.1-h622638d_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libpython-3.13.16-hdc7f604_101_cp313.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.53.4-h0737f62_103.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libraqm-0.11.0-h6406941_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.54.1-h13e7031_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.1-h6154650_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-16.2.0-h934c35e_7.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-16.2.0-hdf11a46_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libsystemd0-262-h26e0ef7_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libtiff-4.7.2-hcc2c06a_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libtorch-2.13.0-cuda129_mkl_h546cc0b_304.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libudev1-262-h26e0ef7_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.42.4-hcfc3c73_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libuv-1.52.1-h280c20c_1.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-16-2.15.4-hbdfff7e_0.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.15.4-ha7a5771_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libwebp-base-1.6.0-hd42ef1d_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxcb-1.17.0-hb83e432_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-16-2.15.4-hf3af7cc_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.15.4-h7df9aa5_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.2-h25fd6f3_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/llvm-openmp-23.1.3-h7148c6a_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/markupsafe-3.0.4-py313h6cd9899_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/matplotlib-base-3.11.2-py313he85fb2c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/mkl-2026.1.0-hd2095e1_245.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/ml_dtypes-0.5.4-np2py313h38606b7_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/mpc-1.4.0-ha2cb11d_1.conda @@ -250,13 +336,19 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/onednn-3.13.3-omp_h64ed1e9_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/onnx-1.23.2-py313hf19c63c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/onnxruntime-1.30.0-py313h77ceba0_202_cuda129.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/openjpeg-2.5.4-heb1ab33_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/openssl-3.6.5-h781a0a9_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/optree-0.20.0-py313h6bdb861_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pcre2-10.47-h8b3dc9c_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pillow-13.0.0-py313h3b26573_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pixman-0.46.4-h54a6638_3.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/protobuf-7.35.1-py313hf4667e8_3.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-h7cc23a3_1004.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.13.16-hf47f18c_101_cp313.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pytorch-2.13.0-cuda129_mkl_py313_h571fb29_304.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pytorch-gpu-2.13.0-cuda129_mkl_h0d04637_304.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pyyaml-6.0.3-py313h3dea7bd_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/qhull-2020.2-h434a139_5.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/rdma-core-65.0-h7b4f2e6_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/readline-8.3-hd6e31c0_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/s2n-1.7.6-h7e3ee7f_0.conda @@ -266,7 +358,15 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/tbb-2023.1.0-haa8c3ee_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h1df4ec4_4.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/triton-3.7.1-cuda129py313h246eb7c_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libice-1.1.2-h280c20c_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libsm-1.2.6-h0d788c3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libx11-1.8.14-hb83e432_0.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxau-1.0.12-h7cc23a3_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxdmcp-1.1.5-h7cc23a3_2.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxext-1.3.7-h7cc23a3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrender-0.9.13-h7cc23a3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/yaml-0.2.5-hebe6cf0_3.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/zlib-ng-2.3.3-hce19668_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.7-hb78ec9c_7.conda - conda: https://conda.anaconda.org/conda-forge/noarch/ca-certificates-2026.7.22-hbd8a1cb_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cached-property-2.0.1-pyhcf101f3_0.conda @@ -276,13 +376,21 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/cpython-3.13.16-py313hd8ed1ab_101.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cuda-cudart_linux-64-12.9.79-h3f2d84a_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cuda-version-12.9-h4f385c5_3.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/cycler-0.12.1-pyhcf101f3_2.conda - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-4.0.12-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-dejavu-sans-mono-2.37-hab24e00_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-inconsolata-3.000-h77eed37_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-source-code-pro-2.038-h77eed37_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-ubuntu-0.83-h77eed37_3.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/fonts-conda-ecosystem-1-0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/fonts-conda-forge-1-hc364b38_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fsspec-2026.9.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.6-pyhcf101f3_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/joblib-1.6.0-pyhcf101f3_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/mpmath-1.4.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/munkres-1.1.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/narwhals-2.27.0-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/networkx-3.7-pyhc364b38_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda @@ -292,10 +400,14 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-11-hc364b38_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pybind11-global-3.0.4-pyh648e204_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pyparsing-3.3.3-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytest-9.1.1-pyhc364b38_2.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-3.0.0-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-flatbuffers-25.12.19-pyh9d96877_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2026.5-pyh5ded981_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python_abi-3.13-9_cp313.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.17.0-pyhe01879c_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sympy-1.14.0-pyh2585a3b_106.conda - conda: https://conda.anaconda.org/conda-forge/noarch/threadpoolctl-3.7.0-pyhc455866_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tomli-2.4.1-pyhcf101f3_0.conda @@ -468,6 +580,37 @@ packages: - aws-checksums >=0.2.10,<0.2.11.0a0 size: 101887 timestamp: 1785159213897 +- conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-1.2.1-h505cf86_0.conda + sha256: 3efb8e6ac07f12773f02e876567700f554965e33a8e30ee05ddd891c303f7aa3 + md5: 65f1fc5f6a3a984a8a25641d0e60fc25 + depends: + - __glibc >=2.17,<3.0.a0 + - brotli-bin 1.2.1 h9908984_0 + - libbrotlidec 1.2.1 ha411449_0 + - libbrotlienc 1.2.1 h018ffa1_0 + - libgcc >=15 + license: MIT + purls: [] + run_exports: + weak: + - libbrotlicommon >=1.2.1,<1.3.0a0 + - libbrotlienc >=1.2.1,<1.3.0a0 + - libbrotlidec >=1.2.1,<1.3.0a0 + size: 20477 + timestamp: 1792653712185 +- conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-bin-1.2.1-h9908984_0.conda + sha256: c64939f0ade0fea29525d2f549a700841a331c0886b3694083d08eb4769936ce + md5: 903eceb31743f0ce070abb9b9f879714 + depends: + - __glibc >=2.17,<3.0.a0 + - libbrotlidec 1.2.1 ha411449_0 + - libbrotlienc 1.2.1 h018ffa1_0 + - libgcc >=15 + license: MIT + purls: [] + run_exports: {} + size: 21494 + timestamp: 1792653706181 - conda: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hda65f42_10.conda sha256: 1a0d382c515ebf55f8ee1f38c8b81bc95af5c2acc42ad53b66bc5df932032f96 md5: e675fabcf81499adc7edf58124fb1e01 @@ -496,6 +639,53 @@ packages: - c-ares >=1.34.8,<2.0a0 size: 228700 timestamp: 1787169971173 +- conda: https://conda.anaconda.org/conda-forge/linux-64/cairo-1.18.6-h3c89d7e_0.conda + sha256: 5d0efc6f9981468aca72897460d9b2d17b74dff72787f20a9d2330e214064515 + md5: 7920701f9abcb488411495742cf365a7 + depends: + - __glibc >=2.17,<3.0.a0 + - fontconfig >=2.18.3,<3.0a0 + - fonts-conda-ecosystem + - icu >=78.3,<79.0a0 + - libexpat >=2.8.1,<3.0a0 + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + - libgcc >=15 + - libglib >=2.90.0,<3.0a0 + - libpng >=1.6.58,<1.7.0a0 + - libstdcxx >=15 + - libxcb >=1.17.0,<2.0a0 + - libzlib >=1.3.2,<2.0a0 + - pixman >=0.46.4,<1.0a0 + - xorg-libice >=1.1.2,<2.0a0 + - xorg-libsm >=1.2.6,<2.0a0 + - xorg-libx11 >=1.8.13,<2.0a0 + - xorg-libxext >=1.3.7,<2.0a0 + - xorg-libxrender >=0.9.12,<0.10.0a0 + license: LGPL-2.1-only or MPL-1.1 + purls: [] + run_exports: + weak: + - cairo >=1.18.6,<2.0a0 + size: 1007110 + timestamp: 1790045358757 +- conda: https://conda.anaconda.org/conda-forge/linux-64/contourpy-1.4.0-py313h2551ef2_1.conda + sha256: 078f4a0f83ee7d0f88c110e15f9f94ff4080dc925711d1d22b52779c2e48cf87 + md5: 1883f23b947ffaa13f9511ea817fc4e6 + depends: + - numpy >=2.0 + - python + - __glibc >=2.17,<3.0.a0 + - libstdcxx >=15 + - libgcc >=15 + - python_abi 3.13.* *_cp313 + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/contourpy?source=compressed-mapping + run_exports: {} + size: 329540 + timestamp: 1789746824998 - conda: https://conda.anaconda.org/conda-forge/linux-64/cuda-crt-tools-12.9.86-ha770c72_2.conda sha256: 2da9964591af14ba11b2379bed01d56e7185260ee0998d1a939add7fb752db45 md5: 503a94e20d2690d534d676a764a1852c @@ -648,6 +838,70 @@ packages: - fmt >=12.1.0,<12.2.0a0 size: 199072 timestamp: 1785915412102 +- conda: https://conda.anaconda.org/conda-forge/linux-64/fontconfig-2.18.3-h4db4eae_1.conda + sha256: 5a3eb10b18a97223ab06b3a7f0d7f56658db2f2800e2f2af95836fe3bf55ba63 + md5: 922776b528a470ab5afa81fd42abfa1d + depends: + - __glibc >=2.17,<3.0.a0 + - libexpat >=2.8.1,<3.0a0 + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + - libgcc >=15 + - libuuid >=2.42.2,<3.0a0 + - libzlib >=1.3.2,<2.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - fontconfig >=2.18.3,<3.0a0 + - fonts-conda-ecosystem + size: 296288 + timestamp: 1786667377340 +- conda: https://conda.anaconda.org/conda-forge/linux-64/fonttools-4.67.0-py313h6cd9899_1.conda + sha256: b81de60784d902b27da442aacf9bf8f059b0aa778178a7d453bc654c43457ec1 + md5: dd719c40c297d87fe93085248d2ff07b + depends: + - __glibc >=2.17,<3.0.a0 + - brotli + - libgcc >=15 + - munkres + - python >=3.13,<3.14.0a0 + - python_abi 3.13.* *_cp313 + license: MIT + license_family: MIT + purls: + - pkg:pypi/fonttools?source=compressed-mapping + run_exports: {} + size: 3161654 + timestamp: 1792672552740 +- conda: https://conda.anaconda.org/conda-forge/linux-64/freetype-2.14.3-ha770c72_2.conda + sha256: 612a8e0c1a6ecae23da54d81ef395f6ebb5c8e4468ec2611593ebce75876a4e0 + md5: 2d0ea23b23603e07ca47f23f949f67b6 + depends: + - libfreetype 2.14.3 ha770c72_2 + - libfreetype6 2.14.3 h5e6c136_2 + license: GPL-2.0-only OR FTL + purls: [] + run_exports: + weak: + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + size: 175239 + timestamp: 1786641011029 +- conda: https://conda.anaconda.org/conda-forge/linux-64/fribidi-1.0.17-h7cc23a3_0.conda + sha256: 3ba79ebfbd14ca5db4affaf10ee8001064e907de5baabc2dbe5bcd9aec856c9f + md5: f9d5302bca196ee87e62f393f2626562 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + license: LGPL-2.1-or-later + purls: [] + run_exports: + weak: + - fribidi >=1.0.17,<2.0a0 + size: 64102 + timestamp: 1790011855888 - conda: https://conda.anaconda.org/conda-forge/linux-64/gmp-6.3.0-hfd2156b_3.conda sha256: f36c336efc874f346a53a9011f67e997f9faac505562cc18c13b6d399cfe61c7 md5: 576e32739f323438bf69ab006c21be7b @@ -680,6 +934,21 @@ packages: run_exports: {} size: 327168 timestamp: 1791166953052 +- conda: https://conda.anaconda.org/conda-forge/linux-64/graphite2-1.3.15-h54a6638_1.conda + sha256: 7fa3b6a9c081fa3e545573152a788d061a0a0ba57df7251cc0f4f75225fc93e7 + md5: f9fe2984587fa8235a6af6004760cd18 + depends: + - __glibc >=2.17,<3.0.a0 + - libstdcxx >=14 + - libgcc >=14 + license: LGPL-2.0-or-later + license_family: LGPL + purls: [] + run_exports: + weak: + - graphite2 >=1.3.15,<2.0a0 + size: 102835 + timestamp: 1786118485753 - conda: https://conda.anaconda.org/conda-forge/linux-64/h5py-3.16.0-nompi_py313hce4e9db_105.conda sha256: 9cbf3ffbf85a46abefed6b8127a738db9e7407fb3020aa7fdeeb75f66930d43d md5: 6b2d14128466dceabd35a3df2abe1aac @@ -725,6 +994,21 @@ packages: - hdf5 >=2.2.0,<3.0a0 size: 4250161 timestamp: 1786233343747 +- conda: https://conda.anaconda.org/conda-forge/linux-64/icu-78.3-py310h44b86e0_2.conda + sha256: 9f07834f0c546ab14d885ce0366285f61f44e326c0edd1fc63b8294e113ae432 + md5: 72a381cbad04f24b1c2a43ef707f45b4 + depends: + - __glibc >=2.17,<3.0.a0 + - libstdcxx >=14 + - libgcc >=14 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - icu >=78.3,<79.0a0 + size: 14459115 + timestamp: 1786545741408 - conda: https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.3-h7cc23a3_1.conda sha256: dd053c96dcb0dcfd59422aefea9d2fe937a190167f34fba7893ec1e10a7e8963 md5: ba55d1b89fd7775e67de8291029b4059 @@ -738,6 +1022,22 @@ packages: - keyutils >=1.6.3,<2.0a0 size: 135295 timestamp: 1786739238128 +- conda: https://conda.anaconda.org/conda-forge/linux-64/kiwisolver-1.5.1-py313h2551ef2_3.conda + sha256: bb5beb208c8379eee9b3ce620684ac44ae73597ae0dab500c12f18e63e3c1020 + md5: 45c8698dd577ba504513001219cfd0fd + depends: + - python + - libstdcxx >=15 + - libgcc >=15 + - __glibc >=2.17,<3.0.a0 + - python_abi 3.13.* *_cp313 + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/kiwisolver?source=compressed-mapping + run_exports: {} + size: 75111 + timestamp: 1790082004004 - conda: https://conda.anaconda.org/conda-forge/linux-64/krb5-1.22.2-hbc21106_2.conda sha256: 2a5c38c85e63df84c4e69ee71439841ce570d259ae3060627bb9a49a938d66f4 md5: 53318d715316929a574f83591308b1f8 @@ -757,6 +1057,22 @@ packages: - krb5 >=1.22.2,<1.23.0a0 size: 1394333 timestamp: 1786762112514 +- conda: https://conda.anaconda.org/conda-forge/linux-64/lcms2-2.19.1-h9073bf1_3.conda + sha256: 03e675b9adaf235aab880e4133c72f4830e87bc7da2df59d6194771612239b22 + md5: 596464faa06e0b656b35416188ef9bba + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - libjpeg-turbo >=3.2.0,<4.0a0 + - libtiff >=4.7.2,<4.8.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - lcms2 >=2.19.1,<3.0a0 + size: 254292 + timestamp: 1789051947923 - conda: https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.46.1-default_hbd61a6d_102.conda sha256: 27d83f1188cd19bcb7754a078b3fa7f4cfb8527f8eb2fde54dd01fc529d1adec md5: 449500f2c089da11c40f5c21312e3e07 @@ -771,6 +1087,21 @@ packages: run_exports: {} size: 745303 timestamp: 1784214507189 +- conda: https://conda.anaconda.org/conda-forge/linux-64/lerc-4.2.0-hdb68285_0.conda + sha256: bf9fdebf55d8bc99d83531cdffda00703f4dc5f93a1a956768c147362c72feda + md5: fb9d356b1a57d6d54768be7ebd5fce09 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=14 + - libstdcxx >=14 + license: Apache-2.0 + license_family: Apache + purls: [] + run_exports: + weak: + - lerc >=4.2.0,<5.0a0 + size: 271158 + timestamp: 1785036167977 - conda: https://conda.anaconda.org/conda-forge/linux-64/libabseil-20260526.0-cxx17_h0dc7533_2.conda sha256: 7bb3d495411b7059e85225aae500d84e7846a4bb02ebd77e4450200b20c180f0 md5: 6983bfe8e09992014b9cf393769c7a84 @@ -827,6 +1158,47 @@ packages: - libblas >=3.11.0,<4.0a0 size: 18622 timestamp: 1789061051585 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlicommon-1.2.1-h39a168f_0.conda + sha256: 8eccfbfdb8ecba32eabfb6ee92f70e818e5f3a35a01c507f7b6bd56e00e4c617 + md5: 9460bdde20bcdf9e6bbef0232b14ad2d + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + license: MIT + purls: [] + run_exports: + weak: + - libbrotlicommon >=1.2.1,<1.3.0a0 + size: 80370 + timestamp: 1792653685570 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlidec-1.2.1-ha411449_0.conda + sha256: 4b4bda6f70ad511bdff95fdd958dca74b6e0534ae335ddcb1d8c6569774d2429 + md5: 6d934e235f4d452ebec720ec7c3638a6 + depends: + - __glibc >=2.17,<3.0.a0 + - libbrotlicommon 1.2.1 h39a168f_0 + - libgcc >=15 + license: MIT + purls: [] + run_exports: + weak: + - libbrotlidec >=1.2.1,<1.3.0a0 + size: 34703 + timestamp: 1792653694124 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libbrotlienc-1.2.1-h018ffa1_0.conda + sha256: 61974cf9bb07115ed6725dacf83d0d985443d78dd123cc4f2758856fda5376ec + md5: 8f3078564b4a4cd9602ebaafe78e0b87 + depends: + - __glibc >=2.17,<3.0.a0 + - libbrotlicommon 1.2.1 h39a168f_0 + - libgcc >=15 + license: MIT + purls: [] + run_exports: + weak: + - libbrotlienc >=1.2.1,<1.3.0a0 + size: 298098 + timestamp: 1792653699767 - conda: https://conda.anaconda.org/conda-forge/linux-64/libcap-2.78-h084b8d7_1.conda sha256: 8cb25174d6b6fac95d31e86cfe41faffc8ee9dacbf2bfd22e6c23377e8f338c1 md5: 5db514adf5f843126ff846d1510f22a4 @@ -1020,6 +1392,20 @@ packages: run_exports: {} size: 208846028 timestamp: 1761069913328 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libdeflate-1.25-hd45a770_1.conda + sha256: 82e134c8a08b1eed9a2ed8ab578b89aa1730dcde3dea8dd87645ed0637878e54 + md5: 40f9b31aa9cf007789867df0decd0492 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=14 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - libdeflate >=1.25,<1.26.0a0 + size: 73710 + timestamp: 1785908694612 - conda: https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20260512-pl5321h373387f_0.conda sha256: 45301f14f4eb66da57cfaf2d265f3eeee73f8b07e99614ee3afc5b26eea91126 md5: 27dbd7e2984b8fe48e069379636ccfdd @@ -1077,6 +1463,31 @@ packages: - libffi >=3.7.0,<3.8.0a0 size: 68004 timestamp: 1787753412298 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libfreetype-2.14.3-ha770c72_2.conda + sha256: fb12ecb46c30d18d928c0e8fc346ab13b5f6fc8a9cacae4f2f4bb188782586f5 + md5: f8054e759d0ddddaf34a5c8fedc900a1 + depends: + - libfreetype6 >=2.14.3 + license: GPL-2.0-only OR FTL + purls: [] + run_exports: {} + size: 8407 + timestamp: 1786641007099 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libfreetype6-2.14.3-h5e6c136_2.conda + sha256: ec607dd5445dd17ff6bf8b7fe6832e5504c226dd91d3aaea7ba83569808b0ce4 + md5: b72a266a9317036fd0464cb98b027cd0 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - libpng >=1.6.58,<1.7.0a0 + - libzlib >=1.3.2,<2.0a0 + constrains: + - freetype >=2.14.3 + license: GPL-2.0-only OR FTL + purls: [] + run_exports: {} + size: 387671 + timestamp: 1786641006460 - conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-16.2.0-ha9f2e26_7.conda sha256: e031634c3a928f9594eba868bc46ef5230d6571a364a0c63215b06c4563bfcea md5: 735629b400b70eeab21a2ba8f5b1c2ce @@ -1092,6 +1503,19 @@ packages: run_exports: {} size: 1058444 timestamp: 1790303109576 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-16.2.0-h69a702a_7.conda + sha256: 03b54d7008de080a17cc2174b0e4acd6d06e1c981b2eb19846f46d8f59966034 + md5: 2005515ac9340f816fb2ac7e83afe553 + depends: + - libgcc 16.2.0 ha9f2e26_7 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + purls: [] + run_exports: + strong: + - libgcc + size: 28616 + timestamp: 1790303114248 - conda: https://conda.anaconda.org/conda-forge/linux-64/libgfortran-16.2.0-h69a702a_7.conda sha256: 9682ae4dd11487e10b904b3cb3ab6379cad25233d45fdfdf90d54349df244494 md5: 3a8d285f5f22138ef826ad54cf267e73 @@ -1119,6 +1543,46 @@ packages: run_exports: {} size: 2528180 timestamp: 1790303122004 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libglib-2.90.0-h569388d_0.conda + sha256: 9e688e046550415c030c3d08ed9a3fd13a51d7bc56295283b858b6c3070bb9f8 + md5: c85e9539551f1fd21104e518d940c244 + depends: + - libgcc >=15 + - __glibc >=2.17,<3.0.a0 + - libiconv >=1.18,<2.0a0 + - pcre2 >=10.47,<10.48.0a0 + - libffi >=3.7.0,<3.8.0a0 + - libzlib >=1.3.2,<2.0a0 + constrains: + - glib >2.66 + license: LGPL-2.1-or-later + purls: [] + run_exports: + weak: + - libglib >=2.90.0,<3.0a0 + size: 4819130 + timestamp: 1789478025196 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libharfbuzz-14.6.0-h23af247_2.conda + sha256: 3dea71a07100fd523ff173538577fd2e06a42beb5cb25e4a18ac9484773753ba + md5: 6a93147cab011f36d1659745c3f579e2 + depends: + - __glibc >=2.17,<3.0.a0 + - cairo >=1.18.6,<2.0a0 + - graphite2 >=1.3.15,<2.0a0 + - icu >=78.3,<79.0a0 + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + - libgcc >=15 + - libglib >=2.90.0,<3.0a0 + - libpng >=1.6.59,<1.7.0a0 + - libstdcxx >=15 + - libzlib >=1.3.2,<2.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: {} + size: 1463302 + timestamp: 1791900600568 - conda: https://conda.anaconda.org/conda-forge/linux-64/libhwloc-2.15.0-default_hd7c4d0c_1001.conda sha256: a140f8b94caad6ea27e9deba66a74ae2566976591db8a867677c652add6ee5a0 md5: 66c755b3bd9ec82308fa6ec7674f473f @@ -1149,6 +1613,21 @@ packages: - libiconv >=1.18,<2.0a0 size: 789471 timestamp: 1787033836207 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libjpeg-turbo-3.2.0-hb03c661_1.conda + sha256: bba8538e6538ed58a8479b332337b96986561f975d06cfa2039a016c2d246ee4 + md5: 898d1c9793eaa52efc4727bd84d2e39a + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=14 + constrains: + - jpeg <0.0.0a + license: IJG AND BSD-3-Clause AND Zlib + purls: [] + run_exports: + weak: + - libjpeg-turbo >=3.2.0,<4.0a0 + size: 650434 + timestamp: 1785896381946 - conda: https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.11.0-11_h5e43f62_mkl.conda build_number: 11 sha256: 7b80fc195419463533262b9d327c75559dd820251902e3fa41cce02a3b23bb5b @@ -1280,6 +1759,20 @@ packages: - libonnx >=1.23.2,<1.23.3.0a0 size: 1676952 timestamp: 1791291889441 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libpng-1.6.59-h922cc85_0.conda + sha256: c7381be8ef713501f6cd2f5ad473e401f2edeaec3c46788296b8dbf0de165e15 + md5: 8c9caf742a485ac688ffa88bbadbf0be + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - libzlib >=1.3.2,<2.0a0 + license: zlib-acknowledgement + purls: [] + run_exports: + weak: + - libpng >=1.6.59,<1.7.0a0 + size: 316872 + timestamp: 1790805159503 - conda: https://conda.anaconda.org/conda-forge/linux-64/libprotobuf-7.35.1-h622638d_3.conda sha256: 37c51fbc936a6bb8bf5f67c8f056edacaaa41e8603738bc8a4dee186292bb114 md5: fd307b61cceb36fdca38e1718bdb2893 @@ -1313,22 +1806,39 @@ packages: - libpython >=3.13,<4.0a0 size: 9718885 timestamp: 1791334276485 -- conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.53.4-h0737f62_103.conda - sha256: 66f4831f4ee3055f0ffe94e01901198cf3601e2c1b4f6b51d05c3f2d8557ce1d - md5: cc1ad2520049c35344239454a17560ac +- conda: https://conda.anaconda.org/conda-forge/linux-64/libraqm-0.11.0-h6406941_0.conda + sha256: ab3ccb9fd5816f76b18ee8974d359cd2605ca87d8ddef55369dc461b9986f95c + md5: 3ac89a48d224409739dbf6200e524373 + depends: + - libgcc >=14 + - __glibc >=2.28,<3.0.a0 + - fribidi >=1.0.16,<2.0a0 + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + - libharfbuzz >=14.2.1 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - libraqm >=0.11.0,<0.12.0a0 + size: 33983 + timestamp: 1784850267262 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.54.1-h13e7031_0.conda + sha256: 07b3c98282022f05781122d073f84e944bfb4299946e8457ece3ce6c384ff78e + md5: 8f15f0ec9b69344df5c3bb5cce1751a1 depends: - __glibc >=2.17,<3.0.a0 + - icu >=78.3,<79.0a0 - libgcc >=15 - libzlib >=1.3.2,<2.0a0 - constrains: - - icu <0.0a0 license: blessing purls: [] run_exports: weak: - - libsqlite >=3.53.4,<4.0a0 - size: 967489 - timestamp: 1791288185694 + - libsqlite >=3.54.1,<4.0a0 + size: 983668 + timestamp: 1792175587601 - conda: https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.1-h6154650_1.conda sha256: 7e463000fa1cba3f3a6597b776f6ab301d425a96e3bc20d0d9d76a3b9f237aa3 md5: 5c526561e1d2a2e071941174eae84557 @@ -1359,6 +1869,19 @@ packages: run_exports: {} size: 6615436 timestamp: 1790303132935 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-16.2.0-hdf11a46_7.conda + sha256: 337f481db36cc357884f05f404ccd1b3a7e0fc1ee48ec5c884e4281d213bc863 + md5: 25a23bde5e26d548374f3e02b4669670 + depends: + - libstdcxx 16.2.0 h934c35e_7 + license: GPL-3.0-only WITH GCC-exception-3.1 + license_family: GPL + purls: [] + run_exports: + strong: + - libstdcxx + size: 28665 + timestamp: 1790303164510 - conda: https://conda.anaconda.org/conda-forge/linux-64/libsystemd0-262-h26e0ef7_2.conda sha256: 265ba1e0bf848b9da2a33f7bec7745bc8d69bc2452e2d9fc75f340492a3b010d md5: e76269d6aff0b947103cbe37a96b5737 @@ -1371,6 +1894,27 @@ packages: run_exports: {} size: 572864 timestamp: 1790777898360 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libtiff-4.7.2-hcc2c06a_1.conda + sha256: 10e125da82ca93e09191e66e5a94d566b2cf8d4024e2a0db3a9114297447e0d9 + md5: 0907d876f460ebc941ae590338b6102f + depends: + - __glibc >=2.17,<3.0.a0 + - lerc >=4.2.0,<5.0a0 + - libdeflate >=1.25,<1.26.0a0 + - libgcc >=15 + - libjpeg-turbo >=3.2.0,<4.0a0 + - liblzma >=5.8.3,<6.0a0 + - libstdcxx >=15 + - libwebp-base >=1.6.0,<2.0a0 + - libzlib >=1.3.2,<2.0a0 + - zstd >=1.5.7,<1.6.0a0 + license: HPND + purls: [] + run_exports: + weak: + - libtiff >=4.7.2,<4.8.0a0 + size: 459753 + timestamp: 1787755584172 - conda: https://conda.anaconda.org/conda-forge/linux-64/libtorch-2.13.0-cuda129_mkl_h546cc0b_304.conda sha256: dbbcc77563fa466db03327374ee096bfe7e8b88d5fd285023c6fea64fc15c277 md5: dce74602df0dadf0c21b861f1e33b62c @@ -1460,36 +2004,68 @@ packages: - libuv >=1.52.1,<2.0a0 size: 420040 timestamp: 1785914567661 -- conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-16-2.15.4-hbdfff7e_0.conda - sha256: b6f96287c408269f5067bb4f7a61693ff5c856152902362964d9807152b9c146 - md5: 176fa262c40e1141e9f364d3e4783795 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libwebp-base-1.6.0-hd42ef1d_1.conda + sha256: 8415001414f488c85b72b9d8cc2071dfb3981a47bc3c8eb56ef91a57d12eae7f + md5: 9332b53d0ea93c5d39e33be03a0c611a depends: - __glibc >=2.17,<3.0.a0 + - libgcc >=14 + constrains: + - libwebp 1.6.0 + license: BSD-3-Clause + license_family: BSD + purls: [] + run_exports: + weak: + - libwebp-base >=1.6.0,<2.0a0 + size: 428430 + timestamp: 1785954557217 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libxcb-1.17.0-hb83e432_2.conda + sha256: 7b49e6fd2a584b7f072943e6adf4149677af5121246975278804782d37752837 + md5: 61f0ffba9161cbb3a77722869b21e4bb + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - pthread-stubs + - xorg-libxau >=1.0.12,<2.0a0 + - xorg-libxdmcp >=1.1.5,<2.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - libxcb >=1.17.0,<2.0a0 + size: 395120 + timestamp: 1787885788278 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-16-2.15.4-hf3af7cc_1.conda + sha256: d1906463070c21f3215cd5de93164f31c44d5bac6ae9b5d8f5adf42b1e304039 + md5: 046d9eada488e1a1657c80b55c23da52 + depends: + - __glibc >=2.17,<3.0.a0 + - icu >=78.3,<79.0a0 - libgcc >=15 - libiconv >=1.18,<2.0a0 - liblzma >=5.8.3,<6.0a0 - libzlib >=1.3.2,<2.0a0 constrains: - - icu <0.0a0 - libxml2 2.15.4 license: MIT license_family: MIT purls: [] run_exports: {} - size: 565717 - timestamp: 1788635209625 -- conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.15.4-ha7a5771_0.conda - sha256: db52c038430a508656530fc7b5650ae3e2629875693a6a256cc48dec203f8bfe - md5: c322ae4591dfe866b2a9b1e8537fe805 + size: 569062 + timestamp: 1791465631497 +- conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.15.4-h7df9aa5_1.conda + sha256: 8c32be9e8720bc413d2b4267517459d7d71fad4a5f398a2aa8319b6d7b8a00e6 + md5: 51e5162f95bd6840f6b2b3169125fff5 depends: - __glibc >=2.17,<3.0.a0 + - icu >=78.3,<79.0a0 - libgcc >=15 - libiconv >=1.18,<2.0a0 - liblzma >=5.8.3,<6.0a0 - - libxml2-16 2.15.4 hbdfff7e_0 + - libxml2-16 2.15.4 hf3af7cc_1 - libzlib >=1.3.2,<2.0a0 - constrains: - - icu <0.0a0 license: MIT license_family: MIT purls: [] @@ -1497,8 +2073,8 @@ packages: weak: - libxml2 - libxml2-16 >=2.15.4 - size: 46952 - timestamp: 1788635214834 + size: 46570 + timestamp: 1791465635923 - conda: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.2-h25fd6f3_3.conda sha256: eb8a0db0aa570124f7d2a93d7c7f596e3390df5e047818d873baad32985fc736 md5: 0de0122d9570a8ab637c6b73db268389 @@ -1548,6 +2124,38 @@ packages: run_exports: {} size: 26579 timestamp: 1791014766127 +- conda: https://conda.anaconda.org/conda-forge/linux-64/matplotlib-base-3.11.2-py313he85fb2c_1.conda + sha256: 0cdfcbf58ca1cab8a941c2dbb1c958ea211fbb92cd262626fb766c06615d5d5e + md5: 85e795dd9e44b84961fafb4e7dd589aa + depends: + - __glibc >=2.17,<3.0.a0 + - contourpy >=1.0.1 + - cycler >=0.10 + - fonttools >=4.28.2 + - freetype + - kiwisolver >=1.3.1 + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + - libgcc >=15 + - libraqm >=0.11.0,<0.12.0a0 + - libstdcxx >=15 + - numpy >=1.25 + - numpy >=1.25,<3 + - packaging >=20.0 + - pillow >=9 + - pyparsing >=3 + - python >=3.13,<3.14.0a0 + - python-dateutil >=2.7 + - python_abi 3.13.* *_cp313 + - qhull >=2020.2,<2020.3.0a0 + - tk >=8.6.13,<8.7.0a0 + license: PSF-2.0 + license_family: PSF + purls: + - pkg:pypi/matplotlib?source=compressed-mapping + run_exports: {} + size: 9026765 + timestamp: 1789824128731 - conda: https://conda.anaconda.org/conda-forge/linux-64/mkl-2026.1.0-hd2095e1_245.conda sha256: a2699b4db5f93ae7211249f5b8df4981c22765c392cc6d34c18d76994fe3b327 md5: 5c8b5643ac9b96cd1c5b65a17337ce5c @@ -1728,6 +2336,24 @@ packages: run_exports: {} size: 294012437 timestamp: 1790746169696 +- conda: https://conda.anaconda.org/conda-forge/linux-64/openjpeg-2.5.4-heb1ab33_2.conda + sha256: 131688a88bea8da92fe418c4558c5073435e2848911bc4c836c3a9dd5994b4aa + md5: a3f3ac7a68d01c198e276dbb99e62032 + depends: + - libgcc >=15 + - __glibc >=2.17,<3.0.a0 + - libstdcxx >=15 + - libtiff >=4.7.2,<4.8.0a0 + - libzlib >=1.3.2,<2.0a0 + - libpng >=1.6.58,<1.7.0a0 + license: BSD-2-Clause + license_family: BSD + purls: [] + run_exports: + weak: + - openjpeg >=2.5.4,<3.0a0 + size: 391242 + timestamp: 1788425045145 - conda: https://conda.anaconda.org/conda-forge/linux-64/openssl-3.6.5-h781a0a9_0.conda sha256: 9c1533f1cf784f0e250919c0c9762d0b0e6bc727a79290ffb7cea1ceca1d038c md5: 5a51a2ea653f120240b1a9bf76e0aae9 @@ -1760,6 +2386,61 @@ packages: run_exports: {} size: 586381 timestamp: 1788504569784 +- conda: https://conda.anaconda.org/conda-forge/linux-64/pcre2-10.47-h8b3dc9c_1.conda + sha256: 9ebb10a4eb3be51ae67d85c679f5a7a50cb040ed25c783e6331a225ea09991d4 + md5: 06f6113cf1ff4a54b65f87ead132a5f1 + depends: + - __glibc >=2.17,<3.0.a0 + - bzip2 >=1.0.8,<2.0a0 + - libgcc >=15 + - libzlib >=1.3.2,<2.0a0 + license: BSD-3-Clause + license_family: BSD + purls: [] + run_exports: + weak: + - pcre2 >=10.47,<10.48.0a0 + size: 1218833 + timestamp: 1787294571916 +- conda: https://conda.anaconda.org/conda-forge/linux-64/pillow-13.0.0-py313h3b26573_0.conda + sha256: e9efd1a2015165aafd118ea1bef35b70b4cd8bb0a7629bc6a2d6d92ae1d01aae + md5: f31c982db861132e73aa9bde2ebdc0b1 + depends: + - python + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - libxcb >=1.17.0,<2.0a0 + - libfreetype >=2.14.3 + - libfreetype6 >=2.14.3 + - lcms2 >=2.19.1,<3.0a0 + - libwebp-base >=1.6.0,<2.0a0 + - openjpeg >=2.5.4,<3.0a0 + - python_abi 3.13.* *_cp313 + - zlib-ng >=2.3.3,<2.4.0a0 + - tk >=8.6.13,<8.7.0a0 + - libtiff >=4.7.2,<4.8.0a0 + - libjpeg-turbo >=3.2.0,<4.0a0 + license: HPND + purls: + - pkg:pypi/pillow?source=compressed-mapping + run_exports: {} + size: 1083173 + timestamp: 1792416406105 +- conda: https://conda.anaconda.org/conda-forge/linux-64/pixman-0.46.4-h54a6638_3.conda + sha256: 829d8288764282de5a9f7b9169acb75cc7dc0b6c3fe2535cfe87dea3436bbc5d + md5: 0ee5bb30034b081a1386c1e2c98ab0a7 + depends: + - libstdcxx >=14 + - libgcc >=14 + - __glibc >=2.17,<3.0.a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - pixman >=0.46.4,<1.0a0 + size: 376704 + timestamp: 1786106621354 - conda: https://conda.anaconda.org/conda-forge/linux-64/protobuf-7.35.1-py313hf4667e8_3.conda sha256: 78296e9a95fb21402682043e79a8bbc829fc9cc317d7ff818fcb07bf4182eb2a md5: e835bdf081aab510728d2c4994492f10 @@ -1781,6 +2462,18 @@ packages: run_exports: {} size: 492698 timestamp: 1788687323172 +- conda: https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-h7cc23a3_1004.conda + sha256: 4a44fd00ea73b79ca2c89b0727b9ccf61c506ead71e67a9abfa4c590042b5a4a + md5: bb66b610707b811e3c65181a6431e7a8 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + license: MIT + license_family: MIT + purls: [] + run_exports: {} + size: 9630 + timestamp: 1788381877753 - conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.13.16-hf47f18c_101_cp313.conda build_number: 101 sha256: 914ce0022ee08951329ce85d8a35f55fa11e74239568bca6102375d630ca9e61 @@ -1872,7 +2565,7 @@ packages: license: BSD-3-Clause license_family: BSD purls: - - pkg:pypi/torch?source=compressed-mapping + - pkg:pypi/torch?source=hash-mapping run_exports: weak: - pytorch >=2.13.0,<2.14.0a0 @@ -1906,6 +2599,20 @@ packages: run_exports: {} size: 201616 timestamp: 1770223543730 +- conda: https://conda.anaconda.org/conda-forge/linux-64/qhull-2020.2-h434a139_5.conda + sha256: 776363493bad83308ba30bcb88c2552632581b143e8ee25b1982c8c743e73abc + md5: 353823361b1d27eb3960efb076dfcaf6 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc-ng >=12 + - libstdcxx-ng >=12 + license: LicenseRef-Qhull + purls: [] + run_exports: + weak: + - qhull >=2020.2,<2020.3.0a0 + size: 552937 + timestamp: 1720813982144 - conda: https://conda.anaconda.org/conda-forge/linux-64/rdma-core-65.0-h7b4f2e6_0.conda sha256: 2da73957fc57eb46efc0d42bb8d73fa3bf36ea98c02a31ce17de06a40d2a1884 md5: b47757f1512801cd064f0f973896d724 @@ -2072,6 +2779,109 @@ packages: run_exports: {} size: 40349627 timestamp: 1781881959760 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libice-1.1.2-h280c20c_0.conda + sha256: 49b532d1df875c6749d9078b56a76f3f5db49a5abe0ca620b593ed474ef0ebf1 + md5: 85c9442aec283b4e464fa9ecc484a2f3 + depends: + - libgcc >=14 + - __glibc >=2.17,<3.0.a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libice >=1.1.2,<2.0a0 + size: 62517 + timestamp: 1786474410404 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libsm-1.2.6-h0d788c3_1.conda + sha256: ef907caee0665cf3b0f775602cc50e388e3bade8ce22ecade0873ff26604b2fd + md5: aa7459ed9ad086ba11dda843d764b33d + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=14 + - xorg-libice >=1.1.2,<2.0a0 + - libuuid >=2.42.2,<3.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libsm >=1.2.6,<2.0a0 + size: 30739 + timestamp: 1786545374265 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libx11-1.8.14-hb83e432_0.conda + sha256: 1815dc9900bf3a4678caeb343bccbbc74cd5e5a5ff3f6e0a2c01c5e19cd9d30b + md5: e7752792cb214013a34e265cc0838352 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - libxcb >=1.17.0,<2.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libx11 >=1.8.14,<2.0a0 + size: 846774 + timestamp: 1792545407029 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxau-1.0.12-h7cc23a3_2.conda + sha256: 3ec065b94554dc48a4ca582a960a5484bc166b26e83ce0954653e08d17e8bd53 + md5: da33efee1a93603d92e06d4a2b68def6 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libxau >=1.0.12,<2.0a0 + size: 18793 + timestamp: 1788960512381 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxdmcp-1.1.5-h7cc23a3_2.conda + sha256: 8a095df9bc1d2e50f2504ce8858a047ae29ea634aad6cc0b43298c63361da6d9 + md5: eabfc45786244de252090cf8d55128a8 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libxdmcp >=1.1.5,<2.0a0 + size: 22606 + timestamp: 1789676943335 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxext-1.3.7-h7cc23a3_1.conda + sha256: aa9bbe8b278aacc194e280ff5037f9f9a1f2c5b33ed97de8e7f01cfbe90dda43 + md5: e5b6b28536b81b3f4cb20db4668a4642 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - xorg-libx11 >=1.8.13,<2.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libxext >=1.3.7,<2.0a0 + size: 53124 + timestamp: 1787100841900 +- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrender-0.9.13-h7cc23a3_0.conda + sha256: 008d610d6ec1d021ad678024afd5dcf534ff84d9c1e9d2877ff36d112c89896f + md5: 7249ce52789c3680e889e7335a2e1c3e + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - xorg-libx11 >=1.8.13,<2.0a0 + license: MIT + license_family: MIT + purls: [] + run_exports: + weak: + - xorg-libxrender >=0.9.13,<0.10.0a0 + size: 34604 + timestamp: 1792530399214 - conda: https://conda.anaconda.org/conda-forge/linux-64/yaml-0.2.5-hebe6cf0_3.conda sha256: d164dfa75ecd538f6fd68765defcc06aa875bc697b9b215362d79a2a73125dd0 md5: e741576fb8f89821ac7c1c537322a33d @@ -2086,6 +2896,21 @@ packages: - yaml >=0.2.5,<0.3.0a0 size: 84936 timestamp: 1787228426393 +- conda: https://conda.anaconda.org/conda-forge/linux-64/zlib-ng-2.3.3-hce19668_1.conda + sha256: 8b786bb4380fa69a718b08a400040b865bc9207eda337e0a1955717c3c3a9403 + md5: 1726acec19beeed1c764385cd8622405 + depends: + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - libstdcxx >=15 + license: Zlib + license_family: Other + purls: [] + run_exports: + weak: + - zlib-ng >=2.3.3,<2.4.0a0 + size: 123959 + timestamp: 1786736890973 - conda: https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.7-hb78ec9c_7.conda sha256: 47d682b9f6d6ec9eb1a6e6c3e75ea6273e899e78fb7fc59f81d39745009fbc60 md5: aa459086047c0e5e27023ab19f8cb86a @@ -2193,6 +3018,19 @@ packages: run_exports: {} size: 21578 timestamp: 1746134436166 +- conda: https://conda.anaconda.org/conda-forge/noarch/cycler-0.12.1-pyhcf101f3_2.conda + sha256: bb47aec5338695ff8efbddbc669064a3b10fe34ad881fb8ad5d64fbfa6910ed1 + md5: 4c2a8fef270f6c69591889b93f9f55c1 + depends: + - python >=3.10 + - python + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/cycler?source=hash-mapping + run_exports: {} + size: 14778 + timestamp: 1764466758386 - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda sha256: ee6cf346d017d954255bbcbdb424cddea4d14e4ed7e9813e429db1d795d01144 md5: 8e662bd460bda79b1ea39194e3c4c9ab @@ -2217,6 +3055,67 @@ packages: run_exports: {} size: 85969 timestamp: 1791210321663 +- conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-dejavu-sans-mono-2.37-hab24e00_0.tar.bz2 + sha256: 58d7f40d2940dd0a8aa28651239adbf5613254df0f75789919c4e6762054403b + md5: 0c96522c6bdaed4b1566d11387caaf45 + license: BSD-3-Clause + license_family: BSD + purls: [] + run_exports: {} + size: 397370 + timestamp: 1566932522327 +- conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-inconsolata-3.000-h77eed37_0.tar.bz2 + sha256: c52a29fdac682c20d252facc50f01e7c2e7ceac52aa9817aaf0bb83f7559ec5c + md5: 34893075a5c9e55cdafac56607368fc6 + license: OFL-1.1 + license_family: Other + purls: [] + run_exports: {} + size: 96530 + timestamp: 1620479909603 +- conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-source-code-pro-2.038-h77eed37_0.tar.bz2 + sha256: 00925c8c055a2275614b4d983e1df637245e19058d79fc7dd1a93b8d9fb4b139 + md5: 4d59c254e01d9cde7957100457e2d5fb + license: OFL-1.1 + license_family: Other + purls: [] + run_exports: {} + size: 700814 + timestamp: 1620479612257 +- conda: https://conda.anaconda.org/conda-forge/noarch/font-ttf-ubuntu-0.83-h77eed37_3.conda + sha256: 2821ec1dc454bd8b9a31d0ed22a7ce22422c0aef163c59f49dfdf915d0f0ca14 + md5: 49023d73832ef61042f6a237cb2687e7 + license: LicenseRef-Ubuntu-Font-Licence-Version-1.0 + license_family: Other + purls: [] + run_exports: {} + size: 1620504 + timestamp: 1727511233259 +- conda: https://conda.anaconda.org/conda-forge/noarch/fonts-conda-ecosystem-1-0.tar.bz2 + sha256: a997f2f1921bb9c9d76e6fa2f6b408b7fa549edd349a77639c9fe7a23ea93e61 + md5: fee5683a3f04bd15cbd8318b096a27ab + depends: + - fonts-conda-forge + license: BSD-3-Clause + license_family: BSD + purls: [] + run_exports: {} + size: 3667 + timestamp: 1566974674465 +- conda: https://conda.anaconda.org/conda-forge/noarch/fonts-conda-forge-1-hc364b38_1.conda + sha256: 54eea8469786bc2291cc40bca5f46438d3e062a399e8f53f013b6a9f50e98333 + md5: a7970cd949a077b7cb9696379d338681 + depends: + - font-ttf-ubuntu + - font-ttf-inconsolata + - font-ttf-dejavu-sans-mono + - font-ttf-source-code-pro + license: BSD-3-Clause + license_family: BSD + purls: [] + run_exports: {} + size: 4059 + timestamp: 1762351264405 - conda: https://conda.anaconda.org/conda-forge/noarch/fsspec-2026.9.0-pyhd8ed1ab_0.conda sha256: 7d17272012e7479ba58f8a72b522d3e88e6837a04a111a278ff417aa82364255 md5: 42de5cd170647599a84f468a42fabb89 @@ -2281,6 +3180,18 @@ packages: run_exports: {} size: 464918 timestamp: 1773662068273 +- conda: https://conda.anaconda.org/conda-forge/noarch/munkres-1.1.4-pyhd8ed1ab_1.conda + sha256: d09c47c2cf456de5c09fa66d2c3c5035aa1fa228a1983a433c47b876aa16ce90 + md5: 37293a85a0f4f77bbd9cf7aaefc62609 + depends: + - python >=3.9 + license: Apache-2.0 + license_family: Apache + purls: + - pkg:pypi/munkres?source=hash-mapping + run_exports: {} + size: 15851 + timestamp: 1749895533014 - conda: https://conda.anaconda.org/conda-forge/noarch/narwhals-2.27.0-pyh5ded981_0.conda sha256: 93be72d3cfd946e08295f9c77e0e3896caad7b1f818e17388d2e682f60b8925d md5: 9e4512fe1aa400d3c08d1ced8eab3139 @@ -2406,6 +3317,19 @@ packages: run_exports: {} size: 959376 timestamp: 1786995678795 +- conda: https://conda.anaconda.org/conda-forge/noarch/pyparsing-3.3.3-pyh5ded981_0.conda + sha256: dc10d64d4b9a1310083b2f563416ab45560ee2a04fd6baab40f223f2b1ab37bc + md5: 8bf43ae1312e9b966063459e04c20fa7 + depends: + - python >=3.11 + - python + license: MIT + license_family: MIT + purls: + - pkg:pypi/pyparsing?source=compressed-mapping + run_exports: {} + size: 114046 + timestamp: 1790063282695 - conda: https://conda.anaconda.org/conda-forge/noarch/pytest-9.1.1-pyhc364b38_2.conda sha256: 430051d80765207a7d782b2b188230ba1489d35c6e75fd9903f76cb9fda4af16 md5: 64c98a12c4e23eb238bf66bbecafdf3c @@ -2428,6 +3352,20 @@ packages: run_exports: {} size: 306724 timestamp: 1782127176429 +- conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-3.0.0-pyh5ded981_0.conda + sha256: 8ad3e3fd71fa3881081a38d660cd9cc7bd18fd4eb99cee96225903e5e2eb9ae9 + md5: d75c60076c9f2cfa4a459e9f17cecd93 + depends: + - python >=3.11 + - six >=1.6 + - python-tzdata + - python + license: Apache-2.0 + purls: + - pkg:pypi/python-dateutil?source=compressed-mapping + run_exports: {} + size: 89526 + timestamp: 1792674886408 - conda: https://conda.anaconda.org/conda-forge/noarch/python-flatbuffers-25.12.19-pyh9d96877_0.conda sha256: dff2f2fc462996f71686c05a0fba78a0dc919034ef8d879dd8366534ad64c0f1 md5: 3a28cf4d2187c1dfb0c31aedbf275b8c @@ -2440,6 +3378,19 @@ packages: run_exports: {} size: 35556 timestamp: 1784053026634 +- conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2026.5-pyh5ded981_0.conda + sha256: b66b783be882069a9f6c00bc44ee561fc3dfba21fe4bab6de31599caf3c63154 + md5: 4a0ae2a06b469e6f8ca95d0655e31c86 + depends: + - python >=3.11 + - python + license: Apache-2.0 + license_family: APACHE + purls: + - pkg:pypi/tzdata?source=compressed-mapping + run_exports: {} + size: 141379 + timestamp: 1791025923003 - conda: https://conda.anaconda.org/conda-forge/noarch/python_abi-3.13-9_cp313.conda build_number: 9 sha256: 9dc0cb6a20ebc7e9bcd8c6868f2bec083c114b0ba20b7118405c036533d5c522 @@ -2464,6 +3415,19 @@ packages: run_exports: {} size: 676888 timestamp: 1770456470072 +- conda: https://conda.anaconda.org/conda-forge/noarch/six-1.17.0-pyhe01879c_1.conda + sha256: 458227f759d5e3fcec5d9b7acce54e10c9e1f4f4b7ec978f3bfd54ce4ee9853d + md5: 3339e3b65d58accf4ca4fb8748ab16b3 + depends: + - python >=3.9 + - python + license: MIT + license_family: MIT + purls: + - pkg:pypi/six?source=hash-mapping + run_exports: {} + size: 18455 + timestamp: 1753199211006 - conda: https://conda.anaconda.org/conda-forge/noarch/sympy-1.14.0-pyh2585a3b_106.conda sha256: 1c8057e6875eba958aa8b3c1a072dc9a75d013f209c26fd8125a5ebd3abbec0c md5: 32d866e43b25275f61566b9391ccb7b5 @@ -2545,6 +3509,7 @@ packages: - h5py>=3.0 - pyyaml>=5.4 - scikit-learn>=1.0 + - matplotlib>=3.5 - onnx>=1.14 ; extra == 'export' - onnxruntime>=1.15 ; extra == 'export' - pytest>=7 ; extra == 'test' From 205be7ed7dbeb774f175f178f66d635329ba5a19 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:24:02 -0400 Subject: [PATCH 17/23] report: ruff format and lint fixes; mean over folds without the empty-slice warning --- src/corenet/report.py | 1048 ++++++++++++++++++++++++++++++++++------- tests/test_report.py | 26 +- 2 files changed, 905 insertions(+), 169 deletions(-) diff --git a/src/corenet/report.py b/src/corenet/report.py index be401ca..9ed1bf1 100644 --- a/src/corenet/report.py +++ b/src/corenet/report.py @@ -15,7 +15,6 @@ could not be produced for the run. Every figure is embedded as PNG; the page needs no other file. """ -# ruff: noqa: RUF001 from __future__ import annotations import argparse @@ -39,18 +38,18 @@ import yaml matplotlib.use("Agg") -import matplotlib.pyplot as plt # noqa: E402 +import matplotlib.pyplot as plt -from . import __version__ # noqa: E402 -from .checkpoint import fold_rule_of, load_checkpoint # noqa: E402 -from .data.h5 import ( # noqa: E402 +from . import __version__ +from .checkpoint import fold_rule_of, load_checkpoint +from .data.h5 import ( FOLD_RULE_EVENT, H5Dataset, event_source, resolve_group, ) -from .models.config import NetworkSpec, parse_config, read_config_dict # noqa: E402 -from .models.network import CoReNet # noqa: E402 +from .models.config import NetworkSpec, parse_config, read_config_dict +from .models.network import CoReNet SECTIONS = [ ("summary", "Run summary"), @@ -118,7 +117,9 @@ def mean_sd(values) -> str: def table(header: list[str], rows: list[list], caption: str = "") -> str: head = "".join(f"{esc(h)}" for h in header) body = "".join( - "" + "".join(f"{c if isinstance(c, str) else fmt(c)}" for c in r) + "" + "" + + "".join(f"{c if isinstance(c, str) else fmt(c)}" for c in r) + + "" for r in rows ) cap = f"{esc(caption)}" if caption else "" @@ -173,7 +174,13 @@ def hist_panel(ax, series, bins, xlabel: str, logy: bool = False) -> None: if not ok.any() or w[ok].sum() <= 0: continue ax.hist( - v[ok], bins=bins, weights=w[ok], density=True, histtype="step", label=lab, **st + v[ok], + bins=bins, + weights=w[ok], + density=True, + histtype="step", + label=lab, + **st, ) ax.set_xlabel(xlabel) ax.set_ylabel("density") @@ -288,9 +295,16 @@ def sub_split(s: Split, sel: np.ndarray, source: str) -> Split: def discover_folds(run_dir: Path, wanted: list[int] | None) -> list[int]: folds = set() - for pattern in ("history_fold*.json", "model_fold*.pkl", "predictions_fold*.h5", "eval_fold*.h5"): + for pattern in ( + "history_fold*.json", + "model_fold*.pkl", + "predictions_fold*.h5", + "eval_fold*.h5", + ): for p in run_dir.glob(pattern): - m = re.fullmatch(r"(?:history|model|predictions|eval)_fold(\d+)\.(?:json|pkl|h5)", p.name) + m = re.fullmatch( + r"(?:history|model|predictions|eval)_fold(\d+)\.(?:json|pkl|h5)", p.name + ) if m: folds.add(int(m.group(1))) if wanted is not None: @@ -321,7 +335,9 @@ def load(self) -> None: raise SystemExit(f"{self.run_dir}: not a directory") fold_ids = discover_folds(self.run_dir, a.folds) if not fold_ids: - raise SystemExit(f"{self.run_dir}: no history_fold*.json, model_fold*.pkl or predictions_fold*.h5") + raise SystemExit( + f"{self.run_dir}: no history_fold*.json, model_fold*.pkl or predictions_fold*.h5" + ) for k in fold_ids: fd = FoldData(k) hp = self.run_dir / f"history_fold{k}.json" @@ -335,14 +351,22 @@ def load(self) -> None: # configuration and network: --config, else the first checkpoint, else the history's config path first_ckpt = next((fd for fd in self.folds if fd.checkpoint), None) if first_ckpt is not None: - self.model, self.spec, ckpt = load_checkpoint(first_ckpt.checkpoint, a.config, "cpu") + self.model, self.spec, ckpt = load_checkpoint( + first_ckpt.checkpoint, a.config, "cpu" + ) self.config = read_config_dict(a.config) if a.config else ckpt["config"] - self.config_source = a.config or f"{first_ckpt.checkpoint.name} (stored configuration)" + self.config_source = ( + a.config or f"{first_ckpt.checkpoint.name} (stored configuration)" + ) else: cfg_path = a.config if cfg_path is None: for fd in self.folds: - if fd.history and fd.history.get("config") and Path(fd.history["config"]).is_file(): + if ( + fd.history + and fd.history.get("config") + and Path(fd.history["config"]).is_file() + ): cfg_path = fd.history["config"] break if cfg_path is None: @@ -354,10 +378,14 @@ def load(self) -> None: self.model = CoReNet(self.spec, device="cpu") self.model.eval() self.config_source = str(cfg_path) - self.gaps.append("no checkpoint in the run directory: the network was built from the configuration without trained weights (parameter count only)") + self.gaps.append( + "no checkpoint in the run directory: the network was built from the configuration without trained weights (parameter count only)" + ) for fd in self.folds: if fd.checkpoint: - meta = torch.load(fd.checkpoint, map_location="cpu", weights_only=False).get("metadata", {}) + meta = torch.load( + fd.checkpoint, map_location="cpu", weights_only=False + ).get("metadata", {}) fd.checkpoint_meta = dict(meta) # the dataset, with the fold rule of the run @@ -370,12 +398,24 @@ def load(self) -> None: n_folds = a.n_folds if a.fold_seed is not None: fold_seed = a.fold_seed - rest_order = a.rest_order or meta.get("rest_order") or (hist.get("recipe") or {}).get("rest_order", "pt") - self.ds = H5Dataset(self.input, self.spec, rest_order=rest_order, n_folds=n_folds, fold_seed=fold_seed) + rest_order = ( + a.rest_order + or meta.get("rest_order") + or (hist.get("recipe") or {}).get("rest_order", "pt") + ) + self.ds = H5Dataset( + self.input, + self.spec, + rest_order=rest_order, + n_folds=n_folds, + fold_seed=fold_seed, + ) self.labels = self.ds.labels.numpy() self.weights = self.ds.weights.numpy().astype(np.float64) self.fold_of = self.ds.folds.numpy() - logging.info(f"{self.input}: {len(self.ds):,} events, folds {self.ds.fold_rule}, classes {self.spec.classes}") + logging.info( + f"{self.input}: {len(self.ds):,} events, folds {self.ds.fold_rule}, classes {self.spec.classes}" + ) # predictions: predictions_fold{k}.h5 (held-out fold) and eval_fold{k}.h5 (any fold, or every event) for fd in self.folds: @@ -388,13 +428,19 @@ def load(self) -> None: if n_par is not None and fd.n_parameters is None: fd.n_parameters = n_par if split.index.max(initial=-1) >= len(self.ds): - self.gaps.append(f"{name}: event indices exceed the input file ({len(self.ds):,} events); the file does not belong to this input") + self.gaps.append( + f"{name}: event indices exceed the input file ({len(self.ds):,} events); the file does not belong to this input" + ) continue if fold_attr == k: - fd.splits.setdefault("test", sub_split(split, np.ones(len(split.index), bool), name)) + fd.splits.setdefault( + "test", sub_split(split, np.ones(len(split.index), bool), name) + ) continue if fold_attr >= 0: - self.gaps.append(f"{name}: evaluated fold {fold_attr}, not the held-out fold {k} nor every event; ignored") + self.gaps.append( + f"{name}: evaluated fold {fold_attr}, not the held-out fold {k} nor every event; ignored" + ) continue folds_of_rows = self.fold_of[split.index] test = folds_of_rows == k @@ -405,15 +451,23 @@ def load(self) -> None: if val.any(): fd.splits["validation"] = sub_split(split, val, name) else: - self.gaps.append(f"fold {k}: the validation folds are unknown (no history / checkpoint metadata); every event outside fold {k} in {name} counts as training") + self.gaps.append( + f"fold {k}: the validation folds are unknown (no history / checkpoint metadata); every event outside fold {k} in {name} counts as training" + ) if train.any(): fd.splits["train"] = sub_split(split, train, name) if "test" not in fd.splits: - self.gaps.append(f"fold {k}: no predictions_fold{k}.h5 or eval_fold{k}.h5: no ROC, scores or view probabilities for this fold") + self.gaps.append( + f"fold {k}: no predictions_fold{k}.h5 or eval_fold{k}.h5: no ROC, scores or view probabilities for this fold" + ) if "train" not in fd.splits: - self.gaps.append(f"fold {k}: no predictions on the training folds (run corenet-evaluate with --fold -1 and keep eval_fold{k}.h5 in the run directory): no overtraining check for this fold") + self.gaps.append( + f"fold {k}: no predictions on the training folds (run corenet-evaluate with --fold -1 and keep eval_fold{k}.h5 in the run directory): no overtraining check for this fold" + ) if fd.history is None: - self.gaps.append(f"fold {k}: no history_fold{k}.json: no training curves for this fold") + self.gaps.append( + f"fold {k}: no history_fold{k}.json: no training curves for this fold" + ) if fd.n_parameters is None and self.model is not None: fd.n_parameters = int(sum(p.numel() for p in self.model.parameters())) @@ -449,33 +503,83 @@ def section_summary(self) -> str: rows = [ ["input file", esc(self.input)], ["events", f"{len(self.ds):,}"], - ["classes", esc(", ".join(f"{i} = {c}" for i, c in enumerate(self.classes)))], + [ + "classes", + esc(", ".join(f"{i} = {c}" for i, c in enumerate(self.classes))), + ], ["folds", f"{self.ds.n_folds} ({esc(self.ds.fold_rule)})"], ["configuration", esc(self.config_source)], ["run directory", esc(self.run_dir)], - ["package", esc(f"corenet {__version__}" + (f", git {git_hash()}" if git_hash() else ""))], + [ + "package", + esc( + f"corenet {__version__}" + + (f", git {git_hash()}" if git_hash() else "") + ), + ], ["generated", esc(self.generated)], ] parts.append(table(["", ""], rows, "Run")) cfg_text = yaml.safe_dump(self.config, sort_keys=False, allow_unicode=True) - parts.append(f"
    Configuration ({esc(self.config_source)})
    {esc(cfg_text)}
    ") + parts.append( + f"
    Configuration ({esc(self.config_source)})
    {esc(cfg_text)}
    " + ) # events per class rows = [] for i, c in enumerate(self.classes): sel = self.labels == i - rows.append([c, int(sel.sum()), float(self.weights[sel].sum()), int((self.weights[sel] < 0).sum())]) - parts.append(table(["class", "events", "sum of weights", "negative weights"], rows, "Events per class in the input file")) + rows.append( + [ + c, + int(sel.sum()), + float(self.weights[sel].sum()), + int((self.weights[sel] < 0).sum()), + ] + ) + parts.append( + table( + ["class", "events", "sum of weights", "negative weights"], + rows, + "Events per class in the input file", + ) + ) # recipe hist = next((fd.history for fd in self.folds if fd.history), None) - meta = next((fd.checkpoint_meta for fd in self.folds if fd.checkpoint_meta), None) - recipe = (hist or {}).get("recipe") or {k: v for k, v in (meta or {}).items() if k not in ("fold", "epoch", "exclude_folds", "input", "n_folds", "fold_rule", "fold_seed", "finetune_trainable_parameters")} + meta = next( + (fd.checkpoint_meta for fd in self.folds if fd.checkpoint_meta), None + ) + recipe = (hist or {}).get("recipe") or { + k: v + for k, v in (meta or {}).items() + if k + not in ( + "fold", + "epoch", + "exclude_folds", + "input", + "n_folds", + "fold_rule", + "fold_seed", + "finetune_trainable_parameters", + ) + } if recipe: - parts.append(table(["setting", "value"], [[k, esc(v)] for k, v in recipe.items()], "Training recipe")) + parts.append( + table( + ["setting", "value"], + [[k, esc(v)] for k, v in recipe.items()], + "Training recipe", + ) + ) else: - parts.append(note("No training recipe recorded (no history or checkpoint).")) - self.gaps.append("training recipe: no history_fold*.json or model_fold*.pkl") + parts.append( + note("No training recipe recorded (no history or checkpoint).") + ) + self.gaps.append( + "training recipe: no history_fold*.json or model_fold*.pkl" + ) # per-fold table rows = [] @@ -505,35 +609,70 @@ def section_summary(self) -> str: n_test, len(entries) if entries else "-", fmt(fd.best_epoch) if fd.best_epoch is not None else "-", - fmt(h.get("stopped_after_epoch")) if h.get("stopped_after_epoch") is not None else "-", + fmt(h.get("stopped_after_epoch")) + if h.get("stopped_after_epoch") is not None + else "-", fd.n_parameters if fd.n_parameters is not None else "-", - fmt(h.get("finetune_trainable_parameters")) if h.get("finetune_trainable_parameters") is not None else "-", + fmt(h.get("finetune_trainable_parameters")) + if h.get("finetune_trainable_parameters") is not None + else "-", fmt(wall, 0) if wall is not None else "-", esc(", ".join(sorted(fd.splits))) or "-", ] ) parts.append( table( - ["fold", "validation folds", "training events", "validation events", "test events", "epochs run", "best epoch", "stopped after", "parameters", "fine-tuned parameters", "wall time [s]", "predictions"], + [ + "fold", + "validation folds", + "training events", + "validation events", + "test events", + "epochs run", + "best epoch", + "stopped after", + "parameters", + "fine-tuned parameters", + "wall time [s]", + "predictions", + ], rows, "Folds", ) ) if not wall_recorded: parts.append(note("Wall time: not recorded in the history files.")) - self.gaps.append("wall time: corenet-train does not record it in history_fold*.json") - if any(fd.history and fd.history.get("early_stop_patience") for fd in self.folds): - parts.append(note("Best epoch: the epoch with the highest validation AUC; its weights are the ones in the checkpoint (early stopping). 'Stopped after' is the epoch at which training stopped, '-' when every epoch was run.")) + self.gaps.append( + "wall time: corenet-train does not record it in history_fold*.json" + ) + if any( + fd.history and fd.history.get("early_stop_patience") for fd in self.folds + ): + parts.append( + note( + "Best epoch: the epoch with the highest validation AUC; its weights are the ones in the checkpoint (early stopping). 'Stopped after' is the epoch at which training stopped, '-' when every epoch was run." + ) + ) else: - parts.append(note("Best epoch: the epoch with the highest validation AUC in the history; without early stopping the checkpoint holds the weights after the last epoch.")) + parts.append( + note( + "Best epoch: the epoch with the highest validation AUC in the history; without early stopping the checkpoint holds the weights after the last epoch." + ) + ) return "".join(parts) def section_training(self) -> str: - with_hist = [fd for fd in self.folds if fd.history and fd.history.get("history")] + with_hist = [ + fd for fd in self.folds if fd.history and fd.history.get("history") + ] if not with_hist: self.gaps.append("training curves: no history_fold*.json with epochs") return note("No history file with epochs: no training curves.") - keys = [("train_loss", "training loss"), ("val_loss", "validation loss"), ("val_auc", "validation AUC")] + keys = [ + ("train_loss", "training loss"), + ("val_loss", "validation loss"), + ("val_auc", "validation AUC"), + ] fig, axes = plt.subplots(1, 3, figsize=(9.6, 2.9)) any_val = False for i, (key, lab) in enumerate(keys): @@ -545,23 +684,56 @@ def section_training(self) -> str: if not ep: continue any_val |= key != "train_loss" - ax.plot(ep, val, "-", color=f"C{j % 10}", lw=1.2, label=f"fold {fd.fold}") + ax.plot( + ep, val, "-", color=f"C{j % 10}", lw=1.2, label=f"fold {fd.fold}" + ) best = fd.best_epoch if best is not None and best in ep: - ax.plot([best], [val[ep.index(best)]], "*", color=f"C{j % 10}", ms=9) + ax.plot( + [best], [val[ep.index(best)]], "*", color=f"C{j % 10}", ms=9 + ) ax.set_xlabel("epoch") ax.set_ylabel(lab) ax.grid(alpha=0.25, lw=0.5) axes[0].legend(frameon=False) - out = figure(fig, "Training loss, validation loss and validation AUC per epoch, one line per fold; the star marks the best epoch (highest validation AUC).") + out = figure( + fig, + "Training loss, validation loss and validation AUC per epoch, one line per fold; the star marks the best epoch (highest validation AUC).", + ) if not any_val: - self.gaps.append("validation curves: the histories have no validation entries (train with --exclude-folds)") - out += note("No validation fold in the histories: validation loss and AUC are empty.") + self.gaps.append( + "validation curves: the histories have no validation entries (train with --exclude-folds)" + ) + out += note( + "No validation fold in the histories: validation loss and AUC are empty." + ) rows = [] for fd in with_hist: e = fd.history["history"][-1] - rows.append([fd.fold, e["epoch"], e.get("batch_size"), fmt(e.get("lr"), 6), e.get("train_loss"), e.get("val_loss"), e.get("val_auc")]) - out += table(["fold", "last epoch", "batch size", "learning rate", "training loss", "validation loss", "validation AUC"], rows, "Last epoch of every fold") + rows.append( + [ + fd.fold, + e["epoch"], + e.get("batch_size"), + fmt(e.get("lr"), 6), + e.get("train_loss"), + e.get("val_loss"), + e.get("val_auc"), + ] + ) + out += table( + [ + "fold", + "last epoch", + "batch size", + "learning rate", + "training loss", + "validation loss", + "validation AUC", + ], + rows, + "Last epoch of every fold", + ) return out # ---- classification @@ -580,12 +752,18 @@ def _main_curves(self): def section_classification(self) -> str: if not any("test" in fd.splits for fd in self.folds): self.gaps.append("classification: no prediction file for any fold") - return note("No prediction file: no ROC curves, AUC table or score distributions.") + return note( + "No prediction file: no ROC curves, AUC table or score distributions." + ) parts = [] curves = self._main_curves() if not curves: - self.gaps.append("ROC curves: the predicted events have only one class (no signal or no background)") - parts.append(note("The predicted events hold a single class: no ROC curve.")) + self.gaps.append( + "ROC curves: the predicted events have only one class (no signal or no background)" + ) + parts.append( + note("The predicted events hold a single class: no ROC curve.") + ) else: fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.4)) colors = {"test": "C0", "train": "C3", "validation": "C2"} @@ -600,9 +778,23 @@ def section_classification(self) -> str: if name == "test": for _, f, t, _ in cs: ax.plot(f, t, color=colors[name], lw=0.6, alpha=0.35) - ax.plot(ROC_GRID, mu, color=colors[name], ls=SPLIT_STYLE[name], lw=1.5, label=lab if ax is a else None) + ax.plot( + ROC_GRID, + mu, + color=colors[name], + ls=SPLIT_STYLE[name], + lw=1.5, + label=lab if ax is a else None, + ) if sd is not None: - ax.fill_between(ROC_GRID, mu - sd, mu + sd, color=colors[name], alpha=0.2, lw=0) + ax.fill_between( + ROC_GRID, + mu - sd, + mu + sd, + color=colors[name], + alpha=0.2, + lw=0, + ) a.plot([0, 1], [0, 1], "k:", lw=0.8) a.set_xlabel("background efficiency") a.set_ylabel("signal efficiency") @@ -616,7 +808,12 @@ def section_classification(self) -> str: b.set_xlabel("background efficiency (log)") b.set_title("(b)", loc="left") b.grid(alpha=0.25, which="both", lw=0.5) - parts.append(figure(fig, f"ROC of the main score P({self.classes[1]}) (class 1 against every other class, weighted): thin lines are the test folds, thick lines the mean over folds with the ± 1 sd band; dashed = training folds, dash-dotted = validation fold, where predictions exist.")) + parts.append( + figure( + fig, + f"ROC of the main score P({self.classes[1]}) (class 1 against every other class, weighted): thin lines are the test folds, thick lines the mean over folds with the ± 1 sd band; dashed = training folds, dash-dotted = validation fold, where predictions exist.", + ) + ) # AUC table rows = [] folds = sorted({c[0] for cs in curves.values() for c in cs}) @@ -626,11 +823,24 @@ def section_classification(self) -> str: v = next((c[3] for c in curves.get(name, []) if c[0] == k), None) row.append(fmt(v) if v is not None else "-") rows.append(row) - rows.append(["mean ± sd"] + [mean_sd([c[3] for c in curves.get(name, [])]) for name in SPLITS]) - parts.append(table(["fold", "test", "validation", "train"], rows, "AUC of the main score (sd over folds, ddof = 1)")) + rows.append( + ["mean ± sd"] + + [mean_sd([c[3] for c in curves.get(name, [])]) for name in SPLITS] + ) + parts.append( + table( + ["fold", "test", "validation", "train"], + rows, + "AUC of the main score (sd over folds, ddof = 1)", + ) + ) for name in ("validation", "train"): if name not in curves: - parts.append(note(f"No predictions on the {name} folds (corenet-evaluate --fold -1 provides them).")) + parts.append( + note( + f"No predictions on the {name} folds (corenet-evaluate --fold -1 provides them)." + ) + ) # score distributions parts.append(self._score_figure()) @@ -685,7 +895,15 @@ def _confusion_figure(self) -> str: im = ax.imshow(norm[present], cmap="Blues", vmin=0, vmax=1) for a, i in enumerate(present): for j in range(n): - ax.text(j, a, f"{norm[i, j]:.3f}", ha="center", va="center", color="white" if norm[i, j] > 0.6 else "black", fontsize=8) + ax.text( + j, + a, + f"{norm[i, j]:.3f}", + ha="center", + va="center", + color="white" if norm[i, j] > 0.6 else "black", + fontsize=8, + ) ax.set_xticks(range(n)) ax.set_xticklabels(self.classes) ax.set_yticks(range(len(present))) @@ -693,24 +911,49 @@ def _confusion_figure(self) -> str: ax.set_xlabel("predicted class (argmax)") ax.set_ylabel("true class") fig.colorbar(im, ax=ax, fraction=0.046) - return figure(fig, "Confusion matrix at the argmax of the class probabilities on the test folds, weighted, each true class normalised to 1.") + return figure( + fig, + "Confusion matrix at the argmax of the class probabilities on the test folds, weighted, each true class normalised to 1.", + ) def _ovr_and_heads_figure(self) -> str: test = self.splits_of("test") parts = [] - n = len(self.classes) has_heads = any(s.heads for _, s in test) - fig, axes = plt.subplots(1, 2 if has_heads else 1, figsize=(7.8 if has_heads else 4.0, 3.4), squeeze=False) + fig, axes = plt.subplots( + 1, + 2 if has_heads else 1, + figsize=(7.8 if has_heads else 4.0, 3.4), + squeeze=False, + ) ax = axes[0, 0] rows = [] for i, c in enumerate(self.classes): - cs = [(fd.fold, *roc_points(s.label == i, s.probs[:, i], np.clip(s.weight, 0, None)), auc_of(s.label == i, s.probs[:, i], np.clip(s.weight, 0, None))) for fd, s in test if (s.label == i).any() and not (s.label == i).all()] + cs = [ + ( + fd.fold, + *roc_points( + s.label == i, s.probs[:, i], np.clip(s.weight, 0, None) + ), + auc_of(s.label == i, s.probs[:, i], np.clip(s.weight, 0, None)), + ) + for fd, s in test + if (s.label == i).any() and not (s.label == i).all() + ] if not cs: continue mu, sd = mean_curve([(f, t) for _, f, t, _ in cs]) - ax.plot(ROC_GRID, mu, color=class_color(i), lw=1.4, label=f"{c} vs rest AUC {mean_sd([x[3] for x in cs])}") + ax.plot( + ROC_GRID, + mu, + color=class_color(i), + lw=1.4, + label=f"{c} vs rest AUC {mean_sd([x[3] for x in cs])}", + ) if sd is not None: - ax.fill_between(ROC_GRID, mu - sd, mu + sd, color=class_color(i), alpha=0.2, lw=0) + ax.fill_between( + ROC_GRID, mu - sd, mu + sd, color=class_color(i), alpha=0.2, lw=0 + ) rows.append([f"P({c}) vs label = {c}", mean_sd([x[3] for x in cs])]) ax.plot([0, 1], [0, 1], "k:", lw=0.8) ax.set_xlabel("efficiency of the other classes") @@ -723,21 +966,64 @@ def _ovr_and_heads_figure(self) -> str: i = self.classes.index(name) if name in self.classes else None if i is None: continue - cs = [(fd.fold, *roc_points(s.label == i, s.heads[name], np.clip(s.weight, 0, None)), auc_of(s.label == i, s.heads[name], np.clip(s.weight, 0, None))) for fd, s in test if name in s.heads and (s.label == i).any() and not (s.label == i).all()] + cs = [ + ( + fd.fold, + *roc_points( + s.label == i, s.heads[name], np.clip(s.weight, 0, None) + ), + auc_of(s.label == i, s.heads[name], np.clip(s.weight, 0, None)), + ) + for fd, s in test + if name in s.heads + and (s.label == i).any() + and not (s.label == i).all() + ] if not cs: continue mu, sd = mean_curve([(f, t) for _, f, t, _ in cs]) - ax.plot(ROC_GRID, mu, color=class_color(i), lw=1.4, label=f"head {name} AUC {mean_sd([x[3] for x in cs])}") + ax.plot( + ROC_GRID, + mu, + color=class_color(i), + lw=1.4, + label=f"head {name} AUC {mean_sd([x[3] for x in cs])}", + ) if sd is not None: - ax.fill_between(ROC_GRID, mu - sd, mu + sd, color=class_color(i), alpha=0.2, lw=0) - rows.append([f"head {name} vs label = {name}", mean_sd([x[3] for x in cs])]) + ax.fill_between( + ROC_GRID, + mu - sd, + mu + sd, + color=class_color(i), + alpha=0.2, + lw=0, + ) + rows.append( + [f"head {name} vs label = {name}", mean_sd([x[3] for x in cs])] + ) ax.plot([0, 1], [0, 1], "k:", lw=0.8) ax.set_xlabel("efficiency of the other classes") ax.set_ylabel("efficiency of the class") ax.set_title("(b) auxiliary heads", loc="left") ax.legend(loc="lower right", frameon=False) - parts.append(figure(fig, "Test folds, mean over folds with the ± 1 sd band: (a) every class scored by its own probability against all other classes" + ("; (b) the auxiliary head of every further output against its class." if has_heads else "."))) - parts.append(table(["score", "AUC (mean ± sd over test folds)"], rows, "One-against-the-rest and auxiliary-head AUC")) + parts.append( + figure( + fig, + "Test folds, mean over folds with the ± 1 sd band: (a) every class scored by its own probability against all other classes" + + ( + "; (b) the auxiliary head of every further output against its class." + if has_heads + else "." + ), + ) + ) + parts.append( + table( + ["score", "AUC (mean ± sd over test folds)"], + rows, + "One-against-the-rest and auxiliary-head AUC", + ) + ) return "".join(parts) # ---- hypotheses and pairing @@ -747,7 +1033,11 @@ def section_hypotheses(self) -> str: parts = [] if not hyps: if test: - parts.append(note("Every hypothesis has a single candidate: no view probabilities.")) + parts.append( + note( + "Every hypothesis has a single candidate: no view probabilities." + ) + ) else: self.gaps.append("hypotheses: no prediction file") parts.append(note("No prediction file: no view probabilities.")) @@ -763,10 +1053,20 @@ def section_hypotheses(self) -> str: mx = np.concatenate([s.views[h].max(1) for _, s in sp]) lab = np.concatenate([s.label for _, s in sp]) w = np.concatenate([s.weight for _, s in sp]) - series = [(f"{c} ({name})", v, ww, st) for c, v, ww, st in self.class_series(mx, lab, w, {"ls": SPLIT_STYLE[name]})] + series = [ + (f"{c} ({name})", v, ww, st) + for c, v, ww, st in self.class_series( + mx, lab, w, {"ls": SPLIT_STYLE[name]} + ) + ] hist_panel(ax, series, bins, f"max view probability, {h} ({V} views)") ax.legend(frameon=False) - parts.append(figure(fig, "Highest view probability per event and class on the test folds (dashed: training folds when available). The views of a hypothesis are its candidate assignments, e.g. the pairings of the b jets into two Higgs bosons.")) + parts.append( + figure( + fig, + "Highest view probability per event and class on the test folds (dashed: training folds when available). The views of a hypothesis are its candidate assignments, e.g. the pairings of the b jets into two Higgs bosons.", + ) + ) # argmax view shares rows = [] for h in hyps: @@ -786,7 +1086,13 @@ def section_hypotheses(self) -> str: if counts.sum() > 0: rows.append([h, c] + [fmt(x) for x in counts / counts.sum()]) if rows: - parts.append(table(["hypothesis", "class"] + names, [r for r in rows if r[0] == h], f"Weighted share of the argmax view, test folds: {h}")) + parts.append( + table( + ["hypothesis", "class", *names], + [r for r in rows if r[0] == h], + f"Weighted share of the argmax view, test folds: {h}", + ) + ) parts.append(self._pairing_accuracy(test, hyps)) return "".join(parts) @@ -796,7 +1102,9 @@ def _view_names(self, h: str, V: int) -> list[str]: return [f"view {v}" for v in range(V)] names = [] for view in T.views: - names.append("|".join("".join(str(slot) for _, slot in child) for child in view)) + names.append( + "|".join("".join(str(slot) for _, slot in child) for child in view) + ) return names def _targets(self) -> dict[str, dict[str, np.ndarray]]: @@ -808,7 +1116,14 @@ def _targets(self) -> dict[str, dict[str, np.ndarray]]: grp = f["TARGETS"][g] if not isinstance(grp, h5py.Group): continue - leaves = {k: grp[k][...].astype(np.int64) for k in grp if isinstance(grp[k], h5py.Dataset) and grp[k].dtype.kind in "iu" and grp[k].ndim == 1 and len(grp[k]) == len(self.ds)} + leaves = { + k: grp[k][...].astype(np.int64) + for k in grp + if isinstance(grp[k], h5py.Dataset) + and grp[k].dtype.kind in "iu" + and grp[k].ndim == 1 + and len(grp[k]) == len(self.ds) + } if leaves: out[g] = leaves return out @@ -832,8 +1147,12 @@ def rec(declared, canonical, cand): def _pairing_accuracy(self, test, hyps) -> str: targets = self._targets() if not targets: - self.gaps.append("pairing accuracy: the input file has no TARGETS group (generator-matched jets)") - return note("No TARGETS in the input file: the pairing accuracy against the generator matching cannot be computed.") + self.gaps.append( + "pairing accuracy: the input file has no TARGETS group (generator-matched jets)" + ) + return note( + "No TARGETS in the input file: the pairing accuracy against the generator matching cannot be computed." + ) parts = [] sel = self.ds.selected for h in hyps: @@ -842,10 +1161,18 @@ def _pairing_accuracy(self, test, hyps) -> str: if T is None or len(T.views) != V: continue declared = self.spec.nodes_in(h) - matched = {g: n for g in targets for n in declared if norm_name(g) == norm_name(n)} + matched = { + g: n for g in targets for n in declared if norm_name(g) == norm_name(n) + } if not matched: - self.gaps.append(f"pairing accuracy of {h}: no TARGETS group named like one of its nodes ({sorted(declared)}; TARGETS has {sorted(targets)})") - parts.append(note(f"{h}: no TARGETS group matches a node of the hypothesis ({', '.join(sorted(declared))}); TARGETS groups: {', '.join(sorted(targets))}.")) + self.gaps.append( + f"pairing accuracy of {h}: no TARGETS group named like one of its nodes ({sorted(declared)}; TARGETS has {sorted(targets)})" + ) + parts.append( + note( + f"{h}: no TARGETS group matches a node of the hypothesis ({', '.join(sorted(declared))}); TARGETS groups: {', '.join(sorted(targets))}." + ) + ) continue # per matched node: the sorted file slots of its generator-matched jets (truth) and of its # candidate under every view; sibling nodes that are interchangeable (H1 / H2) are compared as @@ -859,29 +1186,49 @@ def _pairing_accuracy(self, test, hyps) -> str: for g, node in matched.items(): truth = np.stack(list(targets[g].values()), 1) # (n, k) file slots assignments = [self._view_assignments(h, v).get(node) for v in range(V)] - pairs = [[(r, s) for r, s in a if r in sel] if a is not None else None for a in assignments] + pairs = [ + [(r, s) for r, s in a if r in sel] if a is not None else None + for a in assignments + ] if any(p is None or len(p) != truth.shape[1] for p in pairs): continue # the group lists a different number of jets than the node has candidates usable.append((g, node)) complete &= (truth >= 0).all(1) roles = sorted({r for p in pairs for r, _ in p}) - pool = np.concatenate([sel[r] for r in roles], 1) # (n, slots) file slots of the roles + pool = np.concatenate( + [sel[r] for r in roles], 1 + ) # (n, slots) file slots of the roles for col in range(truth.shape[1]): contained &= (pool == truth[:, col : col + 1]).any(1) truth_of[node] = np.sort(truth, 1) - views_of[node] = [np.sort(np.stack([sel[r][:, slot] for r, slot in p], 1), 1) for p in pairs] + views_of[node] = [ + np.sort(np.stack([sel[r][:, slot] for r, slot in p], 1), 1) + for p in pairs + ] # groups of interchangeable siblings that are all matched grouped, groups = set(), [] for parent in declared: nt = T.nodes.get(T.aliases.get(parent, parent)) - kids = self.spec.nodes[parent].children if parent in self.spec.nodes else [] - if nt is not None and nt.symmetric_children and len(kids) > 1 and all(k in truth_of for k in kids): + kids = ( + self.spec.nodes[parent].children + if parent in self.spec.nodes + else [] + ) + if ( + nt is not None + and nt.symmetric_children + and len(kids) > 1 + and all(k in truth_of for k in kids) + ): groups.append(list(kids)) grouped.update(kids) def key(slots): # one integer per sorted slot tuple base = 1 << 16 - return sum((slots[:, j].astype(np.int64) + 1) * base**j for j in range(slots.shape[1])) + return sum( + (slots[:, j].astype(np.int64) + 1) * base**j + for j in range(slots.shape[1]) + ) for node in truth_of: if node in grouped: @@ -891,13 +1238,26 @@ def key(slots): # one integer per sorted slot tuple for kids in groups: t = np.sort(np.stack([key(truth_of[k]) for k in kids], 1), 1) for v in range(V): - correct[v] &= (np.sort(np.stack([key(views_of[k][v]) for k in kids], 1), 1) == t).all(1) + correct[v] &= ( + np.sort(np.stack([key(views_of[k][v]) for k in kids], 1), 1) + == t + ).all(1) if not usable: - parts.append(note(f"{h}: the matched TARGETS groups ({', '.join(matched)}) list a different number of jets than the nodes they name.")) + parts.append( + note( + f"{h}: the matched TARGETS groups ({', '.join(matched)}) list a different number of jets than the nodes they name." + ) + ) continue if all(np.array_equal(correct[0], correct[v]) for v in range(1, V)): - parts.append(note(f"{h}: the TARGETS groups {', '.join(g for g, _ in usable)} do not distinguish the {V} views (every view assigns their jets the same way): no pairing accuracy.")) - self.gaps.append(f"pairing accuracy of {h}: the TARGETS groups do not distinguish its views") + parts.append( + note( + f"{h}: the TARGETS groups {', '.join(g for g, _ in usable)} do not distinguish the {V} views (every view assigns their jets the same way): no pairing accuracy." + ) + ) + self.gaps.append( + f"pairing accuracy of {h}: the TARGETS groups do not distinguish its views" + ) continue rows = [] per_fold = [] @@ -913,24 +1273,71 @@ def key(slots): # one integer per sorted slot tuple acc_m = ok[comp].mean() if comp.any() else np.nan acc_c = ok[cont].mean() if cont.any() else np.nan per_fold.append((acc_m, acc_c)) - rows.append([fd.fold, int(comp.sum()), int(cont.sum()), fmt(acc_m), fmt(acc_c)]) + rows.append( + [fd.fold, int(comp.sum()), int(cont.sum()), fmt(acc_m), fmt(acc_c)] + ) thr = [1.0 / V] + [t for t in VIEW_THRESHOLDS if t > 1.0 / V + 1e-9] - thr_rows[fd.fold] = [(t, ok[cont & (mx > t)].mean() if (cont & (mx > t)).any() else np.nan, int((cont & (mx > t)).sum())) for t in thr] + thr_rows[fd.fold] = [ + ( + t, + ok[cont & (mx > t)].mean() + if (cont & (mx > t)).any() + else np.nan, + int((cont & (mx > t)).sum()), + ) + for t in thr + ] if not rows: continue - rows.append(["mean ± sd", "", "", mean_sd([a for a, _ in per_fold]), mean_sd([c for _, c in per_fold])]) - parts.append(table(["fold", "events with complete truth", "of which contained", "accuracy (complete)", "accuracy (contained)"], rows, f"Pairing accuracy of the argmax view of {h} against TARGETS {', '.join(g for g, _ in usable)} (random: 1/{V} = {1.0 / V:.3f})")) + rows.append( + [ + "mean ± sd", + "", + "", + mean_sd([a for a, _ in per_fold]), + mean_sd([c for _, c in per_fold]), + ] + ) + parts.append( + table( + [ + "fold", + "events with complete truth", + "of which contained", + "accuracy (complete)", + "accuracy (contained)", + ], + rows, + f"Pairing accuracy of the argmax view of {h} against TARGETS {', '.join(g for g, _ in usable)} (random: 1/{V} = {1.0 / V:.3f})", + ) + ) fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.2)) thr = [t for t, _, _ in next(iter(thr_rows.values()))] accs = np.array([[acc for _, acc, _ in thr_rows[k]] for k in thr_rows]) ns = np.array([[nn for _, _, nn in thr_rows[k]] for k in thr_rows]).sum(0) x = np.arange(len(thr)) for j, k in enumerate(thr_rows): - a.plot(x, 100 * accs[j], "-", color=f"C{j % 10}", lw=0.8, alpha=0.5, label=f"fold {k}") - mu = np.nanmean(accs, 0) + a.plot( + x, + 100 * accs[j], + "-", + color=f"C{j % 10}", + lw=0.8, + alpha=0.5, + label=f"fold {k}", + ) + cnt = np.isfinite(accs).sum(0) + mu = np.where(cnt > 0, np.nansum(accs, 0) / np.maximum(cnt, 1), np.nan) a.plot(x, 100 * mu, "o-", color="k", lw=1.4, ms=4, label="mean over folds") for xi, (m, nn) in enumerate(zip(mu, ns)): - a.annotate(f"N = {nn:,}", (xi, 100 * m), textcoords="offset points", xytext=(0, 7), ha="center", fontsize=6) + a.annotate( + f"N = {nn:,}", + (xi, 100 * m), + textcoords="offset points", + xytext=(0, 7), + ha="center", + fontsize=6, + ) a.axhline(100.0 / V, color="k", ls="--", lw=0.8) a.set_xticks(x) a.set_xticklabels([f"> {t:.2f}" for t in thr]) @@ -948,22 +1355,51 @@ def key(slots): # one integer per sorted slot tuple am, mx = s.views[h].argmax(1), s.views[h].max(1) ok = correct[am, idx] which = np.clip(np.digitize(mx, edges) - 1, 0, len(edges) - 2) - acc = [ok[cont & (which == b)].mean() if (cont & (which == b)).any() else np.nan for b in range(len(edges) - 1)] - b.plot(0.5 * (edges[1:] + edges[:-1]), 100 * np.array(acc), "o-", color=f"C{j % 10}", lw=1.0, ms=3, label=f"fold {fd.fold}") - b.plot([1.0 / V, 1], [100.0 / V, 100], "k:", lw=0.8, label="perfect calibration") + acc = [ + ok[cont & (which == b)].mean() + if (cont & (which == b)).any() + else np.nan + for b in range(len(edges) - 1) + ] + b.plot( + 0.5 * (edges[1:] + edges[:-1]), + 100 * np.array(acc), + "o-", + color=f"C{j % 10}", + lw=1.0, + ms=3, + label=f"fold {fd.fold}", + ) + b.plot( + [1.0 / V, 1], + [100.0 / V, 100], + "k:", + lw=0.8, + label="perfect calibration", + ) b.set_xlabel(f"max view probability of {h}") b.set_ylabel("pairing accuracy [%]") b.set_ylim(0, 105) b.legend(frameon=False) b.grid(alpha=0.25, lw=0.5) b.set_title("(b) accuracy per probability bin", loc="left") - parts.append(figure(fig, f"Pairing accuracy of {h} on contained events of the test folds (all generator-matched jets among the candidates): (a) for events whose highest view probability exceeds a threshold, N summed over folds, dashed = random; (b) in bins of the highest view probability, dotted = accuracy equal to the probability.")) + parts.append( + figure( + fig, + f"Pairing accuracy of {h} on contained events of the test folds (all generator-matched jets among the candidates): (a) for events whose highest view probability exceeds a threshold, N summed over folds, dashed = random; (b) in bins of the highest view probability, dotted = accuracy equal to the probability.", + ) + ) return "".join(parts) # ---- inputs as the network sees them def _node_phi_label(self, h: str, node: str) -> str: T = self.model.tables[h] - parents = [(pn, j) for pn in self.model.levels[h] for j, c in enumerate(T.nodes[pn].children) if c == node] + parents = [ + (pn, j) + for pn in self.model.levels[h] + for j, c in enumerate(T.nodes[pn].children) + if c == node + ] pnodes = {pn for pn, _ in parents} if len(pnodes) == 1: pnode = next(iter(pnodes)) @@ -981,8 +1417,12 @@ def collect_network_inputs(self, idx: np.ndarray, chunk: int = 16384) -> dict: def add(key, names, x, present, rows): x = x.detach().cpu().numpy() - n, F, P = x.shape - pres = np.ones((n, P), bool) if present is None else present.detach().cpu().numpy().astype(bool) + n, _, P = x.shape + pres = ( + np.ones((n, P), bool) + if present is None + else present.detach().cpu().numpy().astype(bool) + ) vals = x.transpose(0, 2, 1)[pres] lab = np.broadcast_to(self.labels[rows][:, None], (n, P))[pres] w = np.broadcast_to(self.weights[rows][:, None], (n, P))[pres] @@ -1001,7 +1441,13 @@ def event_name(name): inputs = {k: v[sel] for k, v in self.ds.inputs.items()} prep = model._prepare(inputs) if prep["event"] is not None: - add("event scalars", [event_name(n) for n in spec.event], prep["event"], None, rows) + add( + "event scalars", + [event_name(n) for n in spec.event], + prep["event"], + None, + rows, + ) seen = set() for h, T in model.tables.items(): hp = prep["hyp"][h] @@ -1014,25 +1460,78 @@ def event_name(name): names = ["log(1+pT)", "η", f"Δφ to {node}", "log(1+m)"] if child in model.leaves: names += model._extras(child) - add(f"{node} ← {child}", names, hp["slot_feats"][node][j], hp["slot_present"][node][j], rows) + add( + f"{node} ← {child}", + names, + hp["slot_feats"][node][j], + hp["slot_present"][node][j], + rows, + ) if node in model.tops: names = ["log(1+pT)", "η", "log(1+m)"] else: owner = spec.owner.get(node, h) owner = owner if node in model.levels.get(owner, []) else h - names = ["log(1+pT)", "η", self._node_phi_label(owner, node), "log(1+m)"] - add(f"{node} candidates", names, prep["embed_in"][node], prep["present"][node], rows) + names = [ + "log(1+pT)", + "η", + self._node_phi_label(owner, node), + "log(1+m)", + ] + add( + f"{node} candidates", + names, + prep["embed_in"][node], + prep["present"][node], + rows, + ) if "context" in hp: c = hp["context"] - add(f"{h} context: {spec.hypotheses[h].context} and the candidates' jets", ["log(1+pT)", "η", "log(1+m)", "flag (2 = candidate jet, 1 = context jet)"], c["feats"], ~c["mask"], rows) + add( + f"{h} context: {spec.hypotheses[h].context} and the candidates' jets", + [ + "log(1+pT)", + "η", + "log(1+m)", + "flag (2 = candidate jet, 1 = context jet)", + ], + c["feats"], + ~c["mask"], + rows, + ) for key, r in prep["relations"].items(): - add(f"relation {key.replace('|', ' - ')}", ["log(1+M)", "ΔR", "Δφ"], r, None, rows) - return {k: (names, np.concatenate(v), np.concatenate(l), np.concatenate(w)) for k, (names, v, l, w) in acc.items()} + add( + f"relation {key.replace('|', ' - ')}", + ["log(1+M)", "ΔR", "Δφ"], + r, + None, + rows, + ) + return { + k: (names, np.concatenate(v), np.concatenate(lab), np.concatenate(w)) + for k, (names, v, lab, w) in acc.items() + } def section_inputs(self) -> str: idx = self.selected_subset(self.args.max_events) data = self.collect_network_inputs(idx) - parts = [note(f"Distributions of the quantities the network embeds, computed from the input file by the loader and the network's own preparation step, over {len(idx):,} events" + (" (a random subsample; --max-events)" if len(idx) < len(self.ds) else "") + f" and all present candidates; weighted by the event weight (clipped at 0), each class normalised to unit area. Jet features: log(1+pT), η" + (" (reflected so that the leading jet of the first role has η ≥ 0)" if self.spec.training.reflect_eta else "") + ", Δφ to the parent candidate, log(1+m).")] + parts = [ + note( + f"Distributions of the quantities the network embeds, computed from the input file by the loader and the network's own preparation step, over {len(idx):,} events" + + ( + " (a random subsample; --max-events)" + if len(idx) < len(self.ds) + else "" + ) + + " and all present candidates; weighted by the event weight (clipped at 0), each class normalised to unit area. Jet features: log(1+pT), η" + + ( + " (reflected so that the leading jet of the first role has η ≥ 0)" + if self.spec.training.reflect_eta + else "" + ) + + ", Δφ to the parent candidate, log(1+m)." + ) + ] for key, (names, vals, lab, w) in data.items(): fig, axes = grid_figure(len(names), per_row=6) for ax, j, name in zip(axes, range(len(names)), names): @@ -1047,7 +1546,13 @@ def section_raw(self) -> str: ds, spec = self.ds, self.spec idx = self.selected_subset(self.args.max_events) lab, w = self.labels[idx], self.weights[idx] - parts = [note(f"The features of the input file for the members each role selected (per slot), the single objects and the event scalars, before any transformation; {len(idx):,} events" + (" (random subsample)" if len(idx) < len(ds) else "") + ", weighted, each class normalised to unit area. A column read for the selection only (e.g. btag) is shown for the selected jets as well.")] + parts = [ + note( + f"The features of the input file for the members each role selected (per slot), the single objects and the event scalars, before any transformation; {len(idx):,} events" + + (" (random subsample)" if len(idx) < len(ds) else "") + + ", weighted, each class normalised to unit area. A column read for the selection only (e.g. btag) is shown for the selected jets as well." + ) + ] extra_cols = {} with h5py.File(self.input, "r") as f: for role in spec.roles.values(): @@ -1055,7 +1560,11 @@ def section_raw(self) -> str: cols = [c for c in role.columns if c not in coll.features] if cols: group = f["INPUTS"][resolve_group(f, coll.name)] - extra_cols[role.name] = {c: np.atleast_2d(group[c][...].astype(np.float32).T).T for c in cols if c in group} + extra_cols[role.name] = { + c: np.atleast_2d(group[c][...].astype(np.float32).T).T + for c in cols + if c in group + } for role in spec.roles.values(): coll = spec.collections[role.collection] x = ds.inputs[role.name][idx].numpy() # (n, F+1, slots) @@ -1064,13 +1573,22 @@ def section_raw(self) -> str: extra = extra_cols.get(role.name, {}) n_slots = x.shape[2] names = feats + list(extra) - fig, axes = plt.subplots(len(names), n_slots, figsize=(2.3 * n_slots, 1.9 * len(names)), squeeze=False) + fig, axes = plt.subplots( + len(names), + n_slots, + figsize=(2.3 * n_slots, 1.9 * len(names)), + squeeze=False, + ) for i, name in enumerate(names): if name in feats: col = x[:, feats.index(name)] else: slots = ds.selected[role.name][idx] - col = np.where(slots >= 0, extra[name][idx[:, None], np.clip(slots, 0, None)], np.nan) + col = np.where( + slots >= 0, + extra[name][idx[:, None], np.clip(slots, 0, None)], + np.nan, + ) bins = shared_bins([col[present]]) for s in range(n_slots): ax = axes[i, s] @@ -1078,29 +1596,57 @@ def section_raw(self) -> str: series = self.class_series(col[ok, s], lab[ok], w[ok]) hist_panel(ax, series, bins, f"{name} [{role.name} slot {s}]") axes[0, 0].legend(frameon=False) - sel_text = f"{role.collection} {role.selector} {role.n}" + (" lowest" if role.ascending else "") - parts.append(figure(fig, f"Role {role.name} ({sel_text}): rows = features, columns = slots in selection order; empty slots are left out.", dpi=90)) - singles = [c for c in spec.collections.values() if c.max == 1 and c.name in ds.inputs] + sel_text = f"{role.collection} {role.selector} {role.n}" + ( + " lowest" if role.ascending else "" + ) + parts.append( + figure( + fig, + f"Role {role.name} ({sel_text}): rows = features, columns = slots in selection order; empty slots are left out.", + dpi=90, + ) + ) + singles = [ + c for c in spec.collections.values() if c.max == 1 and c.name in ds.inputs + ] for c in singles: x = ds.inputs[c.name][idx].numpy() present = x[:, -1, 0] > 0 fig, axes = grid_figure(len(c.features), per_row=6) for ax, j, name in zip(axes, range(len(c.features)), c.features): series = self.class_series(x[present, j, 0], lab[present], w[present]) - hist_panel(ax, series, shared_bins([v for _, v, _, _ in series]), f"{name} [{c.name}]") + hist_panel( + ax, + series, + shared_bins([v for _, v, _, _ in series]), + f"{name} [{c.name}]", + ) axes[0].legend(frameon=False) - parts.append(figure(fig, f"Single object {c.name}: {', '.join(c.features)}.")) + parts.append( + figure(fig, f"Single object {c.name}: {', '.join(c.features)}.") + ) if spec.event: ev = ds.inputs["event"][idx].numpy() fig, axes = grid_figure(len(spec.event), per_row=6) for ax, j, name in zip(axes, range(len(spec.event)), spec.event): kind, where = event_source(spec, name) series = self.class_series(ev[:, j], lab, w) - hist_panel(ax, series, shared_bins([v for _, v, _, _ in series]), f"{name} ({'computed from ' + where if kind == 'computed' else where})") + hist_panel( + ax, + series, + shared_bins([v for _, v, _, _ in series]), + f"{name} ({'computed from ' + where if kind == 'computed' else where})", + ) axes[0].legend(frameon=False) - parts.append(figure(fig, "Event scalars as read or computed by the loader.")) + parts.append( + figure(fig, "Event scalars as read or computed by the loader.") + ) if not spec.roles and not singles and not spec.event: - parts.append(note("The configuration declares no roles, single objects or event scalars.")) + parts.append( + note( + "The configuration declares no roles, single objects or event scalars." + ) + ) return "".join(parts) # ---- weights @@ -1112,9 +1658,16 @@ def section_weights(self) -> str: for i, c in enumerate(self.classes): sel = lab == i if sel.any(): - series.append((c, w[sel], np.ones(int(sel.sum())), {"color": class_color(i), "lw": 1.3})) + series.append( + ( + c, + w[sel], + np.ones(int(sel.sum())), + {"color": class_color(i), "lw": 1.3}, + ) + ) bins = shared_bins([v for _, v, _, _ in series], 60) - for lab_c, v, ww, st in series: + for lab_c, v, _, st in series: a.hist(v, bins=bins, histtype="step", label=lab_c, **st) a.set_yscale("log") a.set_xlabel("event weight (as in the file)") @@ -1127,15 +1680,29 @@ def section_weights(self) -> str: tot = np.clip(w[sel], 0, None).sum() if tot > 0: normed[sel] = np.clip(w[sel], 0, None) / tot - series = [(c, normed[lab == i], np.ones(int((lab == i).sum())), {"color": class_color(i), "lw": 1.3}) for i, c in enumerate(self.classes) if (lab == i).any()] + series = [ + ( + c, + normed[lab == i], + np.ones(int((lab == i).sum())), + {"color": class_color(i), "lw": 1.3}, + ) + for i, c in enumerate(self.classes) + if (lab == i).any() + ] bins = shared_bins([v for _, v, _, _ in series], 60) - for lab_c, v, ww, st in series: + for lab_c, v, _, st in series: b.hist(v, bins=bins, histtype="step", label=lab_c, **st) b.set_yscale("log") b.set_xlabel("class-normalised weight (clipped at 0, class sum = 1)") b.set_ylabel("events") b.set_title("(b) as training uses them", loc="left") - parts.append(figure(fig, "Event weights per class over the whole input file: (a) as stored; (b) clipped at 0 and divided by the class sum, which is how the training loss weights an event (the training normalises over its own training events of every fold).")) + parts.append( + figure( + fig, + "Event weights per class over the whole input file: (a) as stored; (b) clipped at 0 and divided by the class sum, which is how the training loss weights an event (the training normalises over its own training events of every fold).", + ) + ) rows = [] for i, c in enumerate(self.classes): sel = lab == i @@ -1144,33 +1711,90 @@ def section_weights(self) -> str: ws = w[sel] s1, s2 = ws.sum(), (ws**2).sum() neff = s1**2 / s2 if s2 > 0 else 0.0 - rows.append([c, int(sel.sum()), float(s1), float(ws.min()), float(ws.max()), float(ws.mean()), float(ws.std()), fmt(neff, 1), fmt(neff / sel.sum(), 4), int((ws < 0).sum()), fmt(abs(ws[ws < 0].sum()) / s1 if s1 > 0 else np.nan)]) - parts.append(table(["class", "events", "sum", "min", "max", "mean", "sd", "effective events (sum w)^2 / sum w^2", "effective / events", "negative weights", "|negative sum| / sum"], rows, "Weight statistics per class (whole file)")) + rows.append( + [ + c, + int(sel.sum()), + float(s1), + float(ws.min()), + float(ws.max()), + float(ws.mean()), + float(ws.std()), + fmt(neff, 1), + fmt(neff / sel.sum(), 4), + int((ws < 0).sum()), + fmt(abs(ws[ws < 0].sum()) / s1 if s1 > 0 else np.nan), + ] + ) + parts.append( + table( + [ + "class", + "events", + "sum", + "min", + "max", + "mean", + "sd", + "effective events (sum w)^2 / sum w^2", + "effective / events", + "negative weights", + "|negative sum| / sum", + ], + rows, + "Weight statistics per class (whole file)", + ) + ) folds = sorted(np.unique(self.fold_of).tolist()) rows = [] for k in folds: fsel = self.fold_of == k row = [k, int(fsel.sum())] - for i, c in enumerate(self.classes): + for i in range(len(self.classes)): sel = fsel & (lab == i) tot = w[lab == i].sum() - row += [int(sel.sum()), float(w[sel].sum()), fmt(w[sel].sum() / tot if tot else np.nan, 3), int((w[sel] < 0).sum())] + row += [ + int(sel.sum()), + float(w[sel].sum()), + fmt(w[sel].sum() / tot if tot else np.nan, 3), + int((w[sel] < 0).sum()), + ] rows.append(row) - header = ["fold", "events"] + [f"{c}: {q}" for c in self.classes for q in ("events", "sum", "share", "negative")] - parts.append(table(header, rows, "Events and weights per fold and class (closure: every fold should carry about 1/n_folds of each class)")) + header = ["fold", "events"] + [ + f"{c}: {q}" + for c in self.classes + for q in ("events", "sum", "share", "negative") + ] + parts.append( + table( + header, + rows, + "Events and weights per fold and class (closure: every fold should carry about 1/n_folds of each class)", + ) + ) rows = [] for fd in self.folds: k = fd.fold excl = fd.exclude_folds or [] train = ~np.isin(self.fold_of, [k, *excl]) row = [k, esc(excl) if excl else "-"] - for i, c in enumerate(self.classes): + for i in range(len(self.classes)): sel = train & (lab == i) tot = np.clip(w[sel], 0, None).sum() row += [int(sel.sum()), float(tot), int((w[sel] < 0).sum())] rows.append(row) - header = ["held-out fold", "validation folds"] + [f"{c}: {q}" for c in self.classes for q in ("training events", "training sum", "negative (count as 0)")] - parts.append(table(header, rows, "Training set of every fold: the weights of every class are normalised to 1 over these events")) + header = ["held-out fold", "validation folds"] + [ + f"{c}: {q}" + for c in self.classes + for q in ("training events", "training sum", "negative (count as 0)") + ] + parts.append( + table( + header, + rows, + "Training set of every fold: the weights of every class are normalised to 1 over these events", + ) + ) return "".join(parts) # ---- other checks @@ -1189,12 +1813,21 @@ def section_other(self) -> str: present = x[:, -1] > 0 for s in (0, first_role.n - 1): if s < pt.shape[1]: - profiles.append((f"pT of {first_role.name} slot {s} [GeV]", np.where(present[:, s], pt[:, s], np.nan))) + profiles.append( + ( + f"pT of {first_role.name} slot {s} [GeV]", + np.where(present[:, s], pt[:, s], np.nan), + ) + ) for j, name in enumerate(spec.event): if "nSelJets" in name: profiles.append((name, ds.inputs["event"][idx].numpy()[:, j])) if not profiles: - parts.append(note("No jet role or jet multiplicity in the configuration: no weight profiles.")) + parts.append( + note( + "No jet role or jet multiplicity in the configuration: no weight profiles." + ) + ) return "".join(parts) fig, axes = grid_figure(len(profiles), per_row=3, w=3.2, h=2.6) for ax, (name, x) in zip(axes, profiles): @@ -1206,14 +1839,41 @@ def section_other(self) -> str: if not sel.any(): continue which = np.clip(np.digitize(x[sel], bins) - 1, 0, len(bins) - 2) - means = np.array([w[sel][which == b].mean() if (which == b).any() else np.nan for b in range(len(bins) - 1)]) - sems = np.array([w[sel][which == b].std() / np.sqrt((which == b).sum()) if (which == b).sum() > 1 else np.nan for b in range(len(bins) - 1)]) - ax.errorbar(centres, means, sems, fmt="o-", color=class_color(i), ms=3, lw=1.0, capsize=2, label=c) + means = np.array( + [ + w[sel][which == b].mean() if (which == b).any() else np.nan + for b in range(len(bins) - 1) + ] + ) + sems = np.array( + [ + w[sel][which == b].std() / np.sqrt((which == b).sum()) + if (which == b).sum() > 1 + else np.nan + for b in range(len(bins) - 1) + ] + ) + ax.errorbar( + centres, + means, + sems, + fmt="o-", + color=class_color(i), + ms=3, + lw=1.0, + capsize=2, + label=c, + ) ax.set_xlabel(name) ax.set_ylabel("mean event weight") ax.grid(alpha=0.25, lw=0.5) axes[0].legend(frameon=False) - parts.append(figure(fig, "Mean event weight (as stored) per class in bins of the leading and the last candidate jet pT of the first role and of the jet multiplicity; error bars are the standard error of the mean.")) + parts.append( + figure( + fig, + "Mean event weight (as stored) per class in bins of the leading and the last candidate jet pT of the first role and of the jet multiplicity; error bars are the standard error of the mean.", + ) + ) return "".join(parts) def section_gaps(self) -> str: @@ -1231,12 +1891,22 @@ def render(self) -> str: bodies[key] = getattr(self, f"section_{key}")() except Exception as e: # a section that fails is reported, not fatal logging.error(f"section '{title}' failed:\n{traceback.format_exc()}") - self.gaps.append(f"section '{title}' could not be produced: {type(e).__name__}: {e}") - bodies[key] = f'

    This section could not be produced: {esc(type(e).__name__)}: {esc(e)}

    ' + self.gaps.append( + f"section '{title}' could not be produced: {type(e).__name__}: {e}" + ) + bodies[key] = ( + f'

    This section could not be produced: {esc(type(e).__name__)}: {esc(e)}

    ' + ) plt.close("all") bodies["gaps"] = self.section_gaps() - toc = "".join(f'
  • {i + 1}. {esc(t)}
  • ' for i, (k, t) in enumerate(SECTIONS)) - sections = "".join(f'

    {i + 1}. {esc(t)}

    {bodies[k]}
    ' for i, (k, t) in enumerate(SECTIONS)) + toc = "".join( + f'
  • {i + 1}. {esc(t)}
  • ' + for i, (k, t) in enumerate(SECTIONS) + ) + sections = "".join( + f'

    {i + 1}. {esc(t)}

    {bodies[k]}
    ' + for i, (k, t) in enumerate(SECTIONS) + ) cmd = esc(" ".join(sys.argv)) return f""" CoReNet report: {esc(self.run_dir)} @@ -1268,7 +1938,14 @@ def git_hash() -> str: if _GIT_HASH is None: try: out = subprocess.run( - ["git", "-C", str(Path(__file__).resolve().parent), "rev-parse", "--short", "HEAD"], + [ + "git", + "-C", + str(Path(__file__).resolve().parent), + "rev-parse", + "--short", + "HEAD", + ], capture_output=True, text=True, timeout=5, @@ -1286,28 +1963,67 @@ def build_parser() -> argparse.ArgumentParser: description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) - p.add_argument("--run-dir", required=True, help="directory written by corenet-train (and corenet-evaluate)") - p.add_argument("--input", required=True, help="the HDF5 file the run was trained on") - p.add_argument("--output", default=None, help="HTML file to write [/report.html]") - p.add_argument("--config", default=None, help="configuration file [the one stored in the checkpoint]") - p.add_argument("--folds", type=int, nargs="*", default=None, help="folds to include [every fold found in the run directory]") - p.add_argument("--max-events", type=int, default=500000, help="events of the input file used for the input and weight distributions (random subsample above this) [500000]; 0 = all") - p.add_argument("--n-folds", type=int, default=None, help="fold = squares(event) %% K instead of EVENT/fold [the run's rule]") - p.add_argument("--fold-seed", type=int, default=None, help="seed of that rule [the run's]") - p.add_argument("--rest-order", choices=["pt", "selector"], default=None, help="ordering of the 'rest' selector [the run's]") + p.add_argument( + "--run-dir", + required=True, + help="directory written by corenet-train (and corenet-evaluate)", + ) + p.add_argument( + "--input", required=True, help="the HDF5 file the run was trained on" + ) + p.add_argument( + "--output", default=None, help="HTML file to write [/report.html]" + ) + p.add_argument( + "--config", + default=None, + help="configuration file [the one stored in the checkpoint]", + ) + p.add_argument( + "--folds", + type=int, + nargs="*", + default=None, + help="folds to include [every fold found in the run directory]", + ) + p.add_argument( + "--max-events", + type=int, + default=500000, + help="events of the input file used for the input and weight distributions (random subsample above this) [500000]; 0 = all", + ) + p.add_argument( + "--n-folds", + type=int, + default=None, + help="fold = squares(event) %% K instead of EVENT/fold [the run's rule]", + ) + p.add_argument( + "--fold-seed", type=int, default=None, help="seed of that rule [the run's]" + ) + p.add_argument( + "--rest-order", + choices=["pt", "selector"], + default=None, + help="ordering of the 'rest' selector [the run's]", + ) return p def main(argv=None) -> Path: args = build_parser().parse_args(argv) - logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") + logging.basicConfig( + level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s" + ) report = Report(args) report.load() page = report.render() out = Path(args.output) if args.output else report.run_dir / "report.html" out.parent.mkdir(parents=True, exist_ok=True) out.write_text(page, encoding="utf-8") - logging.info(f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB, {len(report.gaps)} items not produced)") + logging.info( + f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB, {len(report.gaps)} items not produced)" + ) for g in dict.fromkeys(report.gaps): logging.info(f"not produced: {g}") return out diff --git a/tests/test_report.py b/tests/test_report.py index 653f783..320c144 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -24,7 +24,10 @@ def _add_targets(path: Path) -> None: with h5py.File(path, "a") as f: label = f["EVENT/label"][...] n_present = f["INPUTS/Source/MASK"][...].sum(1) - cols = {k: np.full(len(label), -1, dtype=np.int64) for k in ("h1/b1", "h1/b2", "h2/b1", "h2/b2")} + cols = { + k: np.full(len(label), -1, dtype=np.int64) + for k in ("h1/b1", "h1/b2", "h2/b1", "h2/b2") + } for i in np.flatnonzero(label == 1): slots = rng.choice(int(n_present[i]), 4, replace=False) for k, s in zip(cols, slots): @@ -50,7 +53,15 @@ def _evaluate_all(out_dir: Path, data: Path) -> None: def _report(out_dir: Path, data: Path, *extra: str) -> str: out = report.main( - ["--run-dir", str(out_dir), "--input", str(data), "--output", str(out_dir / "report.html"), *extra] + [ + "--run-dir", + str(out_dir), + "--input", + str(data), + "--output", + str(out_dir / "report.html"), + *extra, + ] ) assert out.is_file(), out assert out.stat().st_size < MAX_BYTES, out.stat().st_size @@ -135,4 +146,13 @@ def test_report_needs_a_run_directory() -> None: with tempfile.TemporaryDirectory() as tmp: with pytest.raises(SystemExit): - report.main(["--run-dir", tmp, "--input", str(HH4B), "--output", str(Path(tmp) / "r.html")]) + report.main( + [ + "--run-dir", + tmp, + "--input", + str(HH4B), + "--output", + str(Path(tmp) / "r.html"), + ] + ) From a0790edf8d78cc5370d539832ecf4c592f98abe9 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:45:37 -0400 Subject: [PATCH 18/23] report: readable small weights in the statistics table, staggered N labels in the pairing figure --- src/corenet/report.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/corenet/report.py b/src/corenet/report.py index 9ed1bf1..889e83f 100644 --- a/src/corenet/report.py +++ b/src/corenet/report.py @@ -1334,7 +1334,7 @@ def key(slots): # one integer per sorted slot tuple f"N = {nn:,}", (xi, 100 * m), textcoords="offset points", - xytext=(0, 7), + xytext=(0, 7 + 8 * (xi % 2)), ha="center", fontsize=6, ) @@ -1716,10 +1716,10 @@ def section_weights(self) -> str: c, int(sel.sum()), float(s1), - float(ws.min()), - float(ws.max()), - float(ws.mean()), - float(ws.std()), + f"{ws.min():.3g}", + f"{ws.max():.3g}", + f"{ws.mean():.3g}", + f"{ws.std():.3g}", fmt(neff, 1), fmt(neff / sel.sum(), 4), int((ws < 0).sum()), From e4b2e24a3b14efd3374897ae4975e4e4d3a9532c Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:36:26 -0400 Subject: [PATCH 19/23] report: drop the not-produced section and the wall-time mention; README lists report.html under the evaluation outputs --- README.md | 5 +++- docs/Report.md | 5 ++-- src/corenet/report.py | 60 ++++++++++++++++--------------------------- 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index f178464..daedef5 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ Output: |---|---| | `eval_fold0.h5.json` | the metrics | | `eval_fold0.h5` | the predictions, as below | +| `report.html` | every result of the run on one page, written by `corenet-report` ([Report](#report) below) | | dataset in `eval_fold0.h5` | content | |---|---| @@ -243,7 +244,9 @@ Output: | file | content | |---|---| -| `report.html` | self-contained page: run summary, training curves, ROC / AUC / score distributions, view probabilities and pairing accuracy against `TARGETS`, the inputs as the network embeds them, the raw inputs, the event weights, and the list of what could not be produced ([docs/Report.md](docs/Report.md)) | +| `report.html` | self-contained page: run summary, training curves, ROC / AUC / score distributions, view probabilities and pairing accuracy against `TARGETS`, the inputs as the network embeds them, the raw inputs and the event weights ([docs/Report.md](docs/Report.md)) | + +Open `report.html` in any browser; from a cluster, copy it to your machine first (`scp :runs/bbww/report.html .`). ```python import onnxruntime as ort diff --git a/docs/Report.md b/docs/Report.md index 194b3d1..88dfb61 100644 --- a/docs/Report.md +++ b/docs/Report.md @@ -83,8 +83,9 @@ what could not be produced and why. events and weights per fold and class, and the training set of every fold. 8. **Other checks**: the mean event weight as a function of the leading and the last candidate jet pT and of the jet multiplicity, per class. -9. **Not produced**: everything the run did not provide (no `TARGETS`, no predictions on the training - folds, no history, ...) and the reason. + +A figure whose inputs the run did not provide (no `TARGETS`, no predictions on the training folds, ...) is +left out. Weighted distributions use the event weights of the file clipped at 0, as the training does; each class is normalised to unit area. Mean ± sd are over folds. diff --git a/src/corenet/report.py b/src/corenet/report.py index 889e83f..28af24b 100644 --- a/src/corenet/report.py +++ b/src/corenet/report.py @@ -60,7 +60,6 @@ ("raw", "Raw inputs"), ("weights", "Weights"), ("other", "Other checks"), - ("gaps", "Not produced"), ] SPLITS = ("test", "validation", "train") SPLIT_STYLE = {"test": "-", "train": "--", "validation": "-."} @@ -620,31 +619,24 @@ def section_summary(self) -> str: esc(", ".join(sorted(fd.splits))) or "-", ] ) - parts.append( - table( - [ - "fold", - "validation folds", - "training events", - "validation events", - "test events", - "epochs run", - "best epoch", - "stopped after", - "parameters", - "fine-tuned parameters", - "wall time [s]", - "predictions", - ], - rows, - "Folds", - ) - ) - if not wall_recorded: - parts.append(note("Wall time: not recorded in the history files.")) - self.gaps.append( - "wall time: corenet-train does not record it in history_fold*.json" - ) + header = [ + "fold", + "validation folds", + "training events", + "validation events", + "test events", + "epochs run", + "best epoch", + "stopped after", + "parameters", + "fine-tuned parameters", + "wall time [s]", + "predictions", + ] + if not wall_recorded: # the column exists only when the history files carry a wall time + header.pop(10) + rows = [r[:10] + r[11:] for r in rows] + parts.append(table(header, rows, "Folds")) if any( fd.history and fd.history.get("early_stop_patience") for fd in self.folds ): @@ -1876,17 +1868,10 @@ def section_other(self) -> str: ) return "".join(parts) - def section_gaps(self) -> str: - if not self.gaps: - return "

    Everything requested could be produced for this run.

    " - items = "".join(f"
  • {esc(g)}
  • " for g in dict.fromkeys(self.gaps)) - return f"
      {items}
    " - # ---------------------------------------------------------------- page def render(self) -> str: bodies = {} - order = [s for s in SECTIONS if s[0] != "gaps"] - for key, title in order: + for key, title in SECTIONS: try: bodies[key] = getattr(self, f"section_{key}")() except Exception as e: # a section that fails is reported, not fatal @@ -1898,7 +1883,6 @@ def render(self) -> str: f'

    This section could not be produced: {esc(type(e).__name__)}: {esc(e)}

    ' ) plt.close("all") - bodies["gaps"] = self.section_gaps() toc = "".join( f'
  • {i + 1}. {esc(t)}
  • ' for i, (k, t) in enumerate(SECTIONS) @@ -2022,10 +2006,10 @@ def main(argv=None) -> Path: out.parent.mkdir(parents=True, exist_ok=True) out.write_text(page, encoding="utf-8") logging.info( - f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB, {len(report.gaps)} items not produced)" + f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB)" ) - for g in dict.fromkeys(report.gaps): - logging.info(f"not produced: {g}") + for g in dict.fromkeys(report.gaps): # inputs the run did not provide; verbose only + logging.debug(f"not produced: {g}") return out From c7294764484ffccf20932e8ecdb4e71a040315fa Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:37:19 -0400 Subject: [PATCH 20/23] report: drop the 'Not produced' section and the wall-time note; a figure without inputs is left out - SECTIONS has eight entries; the gaps stay internal and are logged at DEBUG only - the wall-time column of the Folds table appears only when the history records a wall time - notes announcing an absent figure removed (no TARGETS, no training-fold predictions, no history, no prediction file) - tests: the page holds exactly the eight sections in order and no 'not produced' / 'wall time' text; without TARGETS and training-fold predictions there is no pairing-accuracy table and no train / validation AUC or overtraining overlay - docs/Report.md and README: section list and the 'left out' rule --- docs/Report.md | 3 +- src/corenet/report.py | 65 +++++++++---------------------------------- tests/test_report.py | 29 +++++++++++++------ 3 files changed, 35 insertions(+), 62 deletions(-) diff --git a/docs/Report.md b/docs/Report.md index 88dfb61..755591b 100644 --- a/docs/Report.md +++ b/docs/Report.md @@ -42,8 +42,7 @@ Per fold `k`, in `--run-dir`: | `predictions_fold{k}.h5` | predictions on the held-out fold | ROC, AUC, scores, view probabilities, pairing accuracy | | `eval_fold{k}.h5` | `corenet-evaluate` output; with `--fold -1` every event of the file | the training and validation folds in the ROC, AUC and score figures (overtraining check) | -A fold with some of these files missing is reported with what is there; the last section of the page lists -what could not be produced and why. +A fold with some of these files missing is reported with what is there. ## Output diff --git a/src/corenet/report.py b/src/corenet/report.py index 28af24b..ae4c4d9 100644 --- a/src/corenet/report.py +++ b/src/corenet/report.py @@ -11,8 +11,7 @@ Sections: run summary, training curves, classification (ROC, AUC, scores, confusion matrix, auxiliary heads), hypotheses and pairing (view probabilities, pairing accuracy against ``TARGETS``), the inputs -as the network embeds them, the raw inputs, the event weights, further checks, and the list of what -could not be produced for the run. Every figure is embedded as PNG; the page needs no other file. +as the network embeds them, the raw inputs, the event weights and further checks. Every figure is embedded as PNG; the page needs no other file. """ from __future__ import annotations @@ -573,9 +572,6 @@ def section_summary(self) -> str: ) ) else: - parts.append( - note("No training recipe recorded (no history or checkpoint).") - ) self.gaps.append( "training recipe: no history_fold*.json or model_fold*.pkl" ) @@ -659,7 +655,7 @@ def section_training(self) -> str: ] if not with_hist: self.gaps.append("training curves: no history_fold*.json with epochs") - return note("No history file with epochs: no training curves.") + return "" keys = [ ("train_loss", "training loss"), ("val_loss", "validation loss"), @@ -696,9 +692,6 @@ def section_training(self) -> str: self.gaps.append( "validation curves: the histories have no validation entries (train with --exclude-folds)" ) - out += note( - "No validation fold in the histories: validation loss and AUC are empty." - ) rows = [] for fd in with_hist: e = fd.history["history"][-1] @@ -744,18 +737,13 @@ def _main_curves(self): def section_classification(self) -> str: if not any("test" in fd.splits for fd in self.folds): self.gaps.append("classification: no prediction file for any fold") - return note( - "No prediction file: no ROC curves, AUC table or score distributions." - ) + return "" parts = [] curves = self._main_curves() if not curves: self.gaps.append( "ROC curves: the predicted events have only one class (no signal or no background)" ) - parts.append( - note("The predicted events hold a single class: no ROC curve.") - ) else: fig, (a, b) = plt.subplots(1, 2, figsize=(7.8, 3.4)) colors = {"test": "C0", "train": "C3", "validation": "C2"} @@ -828,10 +816,8 @@ def section_classification(self) -> str: ) for name in ("validation", "train"): if name not in curves: - parts.append( - note( - f"No predictions on the {name} folds (corenet-evaluate --fold -1 provides them)." - ) + self.gaps.append( + f"ROC curves: no predictions on the {name} folds (corenet-evaluate --fold -1 provides them)" ) # score distributions @@ -881,7 +867,7 @@ def _confusion_figure(self) -> str: cm[i, j] += w[(s.label == i) & (pred == j)].sum() present = [i for i in range(n) if cm[i].sum() > 0] if not present: - return note("Confusion matrix: no test events.") + return "" norm = cm / np.where(cm.sum(1, keepdims=True) > 0, cm.sum(1, keepdims=True), 1) fig, ax = plt.subplots(figsize=(1.2 * n + 2.2, 1.0 * n + 1.6)) im = ax.imshow(norm[present], cmap="Blues", vmin=0, vmax=1) @@ -1025,14 +1011,11 @@ def section_hypotheses(self) -> str: parts = [] if not hyps: if test: - parts.append( - note( - "Every hypothesis has a single candidate: no view probabilities." - ) + self.gaps.append( + "hypotheses: every hypothesis has a single candidate (no view probabilities)" ) else: self.gaps.append("hypotheses: no prediction file") - parts.append(note("No prediction file: no view probabilities.")) return "".join(parts) fig, axes = grid_figure(len(hyps), per_row=3, w=3.2, h=2.6) for ax, h in zip(axes, hyps): @@ -1142,9 +1125,7 @@ def _pairing_accuracy(self, test, hyps) -> str: self.gaps.append( "pairing accuracy: the input file has no TARGETS group (generator-matched jets)" ) - return note( - "No TARGETS in the input file: the pairing accuracy against the generator matching cannot be computed." - ) + return "" parts = [] sel = self.ds.selected for h in hyps: @@ -1160,11 +1141,6 @@ def _pairing_accuracy(self, test, hyps) -> str: self.gaps.append( f"pairing accuracy of {h}: no TARGETS group named like one of its nodes ({sorted(declared)}; TARGETS has {sorted(targets)})" ) - parts.append( - note( - f"{h}: no TARGETS group matches a node of the hypothesis ({', '.join(sorted(declared))}); TARGETS groups: {', '.join(sorted(targets))}." - ) - ) continue # per matched node: the sorted file slots of its generator-matched jets (truth) and of its # candidate under every view; sibling nodes that are interchangeable (H1 / H2) are compared as @@ -1235,18 +1211,11 @@ def key(slots): # one integer per sorted slot tuple == t ).all(1) if not usable: - parts.append( - note( - f"{h}: the matched TARGETS groups ({', '.join(matched)}) list a different number of jets than the nodes they name." - ) + self.gaps.append( + f"pairing accuracy of {h}: the matched TARGETS groups ({', '.join(matched)}) list a different number of jets than the nodes they name" ) continue if all(np.array_equal(correct[0], correct[v]) for v in range(1, V)): - parts.append( - note( - f"{h}: the TARGETS groups {', '.join(g for g, _ in usable)} do not distinguish the {V} views (every view assigns their jets the same way): no pairing accuracy." - ) - ) self.gaps.append( f"pairing accuracy of {h}: the TARGETS groups do not distinguish its views" ) @@ -1633,12 +1602,6 @@ def section_raw(self) -> str: parts.append( figure(fig, "Event scalars as read or computed by the loader.") ) - if not spec.roles and not singles and not spec.event: - parts.append( - note( - "The configuration declares no roles, single objects or event scalars." - ) - ) return "".join(parts) # ---- weights @@ -1815,10 +1778,8 @@ def section_other(self) -> str: if "nSelJets" in name: profiles.append((name, ds.inputs["event"][idx].numpy()[:, j])) if not profiles: - parts.append( - note( - "No jet role or jet multiplicity in the configuration: no weight profiles." - ) + self.gaps.append( + "weight profiles: no jet role or jet multiplicity in the configuration" ) return "".join(parts) fig, axes = grid_figure(len(profiles), per_row=3, w=3.2, h=2.6) diff --git a/tests/test_report.py b/tests/test_report.py index 320c144..edc39ca 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -1,9 +1,10 @@ """corenet-report on 2-epoch synthetic trainings (CPU): the HTML file exists, is small, holds every section, renders the pairing accuracy when the file has TARGETS and the overtraining check when corenet-evaluate -predictions of every event exist, and lists the gaps when they do not.""" +predictions of every event exist, and leaves those figures out when they do not.""" from __future__ import annotations +import re import tempfile from pathlib import Path @@ -14,7 +15,7 @@ from corenet import evaluate, report -HEADINGS = [t for _, t in report.SECTIONS] +HEADINGS = [f"{i + 1}. {t}" for i, (_, t) in enumerate(report.SECTIONS)] MAX_BYTES = 4_000_000 @@ -66,8 +67,11 @@ def _report(out_dir: Path, data: Path, *extra: str) -> str: assert out.is_file(), out assert out.stat().st_size < MAX_BYTES, out.stat().st_size page = out.read_text(encoding="utf-8") - for heading in HEADINGS: - assert heading in page, f"section '{heading}' missing" + assert len(HEADINGS) == 8, HEADINGS + assert re.findall(r"

    (.*?)

    ", page) == HEADINGS, "the page must hold exactly the eight sections in order" + low = page.lower() + assert "not produced" not in low, "the 'Not produced' list is back" + assert "wall time" not in low, "the wall-time column / note is back" assert "could not be produced" not in page, "a section failed" assert "data:image/png;base64," in page return page @@ -83,8 +87,8 @@ def test_report_with_targets_and_all_events() -> None: _evaluate_all(out_dir, data) page = _report(out_dir, data) assert "Pairing accuracy of the argmax view of HH" in page - assert "no TARGETS" not in page - assert "no predictions on the training folds" not in page + assert re.search(r"mean ± sd[0-9.]+[0-9.]+[0-9.]+", page) + assert "test, train, validation" in page assert "overtraining check" in page assert "AUC of the main score" in page assert "H1 ← b" in page and "HH context" in page and "event scalars" in page @@ -98,8 +102,17 @@ def test_report_without_targets_and_train_predictions() -> None: out_dir = tmp / "run" _train(data, out_dir) page = _report(out_dir, data, "--max-events", "500") - assert "no TARGETS" in page - assert "no predictions on the training folds" in page + # hypotheses: view probabilities and argmax shares, but no pairing accuracy (no TARGETS) + assert "Highest view probability per event and class on the test folds" in page + assert "Weighted share of the argmax view, test folds: HH" in page + assert "Pairing accuracy" not in page and "against TARGETS" not in page + # classification: AUC on the test fold only, no train / validation curves, no overtraining overlay + assert re.search(r"mean ± sd[0-9.]+--", page) + assert "overtraining check" not in page + assert "test" in page and "test, train, validation" not in page + low_page = page.lower() + assert "pairing accuracy" not in low_page + assert "No predictions on the" not in page assert "random subsample" in page From 6168c62bd649722bc4c8670d6f989c81d7f9516e Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:52:04 -0400 Subject: [PATCH 21/23] =?UTF-8?q?release=20metadata:=20.zenodo.json=20for?= =?UTF-8?q?=20the=20GitHub=E2=80=93Zenodo=20integration,=20authors=20in=20?= =?UTF-8?q?CITATION.cff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .zenodo.json | 15 +++++++++++++++ CITATION.cff | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .zenodo.json diff --git a/.zenodo.json b/.zenodo.json new file mode 100644 index 0000000..9e38da7 --- /dev/null +++ b/.zenodo.json @@ -0,0 +1,15 @@ +{ + "title": "CoReNet: Combinatorial Residual Networks for multijet topologies", + "upload_type": "software", + "description": "Reference implementation of CoReNet, a configuration-driven combinatorial residual network for jet assignment and event classification in multijet final states, with the HH to bbbb and HH to bbWW examples of the accompanying paper.", + "creators": [ + {"name": "Khanal, Aniket", "affiliation": "Carnegie Mellon University", "orcid": "0009-0007-5557-9821"}, + {"name": "Alison, John", "affiliation": "Carnegie Mellon University", "orcid": "0000-0003-0843-1641"}, + {"name": "Gomez Espinosa, Alejandro", "affiliation": "Carnegie Mellon University", "orcid": "0000-0002-9443-7769"} + ], + "license": "MIT", + "keywords": ["jet assignment", "Higgs boson pair production", "machine learning", "CMS", "CoReNet"], + "related_identifiers": [ + {"identifier": "10.5281/zenodo.23567532", "relation": "isSupplementedBy", "resource_type": "dataset"} + ] +} diff --git a/CITATION.cff b/CITATION.cff index fae8536..74ac8ba 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,4 +1,4 @@ -# Placeholder: the owner fills in authors, DOI and references before the release. +# The software DOI and the preferred-citation (article) are filled in after the first release. cff-version: 1.2.0 message: "If you use CoReNet, please cite it as below." title: "CoReNet: Combinatorial Residual Network" @@ -8,7 +8,17 @@ date-released: "YYYY-MM-DD" # to be confirmed license: MIT repository-code: "https://github.com/[owner]/CoReNet" # to be confirmed authors: - - family-names: "[to be confirmed]" - given-names: "[to be confirmed]" + - family-names: "Khanal" + given-names: "Aniket" + orcid: "https://orcid.org/0009-0007-5557-9821" + affiliation: "Carnegie Mellon University" + - family-names: "Alison" + given-names: "John" + orcid: "https://orcid.org/0000-0003-0843-1641" + affiliation: "Carnegie Mellon University" + - family-names: "Gomez Espinosa" + given-names: "Alejandro" + orcid: "https://orcid.org/0000-0002-9443-7769" + affiliation: "Carnegie Mellon University" # doi: "10.xxxx/zenodo.xxxxxxx" # to be confirmed # preferred-citation: # to be confirmed (article describing the architecture) From e7b5cf48643eb4603ec95ccbceb1adea2d881b09 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:14:45 -0400 Subject: [PATCH 22/23] ruff format --- src/corenet/report.py | 8 ++++---- src/corenet/train.py | 4 +++- src/corenet/validate.py | 4 +++- tests/test_compat.py | 17 +++++++++++++---- tests/test_h5.py | 27 +++++++++++++++++++------- tests/test_report.py | 12 +++++++++--- tests/test_train.py | 42 ++++++++++++++++++++++++++++++++--------- tests/test_validate.py | 4 +++- 8 files changed, 88 insertions(+), 30 deletions(-) diff --git a/src/corenet/report.py b/src/corenet/report.py index ae4c4d9..45d1e53 100644 --- a/src/corenet/report.py +++ b/src/corenet/report.py @@ -629,7 +629,9 @@ def section_summary(self) -> str: "wall time [s]", "predictions", ] - if not wall_recorded: # the column exists only when the history files carry a wall time + if ( + not wall_recorded + ): # the column exists only when the history files carry a wall time header.pop(10) rows = [r[:10] + r[11:] for r in rows] parts.append(table(header, rows, "Folds")) @@ -1966,9 +1968,7 @@ def main(argv=None) -> Path: out = Path(args.output) if args.output else report.run_dir / "report.html" out.parent.mkdir(parents=True, exist_ok=True) out.write_text(page, encoding="utf-8") - logging.info( - f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB)" - ) + logging.info(f"wrote {out} ({out.stat().st_size / 1e6:.2f} MB)") for g in dict.fromkeys(report.gaps): # inputs the run did not provide; verbose only logging.debug(f"not produced: {g}") return out diff --git a/src/corenet/train.py b/src/corenet/train.py index 8a11732..93717b6 100644 --- a/src/corenet/train.py +++ b/src/corenet/train.py @@ -96,7 +96,9 @@ def batch_schedule(epoch: int, bs_init: int) -> tuple[int, int]: ) bs = bs_init << stage n_gb = (64, 16, 4, 1, 0)[stage] - return bs, ghost_batches(bs, n_gb) # equals the stage's count for any power-of-two batch size >= 512 + return bs, ghost_batches( + bs, n_gb + ) # equals the stage's count for any power-of-two batch size >= 512 def ghost_batches(bs: int, cap: int) -> int: diff --git a/src/corenet/validate.py b/src/corenet/validate.py index 426af9f..fb1d01a 100644 --- a/src/corenet/validate.py +++ b/src/corenet/validate.py @@ -421,7 +421,9 @@ def length(name, ds): if n_folds is None: report.fail(sec, msg + " or pass --n-folds K") else: - report.warn(sec, msg + f"; --n-folds {n_folds} ignores the column") + report.warn( + sec, msg + f"; --n-folds {n_folds} ignores the column" + ) column = None elif n_folds is None: report.fail( diff --git a/tests/test_compat.py b/tests/test_compat.py index ee510ed..bf6eedc 100644 --- a/tests/test_compat.py +++ b/tests/test_compat.py @@ -68,17 +68,23 @@ def test_detector_sees_a_runtime_union(tmp_path): "SeedLike = int | str | Iterable[int | str]\nx: int | None = None\n" "def f(a: int | None) -> str | None:\n y: int | None = None\n return None\n" ) - assert runtime_unions(bad) == ["bad.py:3"] # the annotations on lines 4-6 are not evaluated + assert runtime_unions(bad) == [ + "bad.py:3" + ] # the annotations on lines 4-6 are not evaluated -@pytest.mark.parametrize("path", SOURCES, ids=[str(p.relative_to(SRC)) for p in SOURCES]) +@pytest.mark.parametrize( + "path", SOURCES, ids=[str(p.relative_to(SRC)) for p in SOURCES] +) def test_no_runtime_type_union(path): assert runtime_unions(path) == [], ( "type union evaluated at import time (fails on Python 3.9); use typing.Union" ) -@pytest.mark.parametrize("path", SOURCES, ids=[str(p.relative_to(SRC)) for p in SOURCES]) +@pytest.mark.parametrize( + "path", SOURCES, ids=[str(p.relative_to(SRC)) for p in SOURCES] +) def test_parses_with_python39_grammar(path): ast.parse(path.read_text(), filename=str(path), feature_version=(3, 9)) @@ -88,4 +94,7 @@ def test_seed_alias_is_a_typing_union(): assert typing.get_origin(SeedLike) is typing.Union assert set(typing.get_args(SeedLike)[:2]) == {int, str} - assert Squares("delphes_h5", "fold", 0)._seed == Squares(("delphes_h5", "fold", 0))._seed + assert ( + Squares("delphes_h5", "fold", 0)._seed + == Squares(("delphes_h5", "fold", 0))._seed + ) diff --git a/tests/test_h5.py b/tests/test_h5.py index c30ee1c..3cd2e05 100644 --- a/tests/test_h5.py +++ b/tests/test_h5.py @@ -445,7 +445,8 @@ def test_missing_fold_column(tmp_path): assert len(ds0) == 500 and (ds0.folds.numpy() == NO_FOLD).all() assert ds0[3]["fold"] == NO_FOLD and ds0.inputs["b"].shape == (500, 5, 4) with pytest.raises( - KeyError, match="no EVENT/fold dataset; holding out fold 0 needs .* pass --n-folds K" + KeyError, + match="no EVENT/fold dataset; holding out fold 0 needs .* pass --n-folds K", ): ds0.fold_indices(0) with pytest.raises(KeyError, match="no EVENT/fold dataset; training needs"): @@ -479,7 +480,9 @@ def test_fold_ids_must_be_0_to_k(tmp_path): for bad in ([0, 1, 3], [1, 2, 3], [0, 2, 4]): with h5py.File(path, "a") as f: del f["EVENT/fold"] - f.create_dataset("EVENT/fold", data=np.array(bad, dtype=np.int64)[event % 3]) + f.create_dataset( + "EVENT/fold", data=np.array(bad, dtype=np.int64)[event % 3] + ) with pytest.raises( ValueError, match=re.escape( @@ -509,7 +512,9 @@ def test_selector_sorts_at_file_precision(tmp_path): low[:, 0], low[:, 1] = 16777216, 16777217 f.create_dataset("INPUTS/Source/low", data=low) urank = np.zeros((n, slots), dtype=np.uint8) - urank[:, 1] = 7 # jet 0 has 0: -0 wraps to 0 and would be preferred by a wrapped negation + urank[:, 1] = ( + 7 # jet 0 has 0: -0 wraps to 0 and would be preferred by a wrapped negation + ) f.create_dataset("INPUTS/Source/urank", data=urank) flag = np.zeros((n, slots), dtype=bool) flag[:, 1] = True @@ -527,7 +532,9 @@ def test_selector_sorts_at_file_precision(tmp_path): cfg = _hh4b_cfg(["pt", "eta", "phi", "mass"]) cfg["objects"]["b"] = "jets low 4 lowest" x = H5Dataset(path, parse_config(cfg)).inputs - assert np.array_equal(x["b"][:, 0, 0].numpy(), pt[:, 0]) # the lowest: 16777216 is jet 0 + assert np.array_equal( + x["b"][:, 0, 0].numpy(), pt[:, 0] + ) # the lowest: 16777216 is jet 0 assert np.array_equal(x["b"][:, 0, 1].numpy(), pt[:, 1]) # the b-jet selection of the example files is unchanged (float32 in the file): test_hh4b_small / test_bbww_small @@ -561,12 +568,18 @@ def test_context_role_extras_reach_the_network(): flipped = {k: v.clone() for k, v in batch.items()} present = flipped["other"][:, -1] > 0 assert present.any() - flipped["other"][:, 4][present] = 1.0 - flipped["other"][:, 4][present] # btag of the other jets - assert torch.equal(flipped["b"], batch["b"]) and torch.equal(flipped["event"], batch["event"]) + flipped["other"][:, 4][present] = ( + 1.0 - flipped["other"][:, 4][present] + ) # btag of the other jets + assert torch.equal(flipped["b"], batch["b"]) and torch.equal( + flipped["event"], batch["event"] + ) with torch.no_grad(): out = m5(flipped) again = m5(batch) assert torch.isfinite(out["logits"]).all() - assert not torch.equal(out["logits"], ref["logits"]), "the btag of the other jets is not used" + assert not torch.equal(out["logits"], ref["logits"]), ( + "the btag of the other jets is not used" + ) assert not torch.equal(out["views"]["HH"], ref["views"]["HH"]) assert torch.equal(again["logits"], ref["logits"]) diff --git a/tests/test_report.py b/tests/test_report.py index edc39ca..9d4ffc5 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -68,7 +68,9 @@ def _report(out_dir: Path, data: Path, *extra: str) -> str: assert out.stat().st_size < MAX_BYTES, out.stat().st_size page = out.read_text(encoding="utf-8") assert len(HEADINGS) == 8, HEADINGS - assert re.findall(r"

    (.*?)

    ", page) == HEADINGS, "the page must hold exactly the eight sections in order" + assert re.findall(r"

    (.*?)

    ", page) == HEADINGS, ( + "the page must hold exactly the eight sections in order" + ) low = page.lower() assert "not produced" not in low, "the 'Not produced' list is back" assert "wall time" not in low, "the wall-time column / note is back" @@ -87,7 +89,9 @@ def test_report_with_targets_and_all_events() -> None: _evaluate_all(out_dir, data) page = _report(out_dir, data) assert "Pairing accuracy of the argmax view of HH" in page - assert re.search(r"mean ± sd[0-9.]+[0-9.]+[0-9.]+", page) + assert re.search( + r"mean ± sd[0-9.]+[0-9.]+[0-9.]+", page + ) assert "test, train, validation" in page assert "overtraining check" in page assert "AUC of the main score" in page @@ -107,7 +111,9 @@ def test_report_without_targets_and_train_predictions() -> None: assert "Weighted share of the argmax view, test folds: HH" in page assert "Pairing accuracy" not in page and "against TARGETS" not in page # classification: AUC on the test fold only, no train / validation curves, no overtraining overlay - assert re.search(r"mean ± sd[0-9.]+--", page) + assert re.search( + r"mean ± sd[0-9.]+--", page + ) assert "overtraining check" not in page assert "test" in page and "test, train, validation" not in page low_page = page.lower() diff --git a/tests/test_train.py b/tests/test_train.py index db5ce91..b4d8148 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -191,13 +191,17 @@ def test_batch_schedule_divides_any_batch_size() -> None: for bs_init in (64, 100, 300, 1000, 1500): for e in range(12): bs, n_gb = train.batch_schedule(e, bs_init) - assert n_gb == 0 or (bs % n_gb == 0 and bs // n_gb >= train.MIN_GHOST_BATCH_SIZE), (bs_init, e, bs, n_gb) - for k in range(6, 13): # powers of two: unchanged from the original schedule + assert n_gb == 0 or ( + bs % n_gb == 0 and bs // n_gb >= train.MIN_GHOST_BATCH_SIZE + ), (bs_init, e, bs, n_gb) + for k in range(6, 13): # powers of two: unchanged from the original schedule bs_init = 1 << k for e in range(12): bs, n_gb = train.batch_schedule(e, bs_init) stage = 0 if e == 0 else 1 if e < 3 else 2 if e < 6 else 3 if e < 10 else 4 - assert n_gb == min((64, 16, 4, 1, 0)[stage], max(1, bs // train.MIN_GHOST_BATCH_SIZE)) + assert n_gb == min( + (64, 16, 4, 1, 0)[stage], max(1, bs // train.MIN_GHOST_BATCH_SIZE) + ) def test_batch_schedule() -> None: @@ -533,7 +537,15 @@ def test_early_stopping_needs_validation() -> None: SystemExit, match=r"--early-stop-patience 1 needs validation events, but --exclude-folds \[0\] leaves none", ): - _train(data, tmp / "empty", "--exclude-folds", "0", "--early-stop-patience", "1", epochs=1) + _train( + data, + tmp / "empty", + "--exclude-folds", + "0", + "--early-stop-patience", + "1", + epochs=1, + ) h = _train(data, tmp / "empty_ok", "--exclude-folds", "0", epochs=1) assert h["n_val"] == 0 and "val_loss" not in h["history"][0] one = tmp / "oneclass.h5" @@ -569,15 +581,24 @@ def test_file_without_folds() -> None: with h5py.File(nofold, "a") as f: del f["EVENT/fold"] with pytest.raises( - SystemExit, match="no EVENT/fold dataset; training needs the fold of every event: pass --n-folds K" + SystemExit, + match="no EVENT/fold dataset; training needs the fold of every event: pass --n-folds K", ): _train(nofold, tmp / "nofold_train", epochs=1) assert not (tmp / "nofold_train").exists() with pytest.raises( - SystemExit, match="no EVENT/fold dataset, so fold 0 cannot be selected: pass --fold -1" + SystemExit, + match="no EVENT/fold dataset, so fold 0 cannot be selected: pass --fold -1", ): evaluate.main( - ["--checkpoint", str(ckpt), "--input", str(nofold), "--output", str(tmp / "e0.h5")] + [ + "--checkpoint", + str(ckpt), + "--input", + str(nofold), + "--output", + str(tmp / "e0.h5"), + ] ) metrics = evaluate.main( [ @@ -595,7 +616,9 @@ def test_file_without_folds() -> None: with h5py.File(tmp / "eall.h5", "r") as f: assert f.attrs["fold"] == -1 and f.attrs["n_folds"] == 0 assert f.attrs["fold_rule"] == FOLD_RULE_NONE - assert (f["EVENT/fold"][...] == NO_FOLD).all() and len(f["EVENT/event"]) == 2000 + assert (f["EVENT/fold"][...] == NO_FOLD).all() and len( + f["EVENT/event"] + ) == 2000 meta = export.main( [ "--checkpoint", @@ -759,7 +782,8 @@ def test_n_folds_rule() -> None: ) assert meta["exclude_folds"] == [0] with pytest.raises( - SystemExit, match="no EVENT/fold dataset, so fold 4 cannot be selected: pass --fold -1" + SystemExit, + match="no EVENT/fold dataset, so fold 4 cannot be selected: pass --fold -1", ): evaluate.main( [ diff --git a/tests/test_validate.py b/tests/test_validate.py index c4f5529..0530a2d 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -296,7 +296,9 @@ def _replace(f, name, data): ), ( lambda f: _replace( - f, "EVENT/fold", np.where(f["EVENT/fold"][...] == 2, 7, f["EVENT/fold"][...]) + f, + "EVENT/fold", + np.where(f["EVENT/fold"][...] == 2, 7, f["EVENT/fold"][...]), ), "EVENT/fold: fold ids [0, 1, 3, 4, 7] are not 0..K-1 (the ids of K folds must be exactly 0..K-1; " "--exclude-folds next = fold (k + 1) % K): renumber the column or pass --n-folds K", From c1638c8d9398262c37d161f2a0c1e330c870ea94 Mon Sep 17 00:00:00 2001 From: Aniket Khanal <80410519+aniketkhanal@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:18:08 -0400 Subject: [PATCH 23/23] ruff: noqa for the runtime Union alias, raw regex in a test --- src/corenet/data/folds.py | 2 +- tests/test_h5.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corenet/data/folds.py b/src/corenet/data/folds.py index b691c02..a975ede 100644 --- a/src/corenet/data/folds.py +++ b/src/corenet/data/folds.py @@ -26,7 +26,7 @@ _UINT64_32 = np.uint64(32) # a runtime alias (not an annotation): typing.Union, so that the module imports on Python 3.9 -SeedLike = Union[int, str, Iterable[Union[int, str]]] +SeedLike = Union[int, str, Iterable[Union[int, str]]] # noqa: UP007 def _str_to_entropy(text: str) -> list[np.uint64]: diff --git a/tests/test_h5.py b/tests/test_h5.py index 3cd2e05..03913c3 100644 --- a/tests/test_h5.py +++ b/tests/test_h5.py @@ -446,7 +446,7 @@ def test_missing_fold_column(tmp_path): assert ds0[3]["fold"] == NO_FOLD and ds0.inputs["b"].shape == (500, 5, 4) with pytest.raises( KeyError, - match="no EVENT/fold dataset; holding out fold 0 needs .* pass --n-folds K", + match=r"no EVENT/fold dataset; holding out fold 0 needs .* pass --n-folds K", ): ds0.fold_indices(0) with pytest.raises(KeyError, match="no EVENT/fold dataset; training needs"):