Run reference QD benchmarks =========================== The same QDpy runner can evaluate flat genomes on shifted Sphere, Lunar Lander, a Kheperax target maze, and seven QDax/Brax tasks. It compares Iso+LineDD MAP-Elites with random search using a fixed evaluation count and a common reporting grid for each task. Each evaluator returns raw fitness and descriptors in the units used by its reference. See :doc:`reference_benchmark_results` for the multi-seed Shoal comparison and the commands for reproducing it. From a checkout or an unpacked source distribution, run Sphere with the base installation. .. code-block:: shell python -m examples.reference_benchmarks --tasks sphere --budget 256 \ --seeds 11 23 47 --output build/reference/sphere.json Sphere and Lunar Lander ----------------------- The Sphere evaluator uses a maximum of 100 at the point with every coordinate equal to 2.048. The two descriptor coordinates sum the first and second parts of the genome. A coordinate outside [-5.12, 5.12] contributes ``5.12 / x`` to its descriptor, and fitness uses the original coordinate. The example uses 100 dimensions by default and keeps the search in the nominal box. ``--dimension`` also supports odd dimensions. `pyribs Sphere reference `_ For Lunar Lander, install Gymnasium's optional Box2D extra. .. code-block:: shell python -m pip install 'gymnasium[box2d]==1.4.0' python -m examples.reference_benchmarks --tasks lunar-lander \ --budget 64 --env-seed 7 --bins 50 --output build/reference/lander.json Use ``uv pip install 'gymnasium[box2d]==1.4.0'`` with an active uv environment. The example uses ``LunarLander-v3`` with discrete actions. Reshape each genome into four rows of eight weights. At each step take the action with the largest dot product with the observation. Sum the episode rewards and record horizontal position and vertical velocity on first leg contact. If neither leg contacts the ground, use the final horizontal position and the lowest vertical velocity observed during the episode. Each policy uses the same reset seed. `pyribs rollout reference `_ Kheperax and QDax/Brax ---------------------- Use a separate Python 3.11 environment for the tested Linux CPU stack. The requirements file pins versions that can run the published Brax v1 environments. It also installs the Kheperax scorer. The main QDpy installation has no simulator or JAX requirement. .. code-block:: shell uv venv --python 3.11 .venv-reference source .venv-reference/bin/activate uv pip install . -r examples/reference_jax_requirements.txt With pip, create and activate a Python 3.11 virtual environment and run ``python -m pip install . -r examples/reference_jax_requirements.txt``. Then run the maze and the seven Brax environments. .. code-block:: shell JAX_PLATFORMS=cpu OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 \ python -m examples.reference_benchmarks --tasks kheperax brax \ --budget 16 --batch-size 4 --output build/reference/jax.json The ``brax`` task group expands to the seven tasks below. Select one by passing its name to ``--tasks``. Use ``--episode-length`` to override the rollout horizon. The defaults are 250 steps for the Kheperax maze and 100 for the QDax factory. Increasing the horizon changes the scoring problem and the cost per evaluation. .. list-table:: :header-rows: 1 * - Task - Descriptor returned by the reference scorer * - ``kheperax`` - Final position in the standard target maze * - ``ant_omni`` - Final horizontal position * - ``ant_uni`` - Fraction of the episode in contact with the ground for each of four feet * - ``antmaze`` - Final horizontal position * - ``anttrap`` - Final horizontal position * - ``halfcheetah_uni`` - Ground contact proportions for two feet * - ``walker2d_uni`` - Ground contact proportions for two feet * - ``pointmaze`` - Final position Kheperax uses the two eight-unit hidden layers in the pyribs example. The Brax tasks use the default QDax policy with two 64-unit hidden layers and a common initial state generated from ``--env-seed``. The factories expose the reference simulator through a batch scoring function. It reconstructs the native network parameters in JAX, applies the upstream task's termination mask, and returns fitness and descriptors without transferring the trajectory to QDpy. The example searches policy weights and uses evolutionary updates. `pyribs Kheperax tutorial `_ · `QDax paper `_ · `Brax v1 task factories `_ Use an evaluator in your own search ----------------------------------- .. code-block:: python from qdpy.benchmarks import PyribsSphereBenchmark task = PyribsSphereBenchmark(dimension=100) genomes = task.sample(4, seed=11) measured = task.evaluate_batch(genomes, seed=7) print(measured.fitness) print(measured.descriptors) print(task.features_domain) The same batch interface is available from ``LunarLanderBenchmark()``, ``kheperax_maze()``, and ``qdax_brax("ant_uni")``. Use Lunar Lander as a context manager to close the environment at the end of the run. For seeded comparisons, keep the task version, seeds, episode length, and batch sizes fixed. JAX compilation runs on the first call for each batch shape, including a short final batch. Read the results ---------------- The runner records evaluations, occupied cells, coverage, raw fitness, and both raw and offset QD scores. The offset is added once per occupied cell. It is 600 for Lunar Lander and uses the QDax task's per-step offset times episode length for Brax. Genome evaluations outside the declared descriptor bounds still consume one budget slot and appear in the report. The example uses small grids and a common search setup across tasks. Comparisons with published results also require the same optimizer, network, archive geometry, and training protocol. ``scored_episode_steps`` counts valid transitions through the first termination or truncation. ``simulator_steps`` counts executed transitions, including the masked tail of a fixed-length Kheperax or Brax scan. On Sphere both are zero. Read these counts alongside candidate evaluations when comparing execution costs. Smoke results ------------- On Linux with Python 3.11, both methods completed 16 evaluations per task at batch size four, with seed 11 and environment seed 7. All 20 trials populated their reporting archives. The Kheperax runs executed 4,000 simulator steps per method. Each Brax run executed 1,600 steps. The random Walker2D run used 1,481 of those steps for scoring because some policies terminated early. The Sphere trials used no simulator steps. These small runs exercise task setup and budget accounting. Run the same smoke test with all the optional dependencies installed. .. code-block:: shell JAX_PLATFORMS=cpu OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 \ python -m examples.reference_benchmarks \ --tasks sphere lunar-lander kheperax brax --budget 16 --batch-size 4 \ --output build/reference/smoke.json