File size: 5,948 Bytes
81c7a5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Task Libraries

A **task library** is a collection of [task definitions](task.md) organized into subfolders under a common root directory. RoboLab ships a built-in library in [`robolab/tasks/`](../robolab/tasks/), but you can create and maintain your own task library in a separate repository.

## Building Your Own Task Library

To build a task library, write `Task` dataclasses with USD scenes, language instructions, and termination criteria. See [Creating Tasks](task.md) for the full authoring guide. Once you have tasks, see [Environment Registration](environment_registration.md) for how to register and run them.

The rest of this page covers how to organize your tasks into a library and use RoboLab's utility scripts to generate metadata and statistics.

## Directory Structure

A task library follows this layout:

```
my_task_library/
  scenes/
    scene_a.usda
    scene_b.usda
  tasks/
    apple_in_bowl.py
    banana_on_plate.py
    block_stacking.py
  _metadata/                  # Auto-generated by the metadata scripts
    task_metadata.json
    task_table.csv
```

- **`scenes/`** — USD scene files used by your tasks (see [Scenes](scene.md))
- **`tasks/`** — Task definition Python files, one per task
- **`_metadata/`** — Auto-generated metadata (JSON, CSV, markdown table)

Each task file defines a `Task` dataclass that binds a scene to language instructions and termination criteria. See [Creating Tasks](task.md) for the full authoring guide.

## Using Your Task Library

Once you have task files, register them as runnable Gymnasium environments so they can be instantiated by your evaluation script. Your library does not need to live inside the RoboLab repo. See [Environment Registration](environment_registration.md) for the full workflow.

## Generating and Updating Task Metadata

RoboLab provides utility scripts for generating metadata, README tables, and statistics for your task library. These live in [`robolab/tasks/_utils/`](../robolab/tasks/_utils/README.md) and work with **any** task directory — you point them at your own library the same way RoboLab uses them internally.

| Script | Purpose |
|--------|---------|
| `generate_task_metadata.py` | Scan task files and produce JSON, CSV, and a README table |
| `compute_task_statistics.py` | Analyze metadata: attributes, difficulty, objects, subtasks, episodes, scenes |
| `load_task_info.py` | Importable helpers for extracting metadata from task classes programmatically |

### Generate metadata (JSON, CSV, and README table)

This scans all task files, extracts metadata (instructions, attributes, scenes, subtasks, difficulty scores), and writes structured output files:

```bash
python robolab/tasks/_utils/generate_task_metadata.py \
    --tasks-folder /path/to/my_task_library/tasks \
    --output-folder /path/to/my_task_library/tasks/_metadata
```

Output files:
- `_metadata/task_metadata.json` — Complete metadata for all tasks
- `_metadata/task_table.csv` — Tabular summary
- `tasks/README.md` — Markdown table (auto-generated at the root of the tasks folder)

### View task statistics

Once metadata has been generated, you can view statistics without re-scanning:

```bash
# Summary of task attributes and difficulty distribution
python robolab/tasks/_utils/compute_task_statistics.py \
    --metadata-file /path/to/my_task_library/tasks/_metadata/task_metadata.json

# Full report (attributes, objects, subtasks, episodes, scenes)
python robolab/tasks/_utils/compute_task_statistics.py \
    --metadata-file /path/to/my_task_library/tasks/_metadata/task_metadata.json \
    --verbose

# Individual analysis sections
python robolab/tasks/_utils/compute_task_statistics.py --objects     # Object frequency
python robolab/tasks/_utils/compute_task_statistics.py --subtasks   # Subtask complexity
python robolab/tasks/_utils/compute_task_statistics.py --episodes   # Episode lengths
python robolab/tasks/_utils/compute_task_statistics.py --difficulty  # Difficulty scoring
python robolab/tasks/_utils/compute_task_statistics.py --by-scene   # Tasks grouped by scene
```

### Save a report to file

```bash
python robolab/tasks/_utils/compute_task_statistics.py --verbose --save
```

This writes `_metadata/task_report.txt` alongside the JSON and CSV files.

### Validate tasks

To check that all tasks have valid contact lists, terminations, and scene references:

```bash
# Validate the built-in benchmark tasks
uv run pytest tests/test_tasks_valid.py -v
```

To validate a custom task library outside `robolab/tasks/benchmark/`, point `find_task_files` at it from a script — see `tests/test_tasks_valid.py` for the calling pattern.

## Keeping Metadata Up to Date

Re-run `generate_task_metadata.py` whenever you add, remove, or modify tasks. This regenerates all output files (JSON, CSV, README) so they stay in sync with your task definitions.

A typical workflow when updating your task library:

1. **Add or edit task files** — see [Creating Tasks](task.md) for the authoring guide
2. **Regenerate metadata** — `python robolab/tasks/_utils/generate_task_metadata.py --tasks-folder <your_tasks_dir>`
3. **Review statistics** — `python robolab/tasks/_utils/compute_task_statistics.py --metadata-file <your_metadata_dir>/task_metadata.json --verbose`
4. **Register and test** — follow [Environment Registration](environment_registration.md) to register your updated tasks and run them

## See Also

- [Creating Tasks](task.md) — How to write task definitions (scenes, terminations, instructions, subtasks)
- [Benchmark](benchmark.md) — The built-in benchmark task library and its difficulty scoring
- [Environment Registration](environment_registration.md) — Registering tasks as runnable Gymnasium environments
- [Evaluating a New Policy](policy.md) — Running evaluation against your tasks
- [`robolab/tasks/_utils/README.md`](../robolab/tasks/_utils/README.md) — Quick reference for all utility scripts