Skip to content

[FEATURE] Add history_length to Sensors#2655

Open
Milotrince wants to merge 13 commits intoGenesis-Embodied-AI:mainfrom
Milotrince:sensor_history
Open

[FEATURE] Add history_length to Sensors#2655
Milotrince wants to merge 13 commits intoGenesis-Embodied-AI:mainfrom
Milotrince:sensor_history

Conversation

@Milotrince
Copy link
Copy Markdown
Contributor

@Milotrince Milotrince commented Apr 4, 2026

Description

  • Support history_length for all sensors
  • Detect whether to update_ground_truth_only instead of user having to set the option
  • Add filter_link_idx for Contact sensor

Related Issue

Resolves #2646

Motivation and Context

See issue

How Has This Been / Can This Be Tested?

Added tests/test_sensors.py::test_sensor_history_length_contact_and_imu

Screenshots (if appropriate):

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@Milotrince Milotrince marked this pull request as draft April 4, 2026 04:45
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3672bb240e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/options/sensors/options.py
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

🔴 Benchmark Regression Detected ➡️ Report

@duburcqa
Copy link
Copy Markdown
Collaborator

duburcqa commented Apr 5, 2026

@claude review

@Milotrince Milotrince marked this pull request as ready for review April 5, 2026 18:02
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Comment on lines 228 to +248
def get_cloned_from_cache(self, sensor: "Sensor", is_ground_truth: bool = False) -> torch.Tensor:
dtype = sensor._get_cache_dtype()
if sensor._history_length > 0:
ring = (
self._gt_timeline_ring.get(dtype)
if is_ground_truth
else (self._measured_history_ring.get(dtype) or self._gt_timeline_ring.get(dtype))
)
hist_cache_key = (is_ground_truth, dtype, sensor._cache_idx)
if (cached := self._history_clone_cache.get(hist_cache_key)) is not None:
return cached

hist_idx = torch.arange(sensor._history_length, device=ring.buffer.device, dtype=torch.int32)
blocks = []
for rel_slice in sensor._cache_slices:
abs_slice = slice(sensor._cache_idx + rel_slice.start, sensor._cache_idx + rel_slice.stop)
hist = ring.at(hist_idx, slice(None), abs_slice)
blocks.append(hist.transpose(0, 1).flatten(1, 2))
stacked = torch.cat(blocks, dim=1)
self._history_clone_cache[hist_cache_key] = stacked
return stacked
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current implementation of history is with minimal changes to the current system, so history per sensor is collected upon read like this. should we restructure somehow to make this more efficient or is this ok?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we restructure somehow to make this more efficient or is this ok?

Yes. We should.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would you suggest? each sensor may have varying lengths of history

Copy link
Copy Markdown
Contributor Author

@Milotrince Milotrince Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently: manager has _ground_truth_cache shape(dtype_size, B), _cache shape(dtype_size, B), calls _update_shared_ground_truth_cache() , _update_shared_cache() per sensor class based update_ground_truth_only

im thinking to do: manager has _ground_truth_cache and _cache shape (sensor_size, max_history_len_per_sensor_class, B), calls _update_shared_cache() per sensor class which updates both caches (whether to skip some computation for measured cache based on options can be decided per sensor cls)

i want to avoid flattening the history dim into the cache because it will complicate indexing, and having max history length per dtype instead of sensor might allocate too much unused space if, say, history=10 is used for ContactForce sensors in the scene and no history used for Proximity sensor

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df53cf6e2f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/engine/sensors/sensor_manager.py
Comment thread genesis/engine/sensors/base_sensor.py Outdated
@duburcqa
Copy link
Copy Markdown
Collaborator

duburcqa commented Apr 6, 2026

@claude review

Comment thread genesis/options/sensors/camera.py
Comment thread genesis/engine/sensors/base_sensor.py
@Milotrince
Copy link
Copy Markdown
Contributor Author

bump!

Comment thread genesis/engine/sensors/base_sensor.py Outdated
Comment thread genesis/engine/sensors/base_sensor.py Outdated
Comment on lines +163 to +164
def _options_require_measured_cache(self):
return np.any(np.abs(self._options.delay) > gs.EPS)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding this helper? I hate one-liner functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sensor classes extend this with super()

Comment thread genesis/engine/sensors/base_sensor.py Outdated
Comment on lines +546 to +555
def _options_require_measured_cache(self) -> bool:
return super()._options_require_measured_cache() or (
self._options.jitter > gs.EPS
or (self._options.interpolate and (self._delay_ts > 0 or self._options.jitter > gs.EPS))
or np.any(np.abs(self._options.bias) > gs.EPS)
or np.any(np.abs(self._options.noise) > gs.EPS)
or np.any(np.abs(self._options.random_walk) > gs.EPS)
or np.any(np.abs(self._options.resolution) > gs.EPS)
or np.any(np.array(self._options.jitter) > gs.EPS)
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this branching. I would rather always have measured cache always enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's check how much it affects performance

Comment thread genesis/options/sensors/camera.py
Comment thread tests/test_sensors.py Outdated
Comment thread tests/test_sensors.py Outdated
Comment thread tests/test_sensors.py Outdated
Comment thread tests/test_sensors.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: history_length support for ContactForceSensor

2 participants