Repository navigation
Description
Proposal
Many methods use observation histories (e.g. RMA/Student-Teacher Methods, Async ActorCritic, etc.) but histories are not currently supported by default. It is easy to make a wrapper class observation that stores histories on a per-observation term level, but there doesn't appear to be a way to store histories at the observation group level. Sometimes, e.g. for images it may be desirable to stack the history in terms of the individual observation term, but other times it may be more desirable to stack the history at the group level (which would require a change to the manager). This was something we had an implementation for at BDAI. Is this something that is currently already being worked on? If not I would be happy to take it on, but wasn't going to start working on it for a PR if someone else is already doing so.
Alternatives
- Using the Observation Term class functionality to implement histories on a per-term basis, eg this minimal implementation. This stacks obs terms A B C as AAABBBCCC for history=3.
class HistoryObsWrapper(ManagerTermBase):
def __init__(self, env: ManagerBasedRLEnvCfg, cfg: ObservationTermCfg) -> None:
super().__init__(cfg, env)
self.func = self.cfg.params["func"]
if isinstance(self.func, ManagerTermBase):
self.func = self.func(env, cfg)
self.obs_len = self.func(env, **self.cfg.params["func_params"]).size(-1) # TODO generalize this to multiD obs
self.history_len = self.cfg.params["history_len"]
self.data = torch.zeros(self.num_envs, self.history_len, self.obs_len, device=self.device)
self.scale = self.cfg.params["scale"]
def reset(self, env_ids: torch.Tensor = None) -> None:
if isinstance(self.func, ManagerTermBase):
self.func.reset(env_ids)
self.data[env_ids] = self.func(self._env, **self.cfg.params["func_params"])[env_ids].view(-1, 1, self.obs_len).expand(-1, self.history_len, -1)
def __call__(self, env, func, history_len, func_params, scale) -> torch.Tensor:
self.data = self.data.roll(1, dims=1)
self.data[:, 0] = self.func(self._env, **self.cfg.params["func_params"])
return self.scale * self.data.clone().flatten(start_dim=1)
- Using the Observation Group maybe with a post_init flag to stack whole observations as a history. This stacks obs terms A B C as ABCABCABC for history=3.
- Histories could also be handled at the RL framework/policy level. It is my belief this would be better handled by Isaac Lab directly, but it is an option to just require frameworks to deal with it themselves, e.g. the storage buffer in rsl_rl.
Checklist
- I have checked that there is no similar issue in the repo
Acceptance Criteria
Add the criteria for which this task is considered done. If not known at issue creation time, you can add this once the issue is assigned.
- Option to stack histories at a per-term level
- Option to stack histories at a per-group level
Activity
mpgussert commentedon Oct 10, 2024
Hello @KyleM73
To my knowledge our sensor base class is designed to support recording history https://github.com/isaac-sim/IsaacLab/blob/main/source/extensions/omni.isaac.lab/omni/isaac/lab/sensors/sensor_base.py
checkout the contact sensor, for example
IsaacLab/source/extensions/omni.isaac.lab/omni/isaac/lab/sensors/contact_sensor/contact_sensor.py
Line 291 in cb9fee6
Does this meet your needs? If not, can it be built on the current sensor history API?
KyleM73 commentedon Oct 10, 2024
For observations that are just reading sensors that would satisfy the per-term history, but not the per-group history. In addition, not all observations come from reading sensor data, for example last action (currently only supports a single step) or generated commands. Maybe this is a larger question of "where should histories be stored", but unless the design decision is to implement a corresponding sensor for each observation type, it seems to me like there should be a way to track observation histories more generally i.e. separate from the sensor history API. If the desired solution is to always do it at a per-term level then I can PR a cleaned-up version of the code I provided above to the core isaac.lab MDP. But I do think there is value in supporting histories at a per-group level. I would love to hear feedback either way, for per-term and/or per-group histories.
KyleM73 commentedon Oct 10, 2024
One additional consideration for dealing with this at the manager level as opposed to the observation term level is when adding noise for DR. Using the code I provided above, independent and DIFFERENT noise will be added to the history at each time step by the manager, but this is not realistic, as the noise added at time step k should be the same noise observed for the previous time step when the current step is k+1. This doesn't make a huge difference in practice as the policy learns to be robust to the noise anyways, but it is wrong.
Mayankm96 commentedon Oct 11, 2024
Hi @KyleM73,
I agree. This is a feature we should have. There are many different ways you can do this (depending on the end goal):
@jtigue-bdai will be able to provide better guidance here
KyleM73 commentedon Oct 11, 2024
Thrilled to work with @jtigue-bdai again :)
Some additional thoughts: The best case scenario allows for both obs terms and obs groups to be configured. For example, maybe a history of joint velocities is desired (eg to estimate acceleration if it isn't available on a given robot), but only the most recent command. In that case, the implementation would need to function at the per-term level. Alternatively, for methods like RMA or concurrent estimation, the policy and estimator, respectively, receive obs group histories, and doing so would be more efficient than handling it at the per-term level. I personally think both per-term and per-group should be supported. We could in theory handle this as an env wrapper with a config specifying how many time steps to record for each obs term and group separately. This would be the most efficient but also feels somewhat hacky and not in line with the design of the rest of the manager-based framework, although I'm happy to implement it however. Looking forward to thoughts!
diracdelta7 commentedon Nov 2, 2024
When using the modifier to record observation history,
ObservationManagerencounters difficulty in determining the correct dimensions for the associated observation term.In ObservationManager, the following code attempts to call the observation function once to establish the dimensions for each term:
This approach works when observations maintain fixed dimensions throughout the processing. However, the modifier changes the dimensions by appending additional historical data, which
ObservationManagerdoes not know for now. This results in a dimension mismatch.Would this discrepancy pose any issues during training or evaluation? From my experience, it appears to only produce incorrect [INFO] Observation Manager dimension messages when starting training with rsl_rl. However, the neural network dimensions seem correct, and training proceeds without any errors.
KyleM73 commentedon Nov 2, 2024
When you say the history tracking modifier, what are you referring to? I do not believe there is currently a modifier for tracking history, although we could use that interface to do so. In the example code I provided above, the issue you mention is avoided because the observation buffer already starts out at the correct size, but at the start of each episode the buffer is either mostly full of zeros or set to the uniform value of the first encountered value until enough steps have elapsed to overwrite each element in the buffer. So long as the output is always of fixed size (either [num_envs, obs_length*H] or [num_envs, H, obs_length]) then the manager should have no trouble picking it up during the init. Is this what you're referring to or have I misunderstood?
diracdelta7 commentedon Nov 3, 2024
Thank you for the clarification; I understand now where my approach went wrong.
In my initial approach, I appended a modifier after the
funcmember. This modifier collects historical data into its own buffer, then outputs this buffer as a new observation to other modifiers or noise handlers, and finally as the observation itself. Here’s the code I used:Then, I set up an observation term like this:
Correct Approach Based on Your Code
The issue here is that
ObservationManagercalculates the observation dimension based on the originalmdp.joint_vel_relfunction, which doesn’t account for the modified dimensions introduced byHistoryBuffer.The correct approach is to modify the function itself to handle historical data, avoiding the need for an additional modifier:
Is this understanding correct?
jtigue-bdai commentedon Nov 4, 2024
Hey sorry I have been silent on here. Been preoccupied.
So Modifiers does not allow you to change the output size of the observation so a Modifier cannot (in its current formulation) be used to return history. It can be used to store history for use in delays, filters, etc.
In order to consistently handle history there are a few things to consider:
is_terminated_termin envs/mdp/rewards.py)ObservationManagerpotentially separated by ObservationGroup for managing history across many observations.contact_sensor)KyleM73 commentedon Nov 4, 2024
No worries, thanks for looking at it James!
As far as a PR would go, I think for sensor-based histories nothing needs to change, people can implement custom sensors to track histories if needed at greater than the policy rate. Similarly, for tracking at the observation term level the wrapper class I provided above (with some clean up perhaps) could be added as an observation to the isaac.lab.envs.mdp for people to wrap their obs in. The main new code needed would be for group-level obs histories, which would need to be handled by the manager, like you mentioned. I can start work on that soon. I would additionally be interested in writing documentation on how to use all three.
For the next 3 weeks I'm somewhat out of capacity due to a paper deadline, but post-thanksgiving this is a high priority for me, if you'd be willing to advise it. After thanksgiving I'll make a draft PR to work on this from. Does that all sound reasonable?
Thanks again!
jtigue-bdai commentedon Nov 4, 2024
@KyleM73 that sounds great, happy to advise and help get things going. Let me know if you need anything and good luck with the paper deadline.
ammousa commentedon Nov 18, 2024
Any update on this topic?
jtigue-bdai commentedon Nov 18, 2024
Hey @KyleM73 a user here at the Institute has implemented a Observation History functionality in parallel to what we have discussed. Its a bit of a blend to of the observation term wrapper class and the observation manager level implementations. In an effort to reduce duplication I think it would be good to move it up to a PR on the open source repo. Then we can make sure it satisfies all use cases.
3 remaining items
Adds observation term history support to Observation Manager (#1439)
Adds observation term history support to Observation Manager (isaac-s…
ubgk commentedon Mar 17, 2025
Are there any updates on per-group observation histories @jtigue-bdai ? I agree with @KyleM73 on his comments about handling history buffers on deployment code.
I currently need to handle individual buffers for each observation term when deploying on real hardware, which is somewhat unwieldly. I could also take a look at implementing this should nobody be working on it already.
jtigue-bdai commentedon Mar 17, 2025
@ubgk the PR actually handled this. The title and description were not clear on this but you can do term or group history.
See the ObservationGroupCfg and the ObservationTermCfg
KyleM73 commentedon Mar 17, 2025
If I'm understanding, @ubgk was referring to my request for group-level ordering. Right now (to my understanding) whether the history is triggered at term-level or group-level, the order is still by term. Eg if I have terms A,B,C, then the history will always be stored as AAABBBCCC, but the request is to be able to store histories as ABCABCABC. This is often easier to implement on hardware since you already have the last observation stored as a group, so you just have to pop and append the next observation to do history stacking, as opposed to having to track the history for each term separately.
jtigue-bdai commentedon Mar 17, 2025
Ah I see. I don't think I caught that when we created the feature. I don't think it's on our radar at the moment. If you want to take a stab at it go for it. Happy to review/advise.
ubgk commentedon Mar 17, 2025
Exactly @KyleM73, it would be more convenient to have the observations ordered as ABCABC than AABBCC (current behaviour AFAICT).
I understand that this is more of a "convenience" feature request than a "functional" one, so I can see why it may not be high priority. Nevertheless, I'd be willing to take a look at it if nobody else is already doing that!
Edit: @jtigue-bdai OK, just saw your message. :) Thanks for the green light.
KyleM73 commentedon Mar 17, 2025
I'm also happy to help/give feedback, just lmk if you want to chat @ubgk. Otherwise, thank you for looking more into this! I just haven't had time to dig more into it lately.
jtigue-bdai commentedon Apr 4, 2025
#1958 is addressing the history formulation from AABBCC to ABCABC
Adds observation term history support to Observation Manager (isaac-s…
YuHoChau commentedon Sep 12, 2025
Hello, I still want to confirm that the latest version of the Observation Manager still only supports the AABBCC format. Just wondering if there is any difference in training for this difference with ABCABC format (besides deploying on real hardware). Thank you.
KyleM73 commentedon Sep 12, 2025
Hi, yes that is correct. In terms of performance the order does not matter for MLPs, it only matters for architectures like CNNs and Transformers.
YuHoChau commentedon Sep 12, 2025
Thank you for the answer!
Adds observation term history support to Observation Manager (isaac-s…