"""Small curated benchmark for the task planner. Each case: scene objects, instruction, and a gold list of (skill, object, location-keyword) steps; `None` gold means the planner must declare the task infeasible. Matching is order-sensitive on (skill, object); location only needs to contain the keyword. """ from __future__ import annotations CASES: list[dict] = [ # --- single-step --- {"scene": ["red cube", "blue bowl"], "instr": "pick up the red cube", "gold": [("pick", "red cube", None)]}, {"scene": ["drawer", "green cube"], "instr": "open the drawer", "gold": [("open", "drawer", None)]}, # --- pick & place --- {"scene": ["red cube", "blue bowl", "green cube"], "instr": "put the red cube in the blue bowl", "gold": [("pick", "red cube", None), ("place", "red cube", "bowl")]}, {"scene": ["yellow cube", "green cube", "plate"], "instr": "stack the yellow cube on the green cube", "gold": [("pick", "yellow cube", None), ("stack", "yellow cube", "green")]}, # --- multi-object / long-horizon --- {"scene": ["red cube", "green cube", "blue bowl"], "instr": "put both cubes in the bowl, red first", "gold": [("pick", "red cube", None), ("place", "red cube", "bowl"), ("pick", "green cube", None), ("place", "green cube", "bowl")]}, {"scene": ["drawer", "red cube"], "instr": "put the red cube in the drawer and close it", "gold": [("open", "drawer", None), ("pick", "red cube", None), ("place", "red cube", "drawer"), ("close", "drawer", None)]}, {"scene": ["red cube", "green cube", "blue cube"], "instr": "build a tower: blue at the bottom, then green, then red on top", "gold": [("pick", "green cube", None), ("stack", "green cube", "blue"), ("pick", "red cube", None), ("stack", "red cube", "green")]}, # --- implicit / commonsense --- {"scene": ["apple", "banana", "fruit bowl", "screwdriver"], "instr": "tidy up the fruit", "gold": [("pick", "apple", None), ("place", "apple", "bowl"), ("pick", "banana", None), ("place", "banana", "bowl")], "any_order": True}, {"scene": ["mug", "sponge", "sink"], "instr": "I'm done with my mug, put it where dirty dishes go", "gold": [("pick", "mug", None), ("place", "mug", "sink")]}, {"scene": ["red cube", "blue bowl"], "instr": "when you're finished, return the arm to its rest pose", "gold": [("home", None, None)]}, # --- must refuse (infeasible) --- {"scene": ["red cube", "blue bowl"], "instr": "put the green cube in the bowl", "gold": None}, {"scene": ["red cube", "blue bowl"], "instr": "fly to the kitchen and make coffee", "gold": None}, ] def _norm(s: str | None) -> str: return (s or "").lower().strip() def step_match(pred, gold) -> bool: skill, obj, loc = gold if pred.skill != skill: return False if obj and _norm(pred.object) != obj: return False return not loc or loc in _norm(pred.location) def score(plan, gold, any_order: bool = False) -> bool: if gold is None: return len(plan.steps) == 0 # tolerate an optional trailing "home" the planner may add steps = [s for s in plan.steps if s.skill != "home"] if not any(g[0] == "home" for g in gold) else plan.steps if len(steps) != len(gold): return False if any_order: # pick/place pairs may come in any object order pairs_p = sorted(zip(steps[::2], steps[1::2]), key=lambda p: _norm(p[0].object)) pairs_g = sorted(zip(gold[::2], gold[1::2]), key=lambda p: p[0][1]) return all(step_match(a, b) and step_match(c, d) for (a, c), (b, d) in zip(pairs_p, pairs_g)) return all(step_match(p, g) for p, g in zip(steps, gold))