Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,42 @@ class TaskConfig(GenerationConfig):
difficulty: str = Field(default="medium", description="easy/medium/hard")
```

**Single entry point:** `python examples/generate.py --num-samples 50`
**Single entry point:** `python examples/generate.py --num-samples 50`

---

## 🎯 Available Tasks

### Path Planning Task (避障路径规划)

A visual reasoning task where a path must be found from start to goal avoiding obstacles.

**Task Description:**
- **Input:** Grid map with black obstacles, red start point, and green goal point
- **Output:** Same map with a blue path drawn from start to goal, avoiding all obstacles

**Example Prompt:**
> "Draw a continuous line from the red start circle to the green goal circle, avoiding all black obstacles."

**Usage:**
```bash
python examples/generate_path_planning.py --num-samples 10
python examples/generate_path_planning.py --num-samples 50 --grid-width 20 --grid-height 15
```

**Configuration Options:**
| Parameter | Default | Description |
|-----------|---------|-------------|
| `grid_width` | 15 | Grid width in cells |
| `grid_height` | 10 | Grid height in cells |
| `cell_size` | 40 | Cell size in pixels |
| `obstacle_density` | 0.25 | Percentage of cells as obstacles (0.0-1.0) |

**Output Structure:**
```
data/questions/path_planning_task/{task_id}/
├── first_frame.png # Map with obstacles, start, and goal
├── final_frame.png # Map with solution path drawn
├── prompt.txt # Task instructions
└── ground_truth.mp4 # Animation of path being drawn
```
115 changes: 115 additions & 0 deletions examples/generate_path_planning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""
╔══════════════════════════════════════════════════════════════════════════════╗
║ PATH PLANNING TASK GENERATION ║
║ ║
║ Generate obstacle avoidance path planning task dataset. ║
║ Task: Find path from start to goal avoiding obstacles. ║
╚══════════════════════════════════════════════════════════════════════════════╝

Usage:
python examples/generate_path_planning.py --num-samples 10
python examples/generate_path_planning.py --num-samples 100 --output data/path --seed 42
python examples/generate_path_planning.py --num-samples 50 --grid-width 20 --grid-height 15
"""

import argparse
from pathlib import Path
import sys

# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from core import OutputWriter
from src import PathPlanningGenerator, PathPlanningConfig


def main():
parser = argparse.ArgumentParser(
description="Generate path planning task dataset",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python examples/generate_path_planning.py --num-samples 10
python examples/generate_path_planning.py --num-samples 100 --output data/path --seed 42
python examples/generate_path_planning.py --num-samples 50 --grid-width 20 --grid-height 15
"""
)
parser.add_argument(
"--num-samples",
type=int,
required=True,
help="Number of task samples to generate"
)
parser.add_argument(
"--output",
type=str,
default="data/questions",
help="Output directory (default: data/questions)"
)
parser.add_argument(
"--seed",
type=int,
default=None,
help="Random seed for reproducibility"
)
parser.add_argument(
"--no-videos",
action="store_true",
help="Disable video generation"
)
parser.add_argument(
"--grid-width",
type=int,
default=15,
help="Grid width in cells (default: 15)"
)
parser.add_argument(
"--grid-height",
type=int,
default=10,
help="Grid height in cells (default: 10)"
)
parser.add_argument(
"--cell-size",
type=int,
default=40,
help="Cell size in pixels (default: 40)"
)
parser.add_argument(
"--obstacle-density",
type=float,
default=0.25,
help="Obstacle density 0.0-1.0 (default: 0.25)"
)

args = parser.parse_args()

print(f"🎲 Generating {args.num_samples} path planning tasks...")
print(f" Grid: {args.grid_width}x{args.grid_height}, Obstacle density: {args.obstacle_density}")

# Configure task
config = PathPlanningConfig(
num_samples=args.num_samples,
random_seed=args.seed,
output_dir=Path(args.output),
generate_videos=not args.no_videos,
grid_width=args.grid_width,
grid_height=args.grid_height,
cell_size=args.cell_size,
obstacle_density=args.obstacle_density,
)

# Generate tasks
generator = PathPlanningGenerator(config)
tasks = generator.generate_dataset()

# Write to disk
writer = OutputWriter(Path(args.output))
writer.write_dataset(tasks)

print(f"✅ Done! Generated {len(tasks)} tasks in {args.output}/{config.domain}_task/")


if __name__ == "__main__":
main()
18 changes: 17 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@
- config.py : Task-specific configuration (TaskConfig)
- generator.py: Task generation logic (TaskGenerator)
- prompts.py : Task prompts/instructions (get_prompt)
- path_planning_task.py: Path planning task (PathPlanningGenerator)
"""

from .config import TaskConfig
from .generator import TaskGenerator
from .prompts import get_prompt
from .path_planning_task import (
PathPlanningConfig,
PathPlanningTask,
PathPlanningGenerator,
get_path_planning_prompt
)

__all__ = ["TaskConfig", "TaskGenerator", "get_prompt"]
__all__ = [
"TaskConfig",
"TaskGenerator",
"get_prompt",
# Path planning task
"PathPlanningConfig",
"PathPlanningTask",
"PathPlanningGenerator",
"get_path_planning_prompt",
]
Loading