Benchmark search throughput¶
See QDpy parallelism benchmarks for runtime and speedup plots across 16 methods using sequential evaluation, threads, processes, and local Ray.
Run the suite from the repository root in a Python environment with QDpy’s dependencies installed. The suite runs packed Rastrigin MAP-Elites, steady-state NSLC with a growing parent archive, and two-dimensional CVT lookups. It seeds each repeat, reports median throughput, and checks that the repeats produce identical archives or centroid assignments.
mkdir -p build/benchmarks
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 \
python -m scripts.benchmark_qdpy suite --output build/benchmarks/source.json
For an installed-wheel comparison, run the same script with the interpreters from two environments. Install the default wheel in one and the accelerated wheel in the other. Use the same Python and scientific dependency versions on the same machine. The report records the imported QDpy path, whether acceleration loaded, and the thread settings. See Run the release preflight.
export OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1
/path/to/default-env/bin/python -I scripts/benchmark_qdpy.py suite \
--output build/benchmarks/default.json
/path/to/accelerated-env/bin/python -I scripts/benchmark_qdpy.py suite \
--output build/benchmarks/accelerated.json
python -m scripts.benchmark_qdpy compare \
build/benchmarks/default.json build/benchmarks/accelerated.json
The comparison checks evaluation and admission counts, retained genomes, measurements, order, grid cells, and parent history. It exits with an error on differing workload settings or seeded results. Archive checks exclude elapsed times and timestamp-based candidate names.
The default suite uses 16,384 MAP-Elites evaluations, 3,500 NSLC evaluations
and 4,096 CVT queries. Use --workload to select a single workload and
--repeats to set the repeat count. CVT centroid fitting is reported as
setup time. A million-evaluation evolutionary run is an explicit option:
python -m scripts.benchmark_qdpy suite --workload map-elites \
--map-evaluations 1000000 --repeats 1 --output build/benchmarks/million.json
Measure logging costs¶
The logging command compares the same packed MAP-Elites search without a logger, with in-memory logging, and with standard checkpoint and final pickles. It checks that the three modes retain identical archives. The default budget is 100,000 evaluations with batches of 128 and a checkpoint period of 100 iterations.
python -m scripts.benchmark_qdpy logging --evaluations 100000 \
--checkpoint-period 100 --profile-out build/benchmarks/logging.prof \
--output build/benchmarks/logging.json
python -m pstats build/benchmarks/logging.prof
The JSON contains the duration and file size of each snapshot. Snapshot
time includes table construction, serialization, and the filesystem
write. The files are removed after each run. Set TMPDIR to compare a
particular filesystem. With --profile-out the command runs the
checkpoint case again under cProfile. The profiling pass runs without
RSS sampling and is outside the throughput medians.
Resident memory is sampled approximately every 50 ms during the measured operation. The reports include starting, peak sampled, and ending process RSS. The search traces pair each sample with the completed evaluation count. RSS includes Python, imported libraries, and allocator memory retained from earlier repeats. Checkpoint allocations shorter than one sampling interval can fall between samples.
Compare evaluation executors¶
See QDpy parallelism benchmarks for measured times from the local executor, Walker, Ray, and Rundra runs.
The parallel command uses QDpy’s sequential, multithreading and concurrent process executors on packed Rastrigin MAP-Elites. Four workers and a pack size of 32 allow four evaluation calls per batch of 128. One repeat per backend is the default. Set the evaluation budget explicitly for a longer run:
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 \
python -m scripts.benchmark_qdpy parallel --evaluations 1000000 \
--output build/benchmarks/parallel.json
Use --parallelism sequential, multithreading, or concurrent
to run a backend in its own process. Threads and processes can report
results in different orders within a batch. That order can change
archive admission and subsequent parent choices. The parallel report
retains the archive result for each concurrent repeat along with its
timing. Coordinator RSS and the sampled sum of child RSS are reported
separately. The child sum includes supporting processes and can count
shared pages more than once.
Use a local TMPDIR for process workers when running from a network
filesystem.
Pack evaluations in blocks¶
For inexpensive numerical objectives, convert a block of genomes to an
array, evaluate it with NumPy, and return one result per candidate in the
original order. This works with the sequential executor as well as with a
pool. With a batch_size of 1024, this configuration submits four
calls of up to 256 candidates each.
from qdpy.base import ParallelismManager
with ParallelismManager("multithreading", max_workers=4) as manager:
best = algorithm.optimise(
evaluate_block,
executor=manager.executor,
send_several_suggestions_to_fn=True,
max_nb_suggestions_per_call=256,
)
Choose a pack size that leaves enough calls per batch for your workers.
Threads can overlap work in numerical kernels that release Python’s GIL.
Processes can also run CPU-bound Python code in parallel, with a cost for
serializing candidates and results. Use an importable evaluator and a
__main__ guard when using processes in a script.
Use --batch-size and --pack-size to test the tradeoff. Compare
backends at the same settings because increasing the batch size changes
when the search can select from newly admitted elites. An evaluator can
also parallelize its own work within a single packed call per batch and
return ordered results to the sequential executor. That keeps feedback
in the same order as sequential evaluation at the same batch size.
python -m scripts.benchmark_qdpy parallel --evaluations 32768 \
--repeats 3 --batch-size 1024 --pack-size 256
Add --rastrigin-samples 128 to test a more expensive evaluator with
the same genome and result sizes. It averages 128 deterministic shifted
Rastrigin scores for each candidate. The reported evaluation count still
counts candidates.
Benchmark the Walker simulation¶
The optional walker workload uses the repository’s Bipedal Walker
simulation and a small NumPy policy. Each candidate runs one seeded episode
with a 120-step cap. The fitness is episode reward. The descriptors are
average distance and head stability. Install gymnasium[box2d] in the
benchmark environment and run from the repository root.
OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 \
python -m scripts.benchmark_qdpy parallel --workload walker --ordered \
--evaluations 192 --batch-size 32 --pack-size 4 --repeats 3
--ordered uses ordered worker results within each batch and checks that
all backends produce the same seeded archive. To tune pack size, keep
--batch-size fixed and vary --pack-size. See Control evaluation with ask and tell
for the ordered evaluator pattern.