Multi-Task Multi-Behavior MAP-Elites¶
Keep a separate repertoire for each task while sharing parents across tasks. This example varies the minimum of a quadratic cost and shifts the descriptor for each of four tasks.
Run from the repository root with the base package.
python examples/multitask_map_elites.py
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Transfer genomes among four tasks while keeping their measurements separate.
"""Search four related quadratic tasks with a separate repertoire per task."""
from qdpy.algorithms import mtmb_search
from qdpy.containers import Grid
TASKS = (0.20, 0.35, 0.50, 0.65)
def make_archives():
"""Build a reporting grid with eight cells for each task."""
return {
task: Grid(shape=8, fitness_domain=((0, 1),), features_domain=((0, 1),))
for task in TASKS
}
def evaluate(task, genome):
"""Return a task-specific cost and a shifted descriptor."""
x, y = genome
cost = (x - task) ** 2 + 0.02 * (y - 0.5) ** 2
return (cost,), ((y + task) % 1.0,)
if __name__ == "__main__":
result = mtmb_search(make_archives(), evaluate, dimension=2, budget=64, seed=42)
print(f"Attempts: {sum(result.attempts_by_task.values())}")
for task, archive in result.archives.items():
print(f"Task {task:.2f}: {result.attempts_by_task[task]} attempts, "
f"{archive.filled_bins}/8 cells, QD score {archive.qd_score():.3f}")
Give qdpy.algorithms.mtmb_search() a mapping from task IDs to
distinct empty grids. Use the same genome length and decision bounds
for every task. Each grid has its own descriptor geometry and
objective direction. By default, the search minimises the raw objective.
The evaluator receives one task ID and one immutable genome. Return
((fitness,), descriptors) for that task. After warm-up the search
draws two populated tasks, picks a parent from each, and applies
Iso+LineDD. An offspring is evaluated on its target task even when
both parents came from elsewhere. Only that measurement can enter
the target archive.
The example spends 64 attempts across the four tasks. Read
attempts_by_task to see the realised allocation. Failed calls spend
an attempt and are recorded in failures_by_task. The seed-42 run
filled five, seven, five, and six cells in task order. To compare task
transfer with independent search, set share_parents=False. Keep the
same mapping order and seed to replay the target-task schedule.
The task-transfer procedure follows Anne and Mouret (2023). See Fixed-task and dynamic QD pilots for a comparison at matched per-task budgets.