{ "cells": [ { "cell_type": "markdown", "id": "dca085bb-639d-4507-96d2-d117012b1654", "metadata": { "raw_mimetype": "text/restructuredtext", "tags": [] }, "source": [ "# Computing Results\n", "\n", "## Parallel Generation - ``num_workers`` and ``pool``\n", "\n", "Running a function for many different parameters theoretically allows perfect parallelization since each run is independent. ``xyzpy`` can automatically handle this in a number of different ways:\n", "\n", "1. Supply ``parallel=True`` when calling ``Runner.run_combos(...)`` or ``Harvester.harvest_combos(...)`` etc. This spawns a ``ProcessExecutorPool`` with the same number of workers as logical cores.\n", "\n", "2. Supply ``num_workers=...`` instead to explicitly control how any workers are used. Since for many numeric codes threading is controlled by the environement variable ``$OMP_NUM_THREADS`` you generally want the product of this and ``num_workers`` to be equal to the number of cores.\n", "\n", "3. Supply ``executor=...`` to use any custom parallel pool-executor like object (e.g. a ``dask.distributed`` client or ``mpi4py`` pool) which has a ``submit``/``apply_async`` method, and yields futures with a ``result``/``get`` method. More specifically, this covers pools with an API matching either ``concurrent.futures`` or an ``ipyparallel`` view. Pools from ``multiprocessing.pool`` are also explicitly handled.\n", "\n", "4. Use a {class}`~xyzpy.Crop` to write combos to disk, which can then be 'grown' persistently by any computers with access to the filesystem, such as distributed cluster - see below.\n", "\n", "\n", "The first three options can be used on any of the various functions derived from {func}`~xyzpy.combo_runner`:" ] }, { "cell_type": "code", "execution_count": 1, "id": "fe942df3-732e-40b6-92b5-09963c1ea84d", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|##########| 8/8 [00:01<00:00, 6.53it/s]\n" ] }, { "data": { "text/html": [ "
| \n", " | a | \n", "b | \n", "sum | \n", "diff | \n", "
|---|---|---|---|---|
| 0 | \n", "0 | \n", "1 | \n", "1 | \n", "-1 | \n", "
| 1 | \n", "1 | \n", "2 | \n", "3 | \n", "-1 | \n", "
| 2 | \n", "2 | \n", "3 | \n", "5 | \n", "-1 | \n", "
| 3 | \n", "3 | \n", "4 | \n", "7 | \n", "-1 | \n", "
| 4 | \n", "4 | \n", "5 | \n", "9 | \n", "-1 | \n", "
| 5 | \n", "5 | \n", "6 | \n", "11 | \n", "-1 | \n", "
| 6 | \n", "6 | \n", "7 | \n", "13 | \n", "-1 | \n", "
| 7 | \n", "7 | \n", "8 | \n", "15 | \n", "-1 | \n", "