Download sample/tasks/inspect/inspect_task.py from zero-trust-physics/zero-trust-physics-sample-group-4: direct link, hf CLI and curl.
- Browser
- Download file 7.06 kB
-
https://huggingface.co/datasets/zero-trust-physics/zero-trust-physics-sample-group-4/resolve/main/sample/tasks/inspect/inspect_task.py
- Command line
-
hf download hf://datasets/zero-trust-physics/zero-trust-physics-sample-group-4/sample/tasks/inspect/inspect_task.py
-
curl -L -o inspect_task.py https://huggingface.co/datasets/zero-trust-physics/zero-trust-physics-sample-group-4/resolve/main/sample/tasks/inspect/inspect_task.py
7.06 kB
| """The free sample multi-step physics tasks as one Inspect task (inspect_ai, https://inspect.aisi.org.uk). | |
| pip install inspect-ai mcp | |
| export ZTP_ENGINE=/absolute/path/to/mcp_stdio_local the verifier of release 0.15.3 (commit 664d68f4) over MCP stdio: | |
| mcp_stdio_local beside this file, in a paid pack, runs the bundled | |
| compiled verifier with no network; mcp_stdio_open runs the open | |
| address, https://mcp.zerotrustphysics.com/mcp, through ztp_open_bridge.py | |
| inspect eval inspect_task.py --model <provider>/<model> | |
| Each sample is exactly the text prompt.py prints for one task, with the verifier (the program at ZTP_ENGINE over MCP | |
| stdio) as the agent's tool server. The agent works in many steps: Inspect's generate loop sends every tool call to the | |
| verifier and hands the answer back until the model gives its final reply or the message limit is reached. In the | |
| design_to_limit and chained_design kinds the agent also has Inspect's python tool, because a coupling hands a run's | |
| frames to a solve bit for bit and the frames come as hex: reading them is arithmetic, not physics. That tool runs in a | |
| Docker sandbox (sandbox/compose.yaml: a plain Python image, no network, none of the task rows and no verifier), so the | |
| agent's code reaches neither the answer key nor the verifier off the record. In a chained design that continues a run (from), the next run's start is the first run's final state as the verifier returned it. The budgeted_search and forensics kinds | |
| have the verifier and nothing else, and need no sandbox. The verifier itself runs on the host, reached only through | |
| its MCP tools. | |
| The model's last message is its reply; every call of the verifier's tools in state.messages is its call log, in order | |
| (python tool calls are not verifier calls and are not counted). The scorer is score.py's own, held by pack_score.py to | |
| the release (version 0.15.3, kernel genesis_kernel_v0.13.1), whichever program serves it: it | |
| verifies each proof on the card on the verifier, computes each request again, and gives correct and proofs_hold, each | |
| 0 or 1, with the reason for a 0; reward is 1 only when both are 1. | |
| inspect eval inspect_task.py -T kind=budgeted_search --model <provider>/<model> | |
| inspect eval inspect_task.py -T python=false --model <provider>/<model> | |
| inspect eval inspect_task.py --sample-id <task id> --epochs 8 --model <provider>/<model> pass@8 on one task | |
| Protocol Company. | |
| """ | |
| import asyncio | |
| import json | |
| import os | |
| import sys | |
| from inspect_ai import Task, task | |
| from inspect_ai.dataset import Sample | |
| from inspect_ai.scorer import Score, Target, mean, scorer | |
| from inspect_ai.solver import TaskState, generate, solver, use_tools | |
| from inspect_ai.tool import mcp_server_stdio, mcp_tools | |
| from inspect_ai.tool import python as python_tool | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, HERE) | |
| import prompt as the_prompt # noqa: E402 | |
| import pack_score # noqa: E402 | |
| the_scorer = pack_score.install() | |
| ENVIRONMENTS = os.path.join(HERE, "data", "environments.jsonl") | |
| SANDBOX = os.path.join(HERE, "sandbox", "compose.yaml") | |
| CODE_FAMILIES = ("tradeoff", "chain_design") | |
| KINDS = {"tradeoff": "design_to_limit", "chain_design": "chained_design", "budget": "budgeted_search", "forensics": "forensics"} | |
| def engine_path(engine=None): | |
| path = engine or os.environ.get("ZTP_ENGINE") | |
| if not path: | |
| raise ValueError("give the path to mcp_stdio: set ZTP_ENGINE, or pass -T engine=/absolute/path/to/mcp_stdio") | |
| if not os.path.isfile(path): | |
| raise ValueError("no file at %s: ZTP_ENGINE is the path to the program mcp_stdio" % path) | |
| return os.path.abspath(path) | |
| def calls_of(messages): | |
| """Every call of the verifier's tools in the conversation, in order, as score.py reads a call log: [(tool, arguments)].""" | |
| calls = [] | |
| for message in messages: | |
| for call in getattr(message, "tool_calls", None) or []: | |
| tool = the_scorer.tool_name(call.function) | |
| if tool not in the_scorer.VERIFIER_TOOLS: | |
| continue # the python tool: not a verifier call | |
| arguments = call.arguments | |
| if isinstance(arguments, str): | |
| try: | |
| arguments = json.loads(arguments) | |
| except ValueError: | |
| arguments = {} | |
| calls.append((tool, arguments if isinstance(arguments, dict) else {})) | |
| return calls | |
| def score_one(environment, reply, calls, engine): | |
| try: | |
| verifier = the_scorer.open_verifier(engine) | |
| try: | |
| return the_scorer.score(environment, reply, the_scorer.Replay(verifier), calls) | |
| finally: | |
| the_scorer.close_verifier(verifier) | |
| except SystemExit as stopped: | |
| raise RuntimeError(str(stopped)) from None | |
| def computed_again_on_the_verifier(engine, environments): | |
| by_id = {e["id"]: e for e in environments} | |
| async def score(state: TaskState, target: Target) -> Score: | |
| reply = state.output.completion or "" | |
| row = await asyncio.to_thread(score_one, by_id[state.sample_id], reply, calls_of(state.messages), engine) | |
| lines = [line for line in reply.strip().splitlines() if line.strip()] | |
| return Score(value={"reward": row["reward"], "correct": row["correct"], "proofs_hold": row["proofs_hold"]}, | |
| answer=lines[-1] if lines else "", explanation=row["reason"]) | |
| return score | |
| def tools_for_the_kind(verifier, with_python): | |
| async def solve(state, generate_): | |
| tools = [mcp_tools(verifier)] | |
| if with_python and state.metadata.get("family") in CODE_FAMILIES: | |
| tools.append(python_tool()) | |
| return await use_tools(*tools)(state, generate_) | |
| return solve | |
| def zero_trust_physics_sample(engine: str | None = None, kind: str | None = None, python: bool = True, | |
| message_limit: int = 200): | |
| path = engine_path(engine) | |
| environments = the_scorer.load_environments(ENVIRONMENTS) | |
| if kind is not None: | |
| if kind not in KINDS.values(): | |
| raise ValueError("kind is one of %s" % ", ".join(KINDS.values())) | |
| environments = [e for e in environments if (e.get("kind") or KINDS[e["family"]]) == kind] | |
| verifier = mcp_server_stdio(name="verifier", command=path) | |
| code_tasks = python and any(e["family"] in CODE_FAMILIES for e in environments) | |
| return Task( | |
| dataset=[Sample(id=e["id"], input=the_prompt.prompt(e), | |
| metadata={"family": e["family"], "kind": e.get("kind") or KINDS[e["family"]]}) for e in environments], | |
| solver=[tools_for_the_kind(verifier, python), generate()], | |
| scorer=computed_again_on_the_verifier(path, environments), | |
| sandbox=("docker", SANDBOX) if code_tasks else None, | |
| message_limit=message_limit, | |
| ) | |