# SPDX-License-Identifier: LGPL-3.0-or-later ## @file # @brief Run MAP-Elites and reopen its numeric archive. """Find a low-cost solution in each descriptor cell.""" from qdpy.results import load_grid, read_run_manifest from qdpy.simple import map_elites, run def evaluate(candidate): """Minimise the first coordinate squared and bin on the second.""" x, descriptor = candidate return (x**2,), (descriptor,) def main(): """Save the search and report the best cost and coverage from disk.""" search = map_elites( dimension=2, budget=64, batch_size=8, shape=8, fitness_domain=((0.0, 1.0),), features_domain=((0.0, 1.0),), ) result = run(search, evaluate, seed=42, output_dir="first-map-elites") manifest = read_run_manifest(result.manifest_path) snapshot = manifest["archive"] restored = load_grid( result.manifest_path.with_name(snapshot["file"]), expected_sha256=snapshot["sha256"], ) print(f"Candidate attempts: {result.evaluations}") print(f"Occupied cells: {restored.filled_bins}/{restored.shape[0]}") print(f"Best raw cost: {restored.best.fitness.values[0]:.6f}") if __name__ == "__main__": main()