Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1455e39
Sprite rendering implementation
JackHopkins Jul 14, 2025
f56f1f3
Migrated sprite rendering into the render tool
JackHopkins Jul 14, 2025
b206695
Finished sprite rendering tool implementation
JackHopkins Jul 14, 2025
a9f0dc8
Added timer for more efficient loading of the game state in {
JackHopkins Jul 20, 2025
027b686
More efficient rendering through BASE64 encoding of tiles with run-le…
JackHopkins Jul 20, 2025
e8a03a7
Fixed issue where tests wouldn't run if the player client is connected
JackHopkins Jul 20, 2025
fd201f1
Rendering cliffs
JackHopkins Jul 20, 2025
094a261
Added rendering for entities, rather than dicts
JackHopkins Jul 22, 2025
9d765fb
Support rendering entities from get_entities() as well as blueprints
JackHopkins Jul 22, 2025
c5b3437
Items on belts now rendered
JackHopkins Jul 23, 2025
6097ac5
Icon variants on belts where available
JackHopkins Jul 23, 2025
5b555c6
Alert overlays:
JackHopkins Jul 23, 2025
b810d16
Removed VQA harness
JackHopkins Jul 23, 2025
a5a98b4
Fixed merge conflicts
JackHopkins Jul 23, 2025
a4a9688
Removed large data.json file
JackHopkins Jul 23, 2025
5077426
Added dependency
JackHopkins Jul 23, 2025
ad33d3f
Position normalization in the renderer
JackHopkins Jul 27, 2025
3139b23
Merge branch 'sprites/active_inactive' of https://github.com/JackHopk…
JackHopkins Jul 27, 2025
c365ce6
Added other tasks
JackHopkins Jul 28, 2025
a58cf0c
Minor modifications
JackHopkins Jul 31, 2025
5a5c788
Better question generation
JackHopkins Jul 31, 2025
a438d87
Added direction questions
JackHopkins Jul 31, 2025
803e974
Fixed issues and added blueprint augmentation
JackHopkins Aug 2, 2025
0adf735
Implemented generate terrain questions
JackHopkins Aug 2, 2025
65724dc
Added deepwater tiles
JackHopkins Aug 2, 2025
4255007
More tasks
JackHopkins Aug 3, 2025
4aab0cc
Now rendering centered on the character
JackHopkins Aug 3, 2025
4fd7c3d
Fixed the grid
JackHopkins Aug 3, 2025
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
3 changes: 3 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ TOGETHER_API_KEY=XXX
DEEPSEEK_API_KEY=XXX
OPEN_ROUTER_API_KEY=XXX

# Used for downloading image files for rendering
HF_TOKEN=XXX

# Database Configuration
# Options: "sqlite" (default) or "postgres"
FLE_DB_TYPE="sqlite"
Expand Down
23 changes: 21 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ trajectory_logs/
*.mp4
*.jsonl
*.db
/log/

#fle
.fle/
.fle/

# Jack's stuff.
/docker-compose.yml
/data/plans/factorio_guides/
/docs/assets/videos/
/fle/agents/data/blueprints_to_policies/blueprints/
/fle/eval/open/plots/technology_icons/
/data/icons/
/eval/open/plots/

/data/vqa/logs/
/data/vqa/tasks/spatial_reasoning/.compose.yaml
/data/vqa/tasks/spatial_reasoning/logs/
/data/vqa/tasks/logs/
/data/vqa/images/
/data/vqa/dataset/images/
/data/vqa/tasks/basic/logs/
/data/vqa/tasks/contrastive_alignment/logs/
/data/vqa/tasks/contrastive_alignment/logs/
113 changes: 113 additions & 0 deletions data/vqa/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is the Visual Question Answering (VQA) module for the Factorio Learning Environment (FLE). The goal is to train visual encoders for Factorio using text representations as ground truth.

## Key Commands

### Running Tasks
```bash
# Run all VQA tasks
python tasks.py

# Run specific task type
python tasks/basic/task.py
python tasks/spatial_reasoning/task.py
python tasks/denoising/task.py
# etc.
```

### Installation
```bash
pip install -r requirements.txt
```

## Architecture

### Core Components

1. **Blueprint Loading**: Blueprints are loaded from `.fle/blueprints/` via `utils.find_blueprints_dir()`
2. **Rendering**: Use `instance.namespace._render(blueprint=blueprint)` to render blueprints to images
3. **Dataset Generation**: `dataset.py` creates `MemoryDataset` from blueprints
4. **Task System**: Each task type has:
- `task.py`: Task definitions using `@task` decorator
- `solver.py`: Question generation logic using `@solver` decorator
- `templates/`: Jinja2 templates for prompts
5. **Common Solvers**: `common_solvers.py` contains:
- `validate_qa_answerability()`: Validates if questions are answerable and unambiguous
- `convert_directions_to_compass()`: Converts numeric directions to compass directions
6. **Direction Utilities**: `direction_utils.py` provides Direction enum and conversion utilities

### Task Types

1. **Basic** (`tasks/basic/`)
- Entity name prediction from position
- Position prediction from entity name
- Entity counting

2. **Spatial Reasoning** (`tasks/spatial_reasoning/`)
- Relative entity positions
- Distance calculations
- Spatial context questions

3. **State Prediction** - **NOT IMPLEMENTED**
- Should predict entity states from live factories
- Needs access to live game state, not just blueprints

4. **Denoising** (`tasks/denoising/`)
- Remove/modify/replace entities
- Predict original entity

5. **Action Prediction** (`tasks/action_prediction/`)
- Predict next construction action
- Construction order questions

6. **Productivity Planning** (`tasks/productivity_planning/`)
- Throughput predictions
- Bottleneck analysis
- Optimization suggestions

7. **Contrastive Alignment** (`tasks/contrastive_alignment/`)
- Blueprint title/purpose matching
- Multiple choice format

### Data Flow

1. Blueprint JSON → `raw_blueprint_dataset()` → Task
2. Task uses solver to generate questions
3. Solver renders blueprint: `instance.namespace._render(blueprint=blueprint)`
4. Image saved to `dataset/images/{blueprint_name}/{variant_hash}.jpg`
5. **Validation Pipeline**:
- `convert_directions_to_compass()`: Converts numeric directions (0,2,4,6) to compass (north/east/south/west)
- `validate_qa_answerability()`: Validates questions are answerable and unambiguous, regenerates if needed
6. QA pairs collected by `VQAPairsHook`
7. Results saved as JSONL in `dataset/`

### Key Integration Points

- **FLE Instance**: Create with `create_factorio_instance()` from `fle.agents.data.screenshots_from_run`
- **Rendering**: Returns `RenderedImage` object, save with `.save(path)`
- **Image IDs**: Use folder structure `/dataset/images/{blueprint_name}/{variant_hash}` with clean blueprint names and variant-specific hashes
- **Hooks**: `VQAPairsHook` automatically serializes QA pairs after evaluation

### Adding New Task Types

1. Create directory: `tasks/new_task_type/`
2. Create `task.py` with `@task` decorated functions
3. Create `solver.py` with `@solver` decorated question generators
4. Add templates in `templates/` if needed
5. Update `tasks/__init__.py` to export new tasks
6. Add normalization method in `hook.py` for new QA format

### Important Notes

- **State Prediction tasks** need live game state, not implemented yet
- **Direction Handling**: All tasks now convert numeric directions to compass directions automatically
- **Question Validation**: All generated questions are validated for answerability and clarity
- **Images** are saved with organized folder structure `{blueprint_name}/{variant_hash}.jpg` for better organization
- **QA Pairs** are normalized to consistent format in `hook.py`
- **Framework**: Use `inspect_ai` framework for task/solver definitions
- **Validation Steps**: Always include `convert_directions_to_compass()` and `validate_qa_answerability()` in solver pipelines
Loading