Home

Awesome

Kheperax

The Kheperax task is a re-implementation of the fastsim simulator from Mouret and Doncieux (2012). Kheperax is fully written using JAX, to leverage hardware accelerators and massive parallelization.

Features

<p align="center"> <img src="img/gif/mapelites_progress_standard.gif" width="160" height="160" /> <img src="img/gif/target_policy_standard.gif" width="160" height="160" /> <img src="img/gif/unstructured_progress_snake.gif" width="160" height="160"/> <img src="img/gif/target_policy_snake.gif" width="160" height="160"/> </p>

Installation

Kheperax is available on PyPI and can be installed with:

pip install kheperax

Alternatively, to install Kheperax with CUDA 12 support, you can run:

pip install kheperax[cuda12]

Task Properties

Environment

Each episode is run for a fixed amount of time-steps (by default equal to 250). The agent corresponds to a Khepera-like robot (circular robots with 2 wheels) that moves in a planar 2-dimensional maze. This robot has (by default):

# by default:
[laser 1, laser 2, laser 3, bumper left, bumper right]

The bumpers return 1 if there's a contact with a wall and -1 otherwise.

The actions to pass to the environment should be between -1 and 1. They are then scaled depending on a scale defined in the environment configuration.

Run examples

Install Dependencies

Before running examples, we recommend creating a virtual environment and installing the required dependencies:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

If you want to run the examples with CUDA 12 support, you need install jax with the cuda12 extra:

pip install jax[cuda12]==<version-from-requirements.txt>

Launch MAP-Elites Example

To run the MAP-Elites example on the standard Kheperax task, you can use the following colab notebook:

Open In Colab

Other tasks can be run with the following scripts.

python -m examples.target.target_me_training  # Target task with MAP-Elites

python -m examples.final_distance.final_distance_me_training  # Final Distance task with MAP-Elites

Additional details on those tasks can be found in the Tasks and Maze Types section.

Rendering images and gifs

To render images, you can run the following script:

python -m examples.rendering.maps_rendering

To render gifs, you can run the following script:

python -m examples.rendering.gif

Tasks and Maze Types

Kheperax supports various tasks and maze types. Here's an overview of the available options and their corresponding files:

Basic Kheperax Task

Key Features:

Configuration

A KheperaxConfig object contains all the properties of a KheperaxTask:


from kheperax.tasks.config import KheperaxConfig

config = KheperaxConfig.get_default()

Key configuration options with their default values:

Usage example:


from kheperax.tasks.config import KheperaxConfig
from kheperax.simu.robot import Robot
from kheperax.simu.maze import Maze

config = KheperaxConfig.get_default()

config.episode_length = 1000
config.action_scale = 0.03
config.resolution = (800, 800)

new_robot = Robot.create_default_robot().replace(radius=0.05)
config.robot = new_robot

new_maze = Maze.create(segments_list=[...])  # Define maze segments
config.maze = new_maze

Target Kheperax Task

Key Features:

Configuration

TargetKheperaxConfig contains the same parameters as KheperaxConfig, plus additional target-related parameters:

Usage example:

from kheperax.tasks.target import TargetKheperaxConfig, TargetKheperaxTask

# Create a default target configuration
target_config = TargetKheperaxConfig.get_default()

# Customize the configuration if needed
target_config.target_pos = (0.2, 0.8)  # Change target position
target_config.target_radius = 0.06    # Change target radius

# Create the target task
target_task = TargetKheperaxTask(target_config)

# Use the task in your experiment
# ... (reset, step, etc.)

Final Distance Kheperax Task

Key Features:

TargetKheperaxConfig is still used to manage the configuration for this kind of task (see above description)

Maze Maps

To use a specific maze map:


from kheperax.tasks.config import KheperaxConfig
from kheperax.tasks.target import TargetKheperaxConfig

# Get the default configuration for the desired maze map
maze_map = KheperaxConfig.get_default_for_map("standard")  # or "pointmaze", "snake"

# For target-based tasks
target_maze_map = TargetKheperaxConfig.get_default_for_map("standard")  # or "pointmaze", "snake"
StandardPointMazeSnake
No target<img src="img/maps/no_target/no_quad/standard.png" width="150"><img src="img/maps/no_target/no_quad/pointmaze.png" width="150"><img src="img/maps/no_target/no_quad/snake.png" width="150">
Target<img src="img/maps/target/no_quad/standard.png" width="150"><img src="img/maps/target/no_quad/pointmaze.png" width="150"><img src="img/maps/target/no_quad/snake.png" width="150">

Quad Mazes

To create a quad maze configuration:


from kheperax.tasks.config import KheperaxConfig
from kheperax.tasks.target import TargetKheperaxConfig
from kheperax.tasks.quad import make_quad_config

# Get the default configuration for the desired maze map
maze_map = KheperaxConfig.get_default_for_map("standard")  # or "pointmaze", "snake"
target_maze_map = TargetKheperaxConfig.get_default_for_map("standard")  # or "pointmaze", "snake"

# Create a quad maze configuration
quad_config = make_quad_config(maze_map)  # or target_maze_map for target-based tasks
Quad StandardQuad PointMazeQuad Snake
No target<img src="img/maps/no_target/quad/standard.png" width="150"><img src="img/maps/no_target/quad/pointmaze.png" width="150"><img src="img/maps/no_target/quad/snake.png" width="150">
Target<img src="img/maps/target/quad/standard.png" width="150"><img src="img/maps/target/quad/pointmaze.png" width="150"><img src="img/maps/target/quad/snake.png" width="150">

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use Kheperax in your research, please cite the following paper:

@inproceedings{grillotti2023kheperax,
  title={Kheperax: a lightweight jax-based robot control environment for benchmarking quality-diversity algorithms},
  author={Grillotti, Luca and Cully, Antoine},
  booktitle={Proceedings of the Companion Conference on Genetic and Evolutionary Computation},
  pages={2163--2165},
  year={2023}
}

Acknowledgements