uvex_transients.phase_space.experiment.fork_map#

uvex_transients.phase_space.experiment.fork_map(sampler: Sampler, rule: StoppingRule, processes: int | None = None) → Iterator[Callable][source]#

Provide a map_fn that measures the points of a batch in forked worker processes.

A survey-backed sampler cannot be pickled (its schedule holds a satellite orbit), so an ordinary process pool cannot be sent one. The workers of this pool are forked instead, and inherit the sampler as it is when the pool is made, so anything it has computed by then (a table of redshift limits, say) is shared and not repeated. Each point carries its own seed, so a result does not depend on which worker measured it, or on how many there are.

with fork_map(
    experiment.sampler,
    experiment.rule,
    processes=8,
) as map_fn:
    experiment.run(map_fn=map_fn)
Parameters:
  • sampler (Sampler) – What measures a point. It is not changed by the workers.

  • rule (StoppingRule) – How many tries a point gets.

  • processes (int, optional) – The number of worker processes. By default the number of CPUs.

Yields:

callable – map_fn(function, tasks), for the map_fn of run_campaign(), Experiment.run or run_experiment(). It measures the tasks and ignores function, which it could not send to the workers.

Raises:

ValueError – If the platform cannot fork.