File size: 3,092 Bytes
6cf9dac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Command-line entry point for reviewer-requested reanalysis."""

from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path


PROJECT_ROOT = Path(__file__).resolve().parents[2]
if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))

from revision.scripts.reanalysis_neural import estimate_neural_workload
from revision.scripts.reanalysis_pipeline import run_reanalysis, validate_config


def configure_utf8_console() -> None:
    """Make existing Unicode metric labels safe on Windows GBK consoles."""

    for stream in (sys.stdout, sys.stderr):
        reconfigure = getattr(stream, "reconfigure", None)
        if callable(reconfigure):
            reconfigure(encoding="utf-8")


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(
        description=(
            "Run canonical-identity-grouped and scaffold-aware reviewer analyses "
            "without modifying the original model artifacts."
        )
    )
    parser.add_argument(
        "--config",
        default=str(PROJECT_ROOT / "revision" / "config" / "reanalysis.json"),
        help="Path to the frozen JSON configuration.",
    )
    parser.add_argument(
        "--output-root",
        help="Optional new, empty output directory. Existing nonempty directories are refused.",
    )
    parser.add_argument(
        "--include-neural",
        action="store_true",
        help="Launch all predeclared GAT/GCN/FPNN fits. This is the long-running stage.",
    )
    parser.add_argument(
        "--smoke",
        action="store_true",
        help="Use a small labeled subset, one seed, two folds, and tiny estimators. Never use smoke outputs in the manuscript.",
    )
    parser.add_argument(
        "--estimate-only",
        action="store_true",
        help="Validate the configuration and print the neural workload without creating files.",
    )
    return parser.parse_args()


def main() -> int:
    configure_utf8_console()
    args = parse_args()
    config_path = Path(args.config).resolve()
    config = json.loads(config_path.read_text(encoding="utf-8"))
    if args.output_root:
        config["output_root"] = args.output_root
    normalized = validate_config(config, PROJECT_ROOT)

    if args.estimate_only:
        print(json.dumps(estimate_neural_workload(normalized), indent=2))
        return 0
    if args.smoke and not args.output_root:
        raise ValueError("--smoke requires an explicit new --output-root so smoke artifacts cannot mix with final artifacts.")

    output = run_reanalysis(
        normalized,
        project_root=PROJECT_ROOT,
        include_neural=bool(args.include_neural),
        smoke_only=bool(args.smoke),
    )
    print(f"Reanalysis artifacts written to: {output}")
    if not args.include_neural:
        print("Neural training was not run. Add --include-neural only after reviewing the split manifests.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())