propulate.migrator

Module Contents

Classes

Migrator

Initialize Migrator with given parameters.

Attributes

log

propulate.migrator.log
class propulate.migrator.Migrator(loss_fn: Callable | Generator[float, None, None], propagator: propulate.propagators.Propagator, rng: random.Random, island_idx: int = 0, island_comm: mpi4py.MPI.Comm = MPI.COMM_WORLD, propulate_comm: mpi4py.MPI.Comm = MPI.COMM_WORLD, worker_sub_comm: mpi4py.MPI.Comm = MPI.COMM_SELF, generations: int = -1, checkpoint_path: str | pathlib.Path = Path('./'), migration_topology: numpy.ndarray | None = None, migration_prob: float = 0.0, emigration_propagator: Type[propulate.propagators.Propagator] = SelectMin, island_displs: numpy.ndarray | None = None, island_counts: numpy.ndarray | None = None, surrogate_factory: Callable[[], propulate.surrogate.Surrogate] | None = None)

Bases: propulate.propulator.Propulator

Initialize Migrator with given parameters.

Parameters:
  • loss_fn (Union[Callable, Generator[float, None, None]]) – The loss function to be minimized.

  • propagator (propulate.propagators.Propagator) – The propagator to apply for breeding.

  • rng (random.Random) – The separate random number generator for the Propulate optimization.

  • island_idx (int, optional) – The island’s index. Default is 0.

  • island_comm (MPI.Comm, optional) – The intra-island communicator for communication within that island. Default is MPI.COMM_WORLD.

  • propulate_comm (MPI.Comm, optional) – The Propulate world communicator, consisting of rank 0 of each worker’s sub communicator. Default is MPI.COMM_WORLD.

  • worker_sub_comm (MPI.Comm, optional) – The sub communicator for each (multi rank) worker. Default is MPI.COMM_SELF.

  • generations (int, optional) – The number of generations to run. Default is -1, i.e., run into wall-clock time limit.

  • checkpoint_path (pathlib.Path | str, optional) – The path where the checkpoints are loaded from and stored. Default is current working directory.

  • migration_topology (numpy.ndarray, optional) – The migration topology, i.e., a 2D matrix where entry (i,j) specifies how many individuals are sent by island i to island j.

  • migration_prob (float, optional) – The per-worker migration probability. Default is 0.0.

  • emigration_propagator (Type[propulate.propagators.Propagator]) – The emigration propagator, i.e., how to choose individuals for emigration that are sent to the destination island. Should be some kind of selection operator. Default is SelectMin.

  • island_displs (numpy.ndarray, optional) – An array with propulate_comm rank of each island’s worker 0. Element i specifies the rank of worker 0 on island with index i in the Propulate communicator.

  • island_counts (numpy.ndarray, optional) – An array with the number of workers per island. Element i specifies the number of workers on island i.

  • surrogate_factory (Callable[[], propulate.surrogate.Surrogate], optional) – Function that returns a new instance of a Surrogate model. Only used when loss_fn is a generator function.

_send_emigrants() None

Perform migration, i.e. island sends individuals out to other islands.

_receive_immigrants() None

Check for and possibly receive immigrants send by other islands.

Raises:

RuntimeError – If identical immigrant is already active on target island for real migration.

_check_emigrants_to_deactivate() bool

Redundant safety check for existence of emigrants that could not be deactivated in population.

Returns:

True if emigrants to be deactivated exist in population, False if not.

Return type:

bool

_deactivate_emigrants() None

Check for and possibly receive emigrants from other intra-island workers to be deactivated.

propulate(logging_interval: int = 10, debug: int = 1) None

Execute evolutionary algorithm using island model with real migration in parallel.

Parameters:
  • logging_interval (int, optional) – The logging interval. Default is 10.

  • debug (int) – The debug level; 0 - silent; 1 - moderate, 2 - noisy (debug mode). Default is 1.

Raises:

ValueError – If any individuals are left that should have been deactivated before (only for debug > 0).