Skip to content

Commit b6119b8

Browse files
committed
Merge branch 'main' into py310. Update readme.
2 parents 8981b8a + d9f0455 commit b6119b8

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ Scaffold for a modular imitation learning toolkit with dataset loaders, retarget
55

66
This is **only a skeleton**—fill in each module with real logic as you develop.
77

8+
## Installation
9+
10+
We recommend using the `conda-forge` channel for managing dependencies. For a faster experience, use `mamba` to create the environment and `uv` to install packages.
11+
12+
1. **Create and activate a conda environment:**
13+
```bash
14+
mamba create -n iltools python=3.10 -c conda-forge
15+
conda activate iltools
16+
```
17+
18+
2. **Install `uv`:**
19+
```bash
20+
pip install uv
21+
```
22+
23+
3. **Install the project:**
24+
From the root of this repository, run:
25+
```bash
26+
uv pip install -e .
27+
```
28+
*Note: Using the `-e` flag installs the project in "editable" mode, which is recommended for development.*
29+
30+
## Dataset Structure
31+
832
The structure of a dataset is as follows:
933

1034
```text
@@ -45,3 +69,77 @@ Dataset/
4569
│ └── ...
4670
└── ...
4771
```
72+
73+
## Usage
74+
75+
Here is an example of how to use the `TrajectoryDatasetManager` to load and step through a dataset, inspired by `tests/datasets/test_integration.py`.
76+
77+
```python
78+
import torch
79+
from tensordict import TensorDict
80+
81+
from iltools_datasets.dataset_manager import TrajectoryDatasetManager
82+
83+
# Mock configuration for demonstration
84+
class MockConfig:
85+
def __init__(self, **kwargs):
86+
for key, value in kwargs.items():
87+
setattr(self, key, value)
88+
89+
# 1. Configure the dataset manager
90+
# Replace 'path/to/your/dataset' with the actual path to your Zarr dataset directory.
91+
# This directory should contain 'trajectories.zarr' and 'metadata.json'.
92+
cfg = MockConfig(
93+
dataset_path='path/to/your/dataset',
94+
assignment_strategy='random', # or 'sequential', 'round_robin', 'curriculum'
95+
window_size=128
96+
)
97+
98+
# 2. Initialize the manager for a specified number of environments
99+
num_envs = 16
100+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
101+
manager = TrajectoryDatasetManager(cfg, num_envs, device)
102+
103+
# 3. Reset trajectories at the beginning of a training session
104+
manager.reset_trajectories()
105+
106+
# 4. Fetch reference data in a loop (e.g., inside your RL environment's step function)
107+
for _ in range(1000): # Simulate 1000 steps
108+
# Get a batch of reference data for the current timestep
109+
reference_data = manager.get_reference_data()
110+
111+
# The data is returned as a TensorDict for easy access
112+
# Shape: [num_envs, ...]
113+
com_positions = reference_data["com_pos"]
114+
joint_positions = reference_data["joint_pos"]
115+
116+
# Your agent would use this data to compute actions...
117+
# print(f"Step {_}: COM Position Batch Shape: {com_positions.shape}")
118+
119+
# To reset specific environments that have completed their episode:
120+
# done_env_ids = torch.tensor([2, 5], device=device) # Example IDs
121+
# manager.reset_trajectories(done_env_ids)
122+
123+
```
124+
125+
## Testing
126+
127+
To verify that the `loco_mujoco` dataset loader is working correctly, you can run the specific test file for it. This is currently the recommended test to run.
128+
129+
First, ensure you have the necessary test dependencies installed:
130+
131+
```bash
132+
uv pip install pytest numpy torch omegaconf zarr mujoco
133+
```
134+
135+
Then, run the following command from the root of the project:
136+
137+
```bash
138+
pytest tests/datasets/test_loco_mujoco_loader.py
139+
```
140+
141+
To visually inspect the loaded trajectories, you can use the `--visualize` flag. This will open a MuJoCo viewer and replay the first trajectory.
142+
143+
```bash
144+
pytest tests/datasets/test_loco_mujoco_loader.py --visualize
145+
```

0 commit comments

Comments
 (0)