Skip to main content

A Python Library for Quality-Diversity and NeuroEvolution

Project description

qdax_logo

QDax: Accelerated Quality-Diversity

Documentation Status pytest License: MIT codecov

QDax is a tool to accelerate Quality-Diversity (QD) and neuroevolution algorithms through hardware accelerators and massive parallelization. QD algorithms usually take days/weeks to run on large CPU clusters. With QDax, QD algorithms can now be run in minutes! ⏩ ⏩ 🕛

QDax has been developed as a research framework: it is flexible and easy to extend and build on and can be used for any problem setting. Get started with simple example and run a QD algorithm in minutes here! Open All Collab

Installation

QDax is available on PyPI and can be installed with:

pip install qdax

To install QDax with CUDA 12 support, use:

pip install qdax[cuda12]

Alternatively, the latest commit of QDax can be installed directly from source with:

pip install git+https://github.com/adaptive-intelligent-robotics/QDax.git@main

Installing QDax via pip installs a CPU-only version of JAX by default. To use QDax with NVidia GPUs, you must first install CUDA, CuDNN, and JAX with GPU support.

However, we also provide and recommend using either Docker or conda environments to use the repository which by default provides GPU support. Detailed steps to do so are available in the documentation.

Basic API Usage

For a full and interactive example to see how QDax works, we recommend starting with the tutorial-style Colab notebook. It is an example of the MAP-Elites algorithm used to evolve a population of controllers on a chosen Brax environment (Walker by default).

However, a summary of the main API usage is provided below:

import jax
import functools
from qdax.core.map_elites import MAPElites
from qdax.core.containers.mapelites_repertoire import compute_euclidean_centroids
from qdax.tasks.arm import arm_scoring_function
from qdax.core.emitters.mutation_operators import isoline_variation
from qdax.core.emitters.standard_emitters import MixingEmitter
from qdax.utils.metrics import default_qd_metrics

seed = 42
num_param_dimensions = 100  # num DoF arm
init_batch_size = 100
batch_size = 1024
num_iterations = 50
grid_shape = (100, 100)
min_param = 0.0
max_param = 1.0
min_descriptor = 0.0
max_descriptor = 1.0

# Init a random key
key = jax.random.key(seed)

# Init population of controllers
key, subkey = jax.random.split(key)
init_variables = jax.random.uniform(
    subkey,
    shape=(init_batch_size, num_param_dimensions),
    minval=min_param,
    maxval=max_param,
)

# Define emitter
variation_fn = functools.partial(
    isoline_variation,
    iso_sigma=0.05,
    line_sigma=0.1,
    minval=min_param,
    maxval=max_param,
)
mixing_emitter = MixingEmitter(
    mutation_fn=lambda x, y: (x, y),
    variation_fn=variation_fn,
    variation_percentage=1.0,
    batch_size=batch_size,
)

# Define a metrics function
metrics_fn = functools.partial(
    default_qd_metrics,
    qd_offset=0.0,
)

# Instantiate MAP-Elites
map_elites = MAPElites(
    scoring_function=arm_scoring_function,
    emitter=mixing_emitter,
    metrics_function=metrics_fn,
)

# Compute the centroids
centroids = compute_euclidean_centroids(
    grid_shape=grid_shape,
    minval=min_descriptor,
    maxval=max_descriptor,
)

# Initializes repertoire and emitter state
key, subkey = jax.random.split(key)
repertoire, emitter_state, metrics = map_elites.init(init_variables, centroids, subkey)

# Jit the update function for faster iterations
update_fn = jax.jit(map_elites.update)

# Run MAP-Elites loop
for i in range(num_iterations):
    key, subkey = jax.random.split(key)
    (repertoire, emitter_state, metrics,) = update_fn(
        repertoire,
        emitter_state,
        subkey,
    )

# Get contents of repertoire
repertoire.genotypes, repertoire.fitnesses, repertoire.descriptors

QDax core algorithms

QDax currently supports the following algorithms:

Algorithm Example
MAP-Elites Open All Collab
AURORA Open All Collab
CVT MAP-Elites Open All Collab
Policy Gradient Assisted MAP-Elites (PGA-ME) Open All Collab
DCRL-ME Open All Collab
QDPG Open All Collab
CMA-ME Open All Collab
OMG-MEGA Open All Collab
CMA-MEGA Open All Collab
Multi-Objective MAP-Elites (MOME) Open All Collab
MAP-Elites Evolution Strategies (MEES) Open All Collab
MAP-Elites PBT (ME-PBT) Open All Collab
MAP-Elites Low-Spread (ME-LS) Open All Collab

QDax baseline algorithms

The QDax library also provides implementations for some useful baseline algorithms:

Algorithm Example
DIAYN Open All Collab
DADS Open All Collab
SMERL Open All Collab
NSGA2 Open All Collab
SPEA2 Open All Collab
Population Based Training (PBT) Open All Collab

QDax Tasks

The QDax library also provides numerous implementations for several standard Quality-Diversity tasks.

All those implementations, and their descriptions are provided in the tasks directory.

Contributing

Issues and contributions are welcome. Please refer to the contribution guide in the documentation for more details.

Related Projects

Citing QDax

If you use QDax in your research and want to cite it in your work, please use:

@article{chalumeau2024qdax,
  title={Qdax: A library for quality-diversity and population-based algorithms with hardware acceleration},
  author={Chalumeau, Felix and Lim, Bryan and Boige, Raphael and Allard, Maxime and Grillotti, Luca and Flageat, Manon and Mac{\'e}, Valentin and Richard, Guillaume and Flajolet, Arthur and Pierrot, Thomas and others},
  journal={Journal of Machine Learning Research},
  volume={25},
  number={108},
  pages={1--16},
  year={2024}
}

Contributors

QDax was developed and is maintained by the Adaptive & Intelligent Robotics Lab (AIRL) and InstaDeep.

AIRL_Logo InstaDeep_Logo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qdax-0.5.0.tar.gz (186.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qdax-0.5.0-py3-none-any.whl (284.7 kB view details)

Uploaded Python 3

File details

Details for the file qdax-0.5.0.tar.gz.

File metadata

  • Download URL: qdax-0.5.0.tar.gz
  • Upload date:
  • Size: 186.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for qdax-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b03aee05a08a36298aa8e404c99dc046fbfd4ca02073059ab709785d5b66dc92
MD5 896635ed4d3118a92cdc209a75a2aaf6
BLAKE2b-256 83b8a7c69f9d45c215ef65084dc4bc711cfcbe5a9637425e63260940e0775ba6

See more details on using hashes here.

File details

Details for the file qdax-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: qdax-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 284.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for qdax-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52fc4a6b4b87f5f66e73bd02a82aab94b17ed0c0e9b84c57110b07d7741a7fa9
MD5 8abd16098d5fb848f9685b2ca5c2d650
BLAKE2b-256 be96dcdeaa553e3f6a29b1ea7be4242a918f920cf4cdf41e8e6eb1ce5cbbe82a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page