# SPDX-License-Identifier: LGPL-3.0-or-later ## @file # @brief Save and reopen the local Pareto fronts found by MOME. """Find trade-offs between two costs in each descriptor cell.""" from qdpy.algorithms import MOME from qdpy.containers import ParetoGrid from qdpy.results import load_grid, read_run_manifest from qdpy.simple import run def evaluate(candidate): """Return two costs that favour opposite values of the first coordinate.""" x, descriptor = candidate return (x**2, (1.0 - x)**2), (descriptor,) def main(): """Read the saved fronts and measure their hypervolume.""" unit = (0.0, 1.0) archive = ParetoGrid( shape=8, max_items_per_bin=4, fitness_domain=(unit, unit), features_domain=(unit,), truncation="crowding", ) search = MOME(archive, budget=64, dimension=2, batch_size=8, optimisation_task="minimisation") result = run(search, evaluate, seed=42, output_dir="first-mome") manifest = read_run_manifest(result.manifest_path) snapshot = manifest["archive"] restored = load_grid( result.manifest_path.with_name(snapshot["file"]), expected_sha256=snapshot["sha256"], ) reference = (1.0, 1.0) print(f"Candidate attempts: {result.evaluations}") print(f"Occupied cells: {restored.filled_bins}/{restored.shape[0]}") print(f"Retained trade-offs: {len(restored)}") print(f"Sum of cell hypervolumes: {restored.qd_hypervolume(reference):.6f}") print(f"Global hypervolume: {restored.global_hypervolume(reference):.6f}") if __name__ == "__main__": main()