mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-07 10:01:56 +00:00
645c87e3a9
* refactor(converters): move batch transition functions to converters module - Moved `_default_batch_to_transition` and `_default_transition_to_batch` functions from `pipeline.py` to `converters.py` for better organization and separation of concerns. - Updated references in `RobotProcessor` to use the new location of these functions. - Added tests to ensure correct functionality of the transition functions, including handling of index and task_index fields. - Removed redundant tests from `pipeline.py` to streamline the test suite. * refactor(processor): reorganize EnvTransition and TransitionKey definitions - Moved `EnvTransition` and `TransitionKey` classes from `pipeline.py` to a new `core.py` module for better structure and maintainability. - Updated import statements across relevant modules to reflect the new location of these definitions, ensuring consistent access throughout the codebase. * refactor(converters): rename and update dataset frame conversion functions - Replaced `to_dataset_frame` with `transition_to_dataset_frame` for clarity and consistency in naming. - Updated references in `record.py`, `pipeline.py`, and tests to use the new function name. - Introduced `merge_transitions` to streamline the merging of transitions, enhancing readability and maintainability. - Adjusted related tests to ensure correct functionality with the new naming conventions. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix(processor): solve conflict artefacts * refactor(converters): remove unused identity function and update type hints for merge_transitions * refactor(processor): remove unused identity import and clean up gym_manipulator.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Palma <steven.palma@huggingface.co>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
|
|
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
|
|
#
|
|
# 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.
|
|
|
|
from __future__ import annotations
|
|
|
|
from enum import Enum
|
|
from typing import Any, TypedDict
|
|
|
|
import torch
|
|
|
|
|
|
class TransitionKey(str, Enum):
|
|
"""Keys for accessing EnvTransition dictionary components."""
|
|
|
|
# TODO(Steven): Use consts
|
|
OBSERVATION = "observation"
|
|
ACTION = "action"
|
|
REWARD = "reward"
|
|
DONE = "done"
|
|
TRUNCATED = "truncated"
|
|
INFO = "info"
|
|
COMPLEMENTARY_DATA = "complementary_data"
|
|
|
|
|
|
EnvTransition = TypedDict(
|
|
"EnvTransition",
|
|
{
|
|
TransitionKey.OBSERVATION.value: dict[str, Any] | None,
|
|
TransitionKey.ACTION.value: Any | torch.Tensor | None,
|
|
TransitionKey.REWARD.value: float | torch.Tensor | None,
|
|
TransitionKey.DONE.value: bool | torch.Tensor | None,
|
|
TransitionKey.TRUNCATED.value: bool | torch.Tensor | None,
|
|
TransitionKey.INFO.value: dict[str, Any] | None,
|
|
TransitionKey.COMPLEMENTARY_DATA.value: dict[str, Any] | None,
|
|
},
|
|
)
|