Download code/ampd/cli.py from fryabcfry/cs4486-amp-pd-checkpoints: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/fryabcfry/cs4486-amp-pd-checkpoints/resolve/main/code/ampd/cli.py
- Command line
-
hf download hf://fryabcfry/cs4486-amp-pd-checkpoints/code/ampd/cli.py
-
curl -L -o cli.py https://huggingface.co/fryabcfry/cs4486-amp-pd-checkpoints/resolve/main/code/ampd/cli.py
3.22 kB
| """Command line interface. | |
| Examples: | |
| python -m ampd.cli inspect --config configs/process_mlp.yaml | |
| python -m ampd.cli train --config configs/process_mlp.yaml | |
| python -m ampd.cli train --config configs/smoke.yaml --override trainer.max_epochs=2 | |
| python -m ampd.cli baseline --config configs/process_mlp.yaml --kind median | |
| python -m ampd.cli make-folds --config configs/process_mlp.yaml | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from .config import load_config | |
| from .data.clinical import build_all_data | |
| from .data.splits import make_folds, save_folds | |
| def _cfg(args): | |
| cfg = load_config(args.config, args.override) | |
| device = getattr(args, "device", None) | |
| if device: | |
| cfg["experiment"]["device"] = device | |
| return cfg | |
| def cmd_inspect(args): | |
| from .inspect import inspect_data | |
| cfg = _cfg(args) | |
| inspect_data(cfg) | |
| def cmd_train(args): | |
| from .runner import ExperimentRunner | |
| cfg = _cfg(args) | |
| runner = ExperimentRunner(cfg) | |
| result = runner.run() | |
| print(json.dumps({"run_dir": result["run_dir"], "smape_plus_1": result["metrics"].get("smape_plus_1")}, indent=2)) | |
| def cmd_baseline(args): | |
| from .baselines import run_baselines | |
| cfg = _cfg(args) | |
| run_baselines(cfg, kind=args.kind) | |
| def cmd_compare(args): | |
| from .compare import write_comparison | |
| write_comparison(args.root, args.out) | |
| def cmd_make_folds(args): | |
| cfg = _cfg(args) | |
| bundle = build_all_data(cfg) | |
| folds = make_folds(bundle.patients, cfg["cv"]) | |
| out = Path(args.out or "folds.csv") | |
| save_folds(folds, out) | |
| print(f"wrote {out} ({len(folds)} patients)") | |
| print(folds.groupby("fold").size().to_string()) | |
| def build_parser(): | |
| p = argparse.ArgumentParser(description="AMP-PD experiment platform") | |
| sub = p.add_subparsers(dest="command", required=True) | |
| def common(sp): | |
| sp.add_argument("--config", required=True, help="YAML config path") | |
| sp.add_argument("--override", nargs="*", default=[], help="key=value overrides") | |
| sp.add_argument("--device", default=None, choices=["auto", "cpu", "cuda"], help="device override") | |
| sp = sub.add_parser("inspect", help="build data and print shapes without training") | |
| common(sp) | |
| sp.set_defaults(func=cmd_inspect) | |
| sp = sub.add_parser("train", help="run CV training and automatic evaluation") | |
| common(sp) | |
| sp.set_defaults(func=cmd_train) | |
| sp = sub.add_parser("baseline", help="run median or Ridge baselines") | |
| common(sp) | |
| sp.add_argument("--kind", default="median", choices=["median", "process", "protein", "peptide", "all"]) | |
| sp.set_defaults(func=cmd_baseline) | |
| sp = sub.add_parser("compare", help="collect run metrics into a table") | |
| sp.add_argument("--root", default="runs") | |
| sp.add_argument("--out", default="runs/comparison.csv") | |
| sp.set_defaults(func=cmd_compare) | |
| sp = sub.add_parser("make-folds", help="write patient folds.csv") | |
| common(sp) | |
| sp.add_argument("--out", default="folds.csv") | |
| sp.set_defaults(func=cmd_make_folds) | |
| return p | |
| def main(): | |
| parser = build_parser() | |
| args = parser.parse_args() | |
| args.func(args) | |
| if __name__ == "__main__": | |
| main() | |