Download scripts/execute_notebook.py from pranay5255/agent-trajectory-study-20260930: direct link, hf CLI and curl.
- Browser
- Download file 3.84 kB
-
https://huggingface.co/datasets/pranay5255/agent-trajectory-study-20260930/resolve/main/scripts/execute_notebook.py
- Command line
-
hf download hf://datasets/pranay5255/agent-trajectory-study-20260930/scripts/execute_notebook.py
-
curl -L -o execute_notebook.py https://huggingface.co/datasets/pranay5255/agent-trajectory-study-20260930/resolve/main/scripts/execute_notebook.py
3.84 kB
| """Execute the notebook in a fresh CPU kernel, with an 8 GiB address-space cap.""" | |
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| import resource | |
| import sys | |
| import time | |
| import nbformat | |
| from nbclient import NotebookClient | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--remote", action="store_true") | |
| parser.add_argument("--revision") | |
| parser.add_argument("--output", type=Path, default=Path("/tmp/trajectory_eda_executed.ipynb")) | |
| args = parser.parse_args() | |
| root = Path(__file__).resolve().parents[1] | |
| os.environ.update(MPLCONFIGDIR="/tmp/trajectory_mpl", OPENBLAS_NUM_THREADS="1", OMP_NUM_THREADS="1", | |
| CUDA_VISIBLE_DEVICES="", HF_HUB_DISABLE_IMPLICIT_TOKEN="1", HF_HOME="/tmp/trajectory_anonymous_hf") | |
| os.environ.pop("HF_TOKEN", None) | |
| os.environ["CORPUS_EXPORT_DIR"] = "/tmp/trajectory_eda_exports" | |
| if args.remote: | |
| os.environ.pop("CORPUS_LOCAL_ROOT", None) | |
| else: | |
| os.environ["CORPUS_LOCAL_ROOT"] = str(root) | |
| if args.revision: | |
| os.environ["CORPUS_REVISION"] = args.revision | |
| resource.setrlimit(resource.RLIMIT_AS, (8 * 1024**3, 8 * 1024**3)) | |
| kernel_dir = Path("/tmp/trajectory_jupyter/kernels/trajectory-cpu") | |
| kernel_dir.mkdir(parents=True, exist_ok=True) | |
| (kernel_dir / "kernel.json").write_text(json.dumps({ | |
| "argv":[sys.executable,"-m","ipykernel_launcher","-f","{connection_file}"], | |
| "display_name":"Trajectory CPU validation", "language":"python"})) | |
| os.environ["JUPYTER_PATH"] = "/tmp/trajectory_jupyter" | |
| nb = nbformat.read(root / "trajectory_eda_colab.ipynb", as_version=4) | |
| nb.cells.append(nbformat.v4.new_code_cell(""" | |
| # Validation-only checks for lazy examples and the interactive callback. | |
| process = example_summary.loc[(example_summary.example_kind == 'process') & (example_summary.truncated == True)].iloc[0] | |
| assert inspect_example(process.example_id)['metadata']['truncated'] is True | |
| packet = example_summary.loc[example_summary.example_kind == 'experiment1_judge_packet'].iloc[0] | |
| assert inspect_example(packet.example_id)['packet_id'] == packet.example_id | |
| controls['collection'].value = 'olmo' | |
| rejected = episodes.loc[(episodes.collection == 'olmo') & (episodes.rejected_responses > 0)].sort_values('events').iloc[0] | |
| picker.value = rejected.episode_id | |
| canonical_only.value = False | |
| only_rejected.value = True | |
| show_timeline() | |
| assert selected_bundle['episode']['episode_id'] == rejected.episode_id | |
| assert any(e['rejected_response'] for e in selected_bundle['events']) | |
| controls['collection'].value = 'qwen' | |
| assert all(eid in set(episodes.loc[episodes.collection == 'qwen','episode_id']) for label,eid in picker.options) | |
| print('Inspector filters, rejected-response callback, truncated example, and packet loads passed.') | |
| """)) | |
| start = time.monotonic() | |
| client = NotebookClient(nb, timeout=240, kernel_name="trajectory-cpu", resources={"metadata":{"path":"/tmp"}}) | |
| client.execute() | |
| nbformat.write(nb, args.output) | |
| report = {"status":"passed", "mode":"anonymous_remote" if args.remote else "local_publication_copy", | |
| "code_cells_executed":sum(c.cell_type == "code" for c in nb.cells), | |
| "elapsed_seconds":round(time.monotonic()-start,2), "address_space_cap_gib":8, | |
| "peak_child_rss_mib":round(resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss/1024,2), | |
| "gpu_visible":False, "model_calls":0, "login_required":False, | |
| "dataset_revision":args.revision or "resolved_inside_notebook", "executed_notebook":str(args.output)} | |
| target = root / "provenance" / ("notebook_anonymous_execution.json" if args.remote else "notebook_cpu_execution.json") | |
| target.write_text(json.dumps(report,indent=2)+"\n") | |
| print(json.dumps(report,indent=2)) | |
| if __name__ == "__main__": | |
| main() | |