| """Evaluate one hypothesis with the existing deterministic symbolic scorer.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import json |
| from pathlib import Path |
| import sys |
|
|
| WORKSPACE_ROOT = Path(__file__).resolve().parent.parent |
| if str(WORKSPACE_ROOT) not in sys.path: |
| sys.path.insert(0, str(WORKSPACE_ROOT)) |
|
|
| from experiments import config |
| from symbolic import launch as symbolic_launch |
|
|
|
|
| def configure_symbolic_evaluation( |
| hypothesis, |
| depth="metric", |
| tracking="tracking", |
| input_selection="uniform", |
| frame_count=64, |
| spatial_code_format="explicit", |
| ): |
| """Point symbolic reads and writes at one isolated experiment selection.""" |
| codes = config.spatial_code_directory( |
| hypothesis, depth, tracking, input_selection, frame_count, spatial_code_format |
| ) |
| results = config.result_directory( |
| hypothesis, |
| "symbolic", |
| depth, |
| tracking, |
| input_selection, |
| frame_count, |
| spatial_code_format, |
| ) |
| symbolic_run = symbolic_launch.symbolic_run |
| symbolic_run.SPATIAL_CODES_DEPTH = depth |
| symbolic_run.SPATIAL_CODES_INPUT = input_selection |
| symbolic_run.SPATIAL_CODES_TRACKING = tracking |
| symbolic_run.SPATIAL_CODES_FRAMES = frame_count |
| symbolic_run.SPATIAL_CODES_FORMAT = spatial_code_format |
| symbolic_run.SPATIAL_CODES_DIR = str(codes) |
| symbolic_run.RESULTS_DIR = str(results) |
| symbolic_run.results_dir_for_selection = lambda results_dir=None: str( |
| results_dir or results |
| ) |
| return codes, results |
|
|
|
|
| def evaluate( |
| hypothesis, |
| depth="metric", |
| tracking="tracking", |
| input_selection="uniform", |
| frame_count=64, |
| scene_ids=None, |
| quiet=False, |
| errors=False, |
| spatial_code_format="explicit", |
| ): |
| """Score every available experiment code, or an explicit scene subset.""" |
| codes, results = configure_symbolic_evaluation( |
| hypothesis, |
| depth, |
| tracking, |
| input_selection, |
| frame_count, |
| spatial_code_format, |
| ) |
| available = symbolic_launch.scenes_with_spatial_codes() |
| selected = available if scene_ids is None else list(scene_ids) |
| missing = [scene for scene in selected if scene not in available] |
| if missing: |
| raise FileNotFoundError( |
| f"scene(s) have no hypothesis spatial code under {codes}: {missing}" |
| ) |
| if not selected: |
| raise FileNotFoundError(f"no hypothesis spatial codes found under {codes}") |
| per_scene, combined = symbolic_launch.run_all(selected, quiet=quiet) |
| summary = { |
| "hypothesis": hypothesis, |
| "depth": depth, |
| "input": input_selection, |
| "tracking": tracking, |
| "frames": frame_count, |
| "spatial_code_format": spatial_code_format, |
| "scenes_run": list(per_scene), |
| "combined_aggregate": combined, |
| } |
| if errors: |
| summary["error_analysis"] = { |
| question_type: symbolic_launch.error_analysis(per_scene, question_type) |
| for question_type in symbolic_launch._ANALYZABLE_TYPES |
| } |
| symbolic_launch.print_error_analysis(per_scene) |
| symbolic_launch.print_mca_breakdown(per_scene) |
| results.mkdir(parents=True, exist_ok=True) |
| summary_path = results / "_summary.json" |
| with summary_path.open("w", encoding="utf-8") as stream: |
| json.dump(summary, stream, indent=1) |
| return summary, summary_path |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--hypothesis", required=True) |
| parser.add_argument("--depth", default="metric", choices=("relative", "metric")) |
| parser.add_argument( |
| "--input", |
| default="uniform", |
| choices=("uniform", "selective"), |
| dest="input_selection", |
| ) |
| parser.add_argument( |
| "--tracking", default="tracking", choices=("tracking", "no tracking") |
| ) |
| parser.add_argument("--frames", type=int, default=64) |
| parser.add_argument( |
| "--format", |
| default="explicit", |
| choices=config.SPATIAL_CODE_FORMATS, |
| dest="spatial_code_format", |
| ) |
| parser.add_argument( |
| "--scenes", default="", help="optional comma-separated scene IDs" |
| ) |
| parser.add_argument("--quiet", action="store_true") |
| parser.add_argument("--errors", action="store_true") |
| args = parser.parse_args() |
| if args.frames < 1: |
| parser.error("--frames must be positive") |
| scenes = ( |
| [scene.strip() for scene in args.scenes.split(",") if scene.strip()] |
| if args.scenes |
| else None |
| ) |
| summary, path = evaluate( |
| args.hypothesis, |
| args.depth, |
| args.tracking, |
| args.input_selection, |
| args.frames, |
| scenes, |
| args.quiet, |
| args.errors, |
| args.spatial_code_format, |
| ) |
| print("\nCOMBINED AGGREGATE") |
| for key, value in summary["combined_aggregate"].items(): |
| print(f" {key}: {value}") |
| print(f"\nwrote experiment summary to {path}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|