#!/usr/bin/env python3 """Every learnable feature except one, as --feature flags. Resolves a corpus NAME through the store as well as a run directory path. The first version took only a path, was handed a name, silently wrote nothing, and the fit it fed ran with no --feature flags at all - which means "fit everything", so the ablation was the same fit twice and reported a difference of exactly zero. """ import json import pathlib import subprocess import sys target, drop = sys.argv[1], sys.argv[2] candidates = [ pathlib.Path(target) / "manifest.json", pathlib.Path(target) / "data" / "manifest.json", ] root = subprocess.run( ["git", "rev-parse", "--git-common-dir"], capture_output=True, text=True ).stdout.strip() if root: store = pathlib.Path(root).parent / "corpora" / target candidates += [store / "manifest.json", store / "data" / "manifest.json"] for path in candidates: if path.is_file(): with open(path) as handle: learnable = json.load(handle).get("learnable") or [] break else: sys.exit(f"no manifest for {target!r}; tried {[str(c) for c in candidates]}") if drop not in learnable: sys.exit(f"{drop!r} is not learnable in this corpus; nothing to ablate") kept = [n for n in learnable if n != drop] if len(kept) < 2: sys.exit(f"only {len(kept)} feature(s) left after dropping {drop!r}") print(" ".join(f"--feature {n}" for n in kept))