Counterexamples, design symmetries, and learned policy variation

The example checks schedules under single-job delays, searches networks with interchangeable internal nodes, and compares three ways to mutate a continuous feedback policy. See Counterexamples, design symmetries, and learned policy variation for the workloads and per-seed results.

python -m pip install .
python -I examples/verified_symmetry_manifold.py --task base
python -m pip install ".[rl]"
python -I examples/verified_symmetry_manifold.py --task control

Counterexample-guided MAP-Elites

Separate nominal fitness and descriptors from the requirement a design must meet under every scenario. For instance, choose a buffer size and processing capacity, then check whether the station keeps up under each load spike in a declared set.

from qdpy.algorithms import CounterexampleMAPElites
from qdpy.containers import Grid

archive = Grid(
    shape=(5,), features_domain=((0, 5),),
    fitness_domain=((0., 1.),), fitness_weights=(1.,),
)

def measure(genome):
    capacity, buffer = genome
    return (1. / (capacity + buffer),), (buffer,)

def verify(genome, load):
    capacity, buffer = genome
    return load <= capacity + buffer

def propose(rng):
    return int(rng.integers(1, 6)), int(rng.integers(5))

def mutate(parent, rng):
    capacity, buffer = parent
    if rng.random() < .5:
        return int(rng.integers(1, 6)), buffer
    return capacity, int(rng.integers(5))

search = CounterexampleMAPElites(
    archive, (2, 3, 4, 5, 6), initial_scenarios=(2,),
    propose=propose, mutate=mutate, measure=measure, verify=verify,
    seed=4,
)
stats = search.run(proposals=80, checks=160)
if search.pending_genome is not None:
    stats = search.run(proposals=0, checks=5)
print(search.counterexamples, stats.checks, len(archive))

Start with a few known cases. When a candidate fails on a new case, that case joins the screening set and runs before unseen cases on future candidates. The scalar fitness and descriptors from measure determine whether a candidate could improve the archive. Such candidates enter the archive after every scenario passes.

The two budgets limit proposals and calls to verify separately. A candidate that runs out of checks stays pending. Returning None from verify also pauses that candidate. The next call retries the pending case and can spend its entire budget on that candidate. Certification applies to the declared finite scenario universe. This workflow adapts the proposal–verification loop from counterexample-guided synthesis. SolarLezama2006

Symmetry-aware MAP-Elites

Use a canonicalization callback when several representations denote the same evaluated design. In this example, two machines have identical costs and capacities, so exchanging their labels preserves the total quality and the load imbalance.

from qdpy.algorithms import SymmetryAwareMAPElites
from qdpy.containers import Grid

archive = Grid(
    shape=(5,), features_domain=((0, 5),),
    fitness_domain=((0., 1.),), fitness_weights=(1.,),
)

def propose(rng):
    return tuple(map(int, rng.integers(5, size=2)))

def mutate(genome, rng):
    child = list(genome)
    child[rng.integers(2)] = int(rng.integers(5))
    return tuple(child)

def evaluate(genome):
    first, second = genome
    return (min(1., (first + second) / 6.),), (abs(first - second),)

search = SymmetryAwareMAPElites(
    archive, canonicalize=sorted, propose=propose, mutate=mutate, seed=4,
)
stats = search.run(evaluate, proposals=60, max_evaluations=15)
print(stats.proposals, stats.evaluations, stats.duplicates)

Each proposal becomes a canonical tuple before evaluation. Its entries must be hashable. The callback must return the same tuple for all equivalent designs, and applying it twice must give the same result. Use a fixed, deterministic evaluator because the search caches successfully measured representatives across calls.

To test a symmetry, evaluate a few designs before and after relabeling. Check fitness, descriptors, and feasibility. Preserve labels such as fixed terminals when they have physical meaning. The network example checks the full small design space against its canonical representatives. McKay2014