This package provides utilities for generation, filtering, solving, visualizing, and processing of mazes for training or evaluating ML systems. Primarily built for the maze-transformer interpretability project. You can find our paper on it here: http://arxiv.org/abs/2309.10498
This package includes a variety of maze generation algorithms, including randomized depth first search, Wilson's algorithm for uniform spanning trees, and percolation. Datasets can be filtered to select mazes of a certain length or complexity, remove duplicates, and satisfy custom properties. A variety of output formats for visualization and training ML models are provided.
You can view and search through a wide variety of example mazes here: understanding-search.github.io/maze-dataset/examples/maze_examples
If you use this code in your research, please cite our paper:
@misc{maze-dataset,
title={A Configurable Library for Generating and Manipulating Maze Datasets},
author={Michael Igorevich Ivanitskiy and Rusheb Shah and Alex F. Spies and Tilman Räuker and Dan Valentine and Can Rager and Lucia Quirke and Chris Mathwin and Guillaume Corlouer and Cecilia Diniz Behn and Samy Wu Fung},
year={2023},
eprint={2309.10498},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={http://arxiv.org/abs/2309.10498}
}
This package is available on PyPI, and can be installed via
pip install maze-dataset
Please note that due to an issue with the
rust-fst
package, some tokenization features are not available on macOS. Please see #57
The full hosted documentation is available at https://understanding-search.github.io/maze-dataset/.
Additionally, our notebooks serve as a good starting point for understanding the package.
To create a MazeDataset
, you first create a MazeDatasetConfig
:
from maze_dataset import MazeDataset, MazeDatasetConfig
from maze_dataset.generation import LatticeMazeGenerators
cfg: MazeDatasetConfig = MazeDatasetConfig(
name="test", # name is only for you to keep track of things
grid_n=5, # number of rows/columns in the lattice
n_mazes=4, # number of mazes to generate
maze_ctor=LatticeMazeGenerators.gen_dfs, # algorithm to generate the maze
maze_ctor_kwargs=dict(do_forks=False), # additional parameters to pass to the maze generation algorithm
)
and then pass this config to the MazeDataset.from_config
method:
dataset: MazeDataset = MazeDataset.from_config(cfg)
This method can search for whether a dataset with matching config hash already exists on your filesystem in the expected location, and load it if so. It can also generate a dataset on the fly if needed.
The elements of the dataset are SolvedMaze
objects:
>>> m = dataset[0]
>>> type(m)
maze_dataset.maze.lattice_maze.SolvedMaze
Which can be converted to a variety of formats:
# visual representation as ascii art
print(m.as_ascii())
# RGB image, optionally without solution or endpoints, suitable for CNNs
import matplotlib.pyplot as plt
plt.imshow(m.as_pixels())
# text format for autoreregressive transformers
from maze_dataset.tokenization import MazeTokenizerModular, TokenizationMode, PromptSequencers
m.as_tokens(maze_tokenizer=MazeTokenizerModular(
prompt_sequencer=PromptSequencers.AOTP(), # many options here
))
# advanced visualization with many features
from maze_dataset.plotting import MazePlot
MazePlot(m).plot()
We use this makefile template with slight modifications for our development workflow. This project uses uv for dependency and virtual environment management.
- clone with
git clone https://github.com/understanding-search/maze-dataset
- if you don't already have uv, install it. We only guarantee compatibility with
uv
newer than0.8.0
make dep
to install all dependenciesmake help
will print all available commandsmake test
will run basic tests to ensure the package is working- run just the unit tests with
make test-unit
- see all tests with explanations using
make help
ormake help | grep test
- run just the unit tests with
make format
will run ruff to format and check the code
Note: due to compatibility issues between the
rust_fst
package and Darwin/macOS systems, not all tests will pass on these systems. However,make test-unit
andmake test-notebooks-muutils
should still pass. Please see #57 for updates on resolving this problem.
We welcome contributions! We use GitHub issues to track bugs and feature requests. If you have a bug fix or a new feature to contribute, please open a pull request. We are also happy to provide usage support and answer questions about the package via issues!
While we expect that the core interface of the package is stable, we are very open to adding new features. We're particularly excited about adding new maze generation algorithms and new output formats. Please feel free to both suggest new formats or algorithms, and to implement them and open PRs! For more info on how to add a new maze generation algorithm, see the documentation on generators.
We are also aware that like any piece of software, maze-dataset
is not without bugs. If something isn't working as expected, please open an issue and we will do our best to fix it. It helps us keep things tidy if you first search existing bug reports to see if your issue has already been reported.