Add robustness_check/src/robustness_check/cli.py

This commit is contained in:
Mika 2026-01-26 12:23:46 +00:00
parent fcf098a16f
commit bc2817ff6c

View file

@ -0,0 +1,52 @@
import argparse
import json
from pathlib import Path
from robustness_check.core import check_robustness
def main() -> None:
"""Command-line entry point for Gate v0 Robustness Evaluation."""
parser = argparse.ArgumentParser(
description="Analyse der Gate-v0-Robustheit aus Frozen-Run-Daten."
)
parser.add_argument(
"--input",
required=True,
help="Pfad zur Eingabedatei mit Run-Daten im JSON-Format."
)
parser.add_argument(
"--output",
required=True,
help="Pfad zur Ausgabedatei für die Robustheitsergebnisse."
)
args = parser.parse_args()
input_path = Path(args.input)
output_path = Path(args.output)
if not input_path.exists():
parser.error(f"Eingabedatei nicht gefunden: {input_path}")
try:
with input_path.open("r", encoding="utf-8") as f:
runs_data = json.load(f)
if not isinstance(runs_data, list):
raise ValueError("Eingabedatei muss eine Liste von Run-Objekten enthalten.")
except (json.JSONDecodeError, ValueError) as e:
parser.error(f"Ungültiges Eingabeformat: {e}")
result = check_robustness(runs_data)
# Prepare output directory
output_path.parent.mkdir(parents=True, exist_ok=True)
with output_path.open("w", encoding="utf-8") as f:
json.dump({
"k_value": result.k_value,
"flip_flops": result.flip_flops,
"average_decision": result.average_decision,
}, f, indent=2)
if __name__ == "__main__":
main()