-
Notifications
You must be signed in to change notification settings - Fork 811
feat(evals): ground-truth store, predicate library, xarm7 tabletop suite #4040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jerrybery
wants to merge
3
commits into
dimensionalOS:main
Choose a base branch
from
Jerrybery:feat/evals-gt-store
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """GT recorder: the simulator's privileged object poses, recorded for scoring. | ||
|
|
||
| Subscribes ``/gt_object_poses`` (MujocoSimModule ``publish_ground_truth``) | ||
| over LCM and records it to its own db, separate from the agent-visible | ||
| recording — ground truth must never leak into the agent's memory. The eval | ||
| runner deploys this per case that declares ``ground_truth=True``; scorers | ||
| read it back through ``EvalRunner.gt_store()`` and | ||
| :mod:`dimos.evals.predicates`. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dimos.core.stream import In | ||
| from dimos.memory.module import Recorder | ||
| from dimos.msgs.geometry_msgs.PoseStamped import PoseStamped | ||
|
|
||
|
|
||
| class GTRecorder(Recorder): | ||
| """Records the GT object pose stream to ``db_path``. | ||
|
|
||
| GT poses are already world-frame (frame_id = body name, no tf anchor), | ||
| so deploy with ``poseless_streams=[predicates.GT_STREAM]`` and | ||
| ``record_tf=False``. The stream keeps the port name — the wiring layer | ||
| names topics after it. | ||
| """ | ||
|
|
||
| gt_object_poses: In[PoseStamped] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # Copyright 2026 Dimensional Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Ground-truth predicates: physical outcomes from simulator truth, not agent memory. | ||
|
|
||
| Interactive cases that declare ``ground_truth=True`` get a second store in | ||
| their score callable — the GT recorder's db of world poses the sim publishes | ||
| for every free-joint scene body (MujocoSimModule ``publish_ground_truth``). | ||
| Predicates here turn a role's pose history into a 0.0/1.0 outcome that | ||
| composes with the usual scorers and aggregates:: | ||
|
|
||
| ROLES = {"cup": "cup", "apple": "apple"} | ||
|
|
||
| def score(store: Store, gt: Store) -> float: | ||
| picked = lifted(gt, ROLES, "cup", min_delta=0.05) | ||
| collateral = displaced(gt, ROLES, "apple", threshold=0.10) | ||
| return picked * (1.0 - collateral) | ||
|
|
||
| InteractiveEval(..., score=score, ground_truth=True, aggregate=final) | ||
|
|
||
| ``roles`` maps the case's semantic names to GT body names (the pose's | ||
| ``frame_id``). All predicates raise LookupError while the GT stream has no | ||
| data for the role — the runner's sampler treats LookupError as "not yet, | ||
| keep waiting". | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from dimos.msgs.geometry_msgs.PoseStamped import PoseStamped | ||
|
|
||
| if TYPE_CHECKING: | ||
| from dimos.memory.store.base import Store | ||
|
|
||
| GT_STREAM = "gt_object_poses" | ||
| """Stream (and module port) the simulator's ground-truth poses flow on.""" | ||
|
|
||
| # Body up-axis alignment below which a pose counts as toppled (cos 60°). | ||
| _UP_DOT_MIN = 0.5 | ||
|
|
||
|
|
||
| def gt_poses( | ||
| gt: Store, roles: Mapping[str, str], role: str, *, stream: str = GT_STREAM | ||
| ) -> list[PoseStamped]: | ||
| """Time-ordered world poses of the body *role* maps to. | ||
|
|
||
| The GT stream multiplexes every scene body on one stream; ``frame_id`` | ||
| carries the body name. | ||
| """ | ||
| body = roles[role] | ||
| poses = [obs.data for obs in gt.streams[stream] if obs.data.frame_id == body] | ||
| if not poses: | ||
| raise LookupError(f"no GT poses for role {role!r} (body {body!r}) on stream {stream!r}") | ||
| return poses | ||
|
|
||
|
|
||
| def lifted(gt: Store, roles: Mapping[str, str], role: str, *, min_delta: float) -> float: | ||
| """1.0 once the body's z rises ``min_delta`` above its episode-start z.""" | ||
| poses = gt_poses(gt, roles, role) | ||
| gain = max(p.position.z for p in poses) - poses[0].position.z | ||
| return float(gain > min_delta) | ||
|
|
||
|
|
||
| def displaced(gt: Store, roles: Mapping[str, str], role: str, *, threshold: float) -> float: | ||
| """1.0 once the body's xy distance from its episode-start xy exceeds | ||
| ``threshold`` — the knock-down/knock-aside detector.""" | ||
| poses = gt_poses(gt, roles, role) | ||
| x0, y0 = poses[0].position.x, poses[0].position.y | ||
| farthest = max(((p.position.x - x0) ** 2 + (p.position.y - y0) ** 2) ** 0.5 for p in poses) | ||
| return float(farthest > threshold) | ||
|
|
||
|
|
||
| def knocked_over(gt: Store, roles: Mapping[str, str], role: str) -> float: | ||
| """1.0 once the body's up axis tips more than 60° off world-up.""" | ||
| poses = gt_poses(gt, roles, role) | ||
| for p in poses: | ||
| up_z = p.orientation.to_rotation_matrix()[2, 2] | ||
| if up_z < _UP_DOT_MIN: | ||
| return 1.0 | ||
| return 0.0 | ||
|
|
||
|
|
||
| def near(gt: Store, roles: Mapping[str, str], role_a: str, role_b: str, *, dist: float) -> float: | ||
| """1.0 when the two bodies' latest positions are within ``dist`` (3D).""" | ||
| a, b = gt_poses(gt, roles, role_a)[-1], gt_poses(gt, roles, role_b)[-1] | ||
| return float((a.position - b.position).length() <= dist) | ||
|
|
||
|
|
||
| def contained( | ||
| gt: Store, | ||
| roles: Mapping[str, str], | ||
| role_a: str, | ||
| role_b: str, | ||
| *, | ||
| xy_tol: float = 0.1, | ||
| ) -> float: | ||
| """1.0 when a sits inside b: within ``xy_tol`` of b's xy and above b's z. | ||
|
|
||
| Pose-derived approximation — GT carries body poses, not shape extents, | ||
| so b's "footprint" is the tolerance disc around its center and its "top" | ||
| is its origin height. Size ``xy_tol`` to the container, not the content. | ||
| """ | ||
| a, b = gt_poses(gt, roles, role_a)[-1], gt_poses(gt, roles, role_b)[-1] | ||
| dx, dy = a.position.x - b.position.x, a.position.y - b.position.y | ||
| return float((dx**2 + dy**2) ** 0.5 <= xy_tol and a.position.z > b.position.z) | ||
|
|
||
|
|
||
| def grasped(gt: Store, roles: Mapping[str, str], role: str) -> float: | ||
| """Whether the gripper holds the object — placeholder. | ||
|
|
||
| Not decidable from poses alone: a pose-only heuristic (object tracks the | ||
| end effector) also fires on pushes and drags. Blocked on the contact / | ||
| gripper-force channel from issue #3594 phase 2. | ||
| """ | ||
| raise NotImplementedError( | ||
| "grasped() needs the contact channel (issue #3594 phase 2); poses alone can't tell a grasp from a push" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This multiplexed input is recorded through the inherited recorder callback, which retains only the latest unprocessed message. MuJoCo sends one pose message per object in succession, so a later object's update can replace an earlier update when SQLite recording falls behind. The tabletop scorer can then receive no history for the cup or a bystander and fail an otherwise valid evaluation. Record this stream through a lossless serialized queue, or publish each tick's object poses as one atomic message.
Knowledge Base Used: Robot memory services