Download scripts/reference_solution.py from ArnavM10/rl-env-2605.07119-classification-fields: direct link, hf CLI and curl.
- Browser
- Download file 3.72 kB
-
https://huggingface.co/spaces/ArnavM10/rl-env-2605.07119-classification-fields/resolve/main/scripts/reference_solution.py
- Command line
-
hf download hf://spaces/ArnavM10/rl-env-2605.07119-classification-fields/scripts/reference_solution.py
-
curl -L -o reference_solution.py https://huggingface.co/spaces/ArnavM10/rl-env-2605.07119-classification-fields/resolve/main/scripts/reference_solution.py
3.72 kB
| # Reference solution for the Classification Fields RL environment | |
| # (arXiv:2605.07119). Gets the FULL reward (1.0). | |
| # | |
| # Strategy: run the official nonlinear IFS pipeline of arXiv:2605.07119 via the | |
| # environment's `run_reproduction` tool (official repo at pinned commit cb52f15, | |
| # 5 seeds x 3 benchmarks, CPU, ~minutes), then submit the resulting Table 1 | |
| # cells with the paper's verdict. All 6 benchmark cells land within tolerance | |
| # of the paper's numbers and the verdict matches, so the deterministic scorer | |
| # grants full credit. | |
| # | |
| # Usage: | |
| # python scripts/reference_solution.py --base-url http://localhost:8000 | |
| # python scripts/reference_solution.py --base-url \ | |
| # https://arnavm10-rl-env-2605-07119-classification-fields.hf.space | |
| import argparse | |
| import sys | |
| from classification_fields_env import CallToolAction, ClassificationFieldsEnv | |
| def tool_data(result: object) -> dict: | |
| """Unwrap a tool result across client serialization variants.""" | |
| if isinstance(result, dict): | |
| for key in ("data", "result"): | |
| inner = result.get(key) | |
| if isinstance(inner, dict): | |
| return inner | |
| return result | |
| for attr in ("data", "structured_content", "result"): | |
| inner = getattr(result, attr, None) | |
| if isinstance(inner, dict): | |
| return inner | |
| raise RuntimeError(f"could not unwrap tool result: {result!r}") | |
| def main() -> int: | |
| parser = argparse.ArgumentParser( | |
| description=( | |
| "Reference solution: full-reward reproduction of Table 1 of " | |
| "arXiv:2605.07119 (Classification Fields, nonlinear IFS benchmarks)." | |
| ) | |
| ) | |
| parser.add_argument( | |
| "--base-url", | |
| required=True, | |
| help="URL of the Classification Fields environment server", | |
| ) | |
| args = parser.parse_args() | |
| with ClassificationFieldsEnv(base_url=args.base_url).sync() as env: | |
| env.reset() | |
| print("episode reset; running the official arXiv:2605.07119 pipeline...") | |
| run = tool_data(env.call_tool("run_reproduction")) | |
| print( | |
| f"pipeline finished in {run['elapsed_seconds']:.1f}s " | |
| f"(commit {run['repo_commit']}, seeds {run['seeds']})" | |
| ) | |
| for benchmark, methods in run["cells"].items(): | |
| for method, stats in methods.items(): | |
| print( | |
| f" {benchmark:>12s} {method:>6s}: " | |
| f"{stats['ordered_mse_x1e3']:.2f} " | |
| f"+/- {stats['ordered_mse_std_x1e3']:.2f} (x 1e-3)" | |
| ) | |
| step = env.step( | |
| CallToolAction( | |
| tool_name="submit_table", | |
| arguments={ | |
| # The paper's verdict: the CFP beats the affine residual | |
| # predictor by >= 10x lower rollout MSE on all three | |
| # benchmarks of Table 1. | |
| "verdict": "cfp_wins_all_three", | |
| "cells": { | |
| benchmark: { | |
| method: stats["ordered_mse_x1e3"] | |
| for method, stats in methods.items() | |
| } | |
| for benchmark, methods in run["cells"].items() | |
| }, | |
| }, | |
| ) | |
| ) | |
| reward = step.reward | |
| details = step.observation.metadata.get("score_details", {}) if hasattr(step, "observation") else {} | |
| matched = details.get("matched_cells") | |
| total = details.get("total_cells") | |
| print(f"reward: {reward}") | |
| print(f"matched cells: {matched}/{total}, full credit: {details.get('full_credit')}") | |
| return 0 if reward == 1.0 else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |