Run your first searches from PyPI ================================= Install QDpy in a Python 3.11 or newer environment. All four scripts below use the base package. You can save each code block as a Python file in an empty working directory and run it without a repository checkout. .. code-block:: sh python -m pip install qdpy In an existing uv project, run ``uv add qdpy`` and replace ``python`` with ``uv run python`` in the example commands. .. _map-elites: MAP-Elites ---------- Search for a small value of ``x`` across cells of the descriptor ``y``. Each occupied cell keeps one design. The search spends 64 candidate attempts and saves ``first-map-elites/run.json`` and a numeric archive. The script reads the manifest, verifies the archive checksum, and prints coverage and the best raw cost from the saved measurements. Save the code as :download:`map_elites.py <../examples/first_searches/map_elites.py>` and run ``python map_elites.py``. .. literalinclude:: ../examples/first_searches/map_elites.py :language: python .. _mome: MOME ---- Keep trade-offs between ``x**2`` and ``(1 - x)**2`` in each descriptor cell. The search spends 64 candidate attempts and writes its manifest and archive under ``first-mome``. An occupied cell can hold up to four nondominated designs. The sum of cell hypervolumes measures the trade-offs available across cells. Global hypervolume treats designs from all cells as one front. Use the same reference point and objective directions when comparing runs. Save the code as :download:`mome.py <../examples/first_searches/mome.py>` and run ``python mome.py``. .. literalinclude:: ../examples/first_searches/mome.py :language: python .. _noisy-search: Noisy search ------------ Add noise to both the reward and descriptor. The 64-rollout search budget includes reevaluations. After search, measure one elite per occupied source cell eight more times using independent seeds. The audit uses median measurements and can reassign an elite to a different cell. Read the coverage and QD score from ``first-noisy/audited-archive.json``. The printed audit rollout count is separate from the search budget. Save the code as :download:`noisy.py <../examples/first_searches/noisy.py>` and run ``python noisy.py``. .. literalinclude:: ../examples/first_searches/noisy.py :language: python .. _constraint-handling: Constraint handling ------------------- Minimise ``x**2`` subject to ``x + y <= 1`` and fill cells along ``y``. The evaluator reports a named residual, which must be at most zero for the candidate to enter the feasible grid. The search spends 64 candidate attempts and saves that grid under ``first-constrained``. The script recomputes the residual from each saved genome and prints the largest one, which should be nonpositive. Save the code as :download:`constrained.py <../examples/first_searches/constrained.py>` and run ``python constrained.py``. .. literalinclude:: ../examples/first_searches/constrained.py :language: python Inspect a saved archive ----------------------- Use a fresh output directory for each run. The snapshots store genomes, fitness values, descriptors, and cell assignments. The noisy example saves the audited measurements, and the constrained example saves the feasible grid. For plots and result-file details, see :doc:`tutorial_visualization` and :doc:`run_results`.