Evaluate a MAP-Elites search with Ray ===================================== Run one QDpy driver for the search. It asks for candidates, receives their results, and updates its archive. Ray workers evaluate the candidates. Install the same Python version, QDpy, Ray, and your evaluator's dependencies on each worker. Evaluators and candidate data must be serializable by Ray. Start on one machine -------------------- From the QDpy checkout, install the optional backend in your environment and run the small ordered example. The ``--workers`` setting gives local Ray two CPUs. The explicit address ``local`` starts a fresh Ray runtime. .. code-block:: bash python -m pip install '.[ray]' 'ray==2.60.0' python examples/ray_slurm/map_elites.py --ray-address local --workers 2 \ --budget 128 --batch-size 32 --pack-size 8 --work 1 64 \ --output build/ray-local A run with seed 19 on one Shoal node reported 128 candidates, 90 occupied cells, and a best fitness of 0.170684 for both workloads. The serial and Ray files shared the same archive fingerprint. Read ``build/ray-local/summary.json`` for the timings and candidate count per worker host. Attach to a running cluster --------------------------- To attach to a running cluster from one of its nodes, pass the Ray head's address to the parallelism manager. Match the cluster's authentication settings in the driver environment. .. code-block:: python from qdpy.base import ParallelismManager with ParallelismManager("ray", ray_address="10.0.1.21:6379") as parallel: search.optimise(evaluate, executor=parallel.executor) You can supply the address through ``RAY_ADDRESS`` instead. With neither setting, the manager starts local Ray. If your application initialized Ray already, omit the address to share that connection. Closing the manager leaves a caller-owned connection usable. An attached cluster sets its own CPU capacity. The YAML-driven Rastrigin example also accepts ``python examples/rastrigin.py --ray-address HEAD:PORT``. Pass the address again when replaying a run against a specific cluster. See `Starting Ray `__ and `Ray token authentication `__. Resume an ordered Ray search ---------------------------- The checkpoint example sends each MAP-Elites batch to an ordered Ray map. The driver publishes its progress after completing whole batches. Keep the output directory across processes and use the same search settings on both invocations. .. code-block:: sh python examples/resume_map_elites.py build/resume-ray --ray-address local --stop-after 32 python examples/resume_map_elites.py build/resume-ray --ray-address local --resume-trusted Use the head address in place of ``local`` for an attached cluster. See :doc:`run_results` for checkpoint and evaluator requirements. Use Ray inside a Rundra task ---------------------------- In the Rundra example, each task can start a local Ray runtime and keep its own archive. From ``examples/rundra``, run the Ray pilot once your target and image are configured. Use the printed Run ID to wait for and fetch the output. See :doc:`tutorial_rundra` for target setup and the full retrieval commands. .. code-block:: bash rundr submit experiment-shoal-ray.yaml --profile shoal --config ray.yaml --seed 0 Use the same Apptainer image for a multi-node search with the Slurm launcher below. Launch a multi-node search with Slurm ------------------------------------- The launcher uses one Slurm task per node and starts the driver on the head node. The tested runtime used Ray 2.60.0. The launcher creates a per-job token on the shared filesystem and derives a TCP port from the job ID. Use it within a trusted cluster network. The script defaults to two nodes with nine allocated CPUs each and gives Ray eight CPUs per node. Use an absolute path on the shared filesystem for the script and output directory. From an account with a matching environment on every node, including Ray and ``grpcio``, run the following from the checkout. An optional runtime prefix lets you use an Apptainer image containing the same environment. .. code-block:: bash python -m pip install '.[ray]' 'ray==2.60.0' grpcio sbatch examples/ray_slurm/run.sh "$PWD/examples/ray_slurm/map_elites.py" \ "$PWD/ray-results" sbatch examples/ray_slurm/run.sh "$PWD/examples/ray_slurm/map_elites.py" \ "$PWD/ray-results" apptainer exec --cleanenv /shared/qdpy-ray.sif Set ``QDPY_RAY_HEAD_IP`` if the batch host's first IPv4 address is on a different network. If the selected port is busy, set ``QDPY_RAY_PORT`` to a free port with its successor also free. Slurm's standard output and the per-rank ``ray-*.log`` files capture startup failures. See `Ray's Slurm guide `__. The Shoal test used the Apptainer command. The host-side Slurm script starts Ray on every allocated node and launches one QDpy driver. You can build the image using the same recipe as the Rundra example in :doc:`tutorial_rundra`. Compare the archive and throughput ---------------------------------- The example runs two workloads of 4,096 candidates each. It groups 16 candidates per Ray task and uses the same search seed and batches for serial and distributed evaluation. The coordinator calls ``tell()`` in submission order through ``executor.map()``. QDpy's ordinary ``optimise()`` processes completed groups as they become ready. That order can change which candidates an archive-dependent search proposes next. The script writes four portable archives and a ``summary.json`` with fingerprints, evaluations per host, and search times. A mismatch or insufficient worker hosts makes the job fail. The second workload repeats the same objective call 512 times per candidate to measure how the evaluation cost affects throughput. The archive still receives one observation per candidate. In the two-node Shoal pilot, all four archive files matched and held 960 elites. For the costlier workload, the two Ray nodes evaluated 2,256 and 1,840 candidates and finished the search in 2.84 seconds. Serial took 5.86 seconds. See :doc:`parallelism_benchmarks` for both workloads and timing details, :doc:`tutorial_ask_tell` for control of feedback, and `Ray's guidance on batching small tasks `__.