simsopt.util package

Submodules

simsopt.util.logging module

simsopt.util.logging.initialize_logging(filename: Optional[str] = None, level: Optional[str] = None, mpi: bool = False)None

Initializes logging in a simple way for both serial and MPI jobs. The MPI logging uses MPILogger package.

Parameters
  • filename – Name of file to store the logging info

  • level – Logging level. Could be ‘INFO’, ‘DEBUG’, ‘WARNING’, etc.

  • mpi – If True MPI logging is used provided mpi4py is installed.

simsopt.util.mpi module

This module contains the MpiPartition class.

This module should be completely self-contained, depending only on mpi4py and numpy, not on any other simsopt components.

class simsopt.util.mpi.MpiPartition(ngroups: Union[None, int] = None, comm_world: Optional[mpi4py.MPI.Intracomm] = mpi4py.MPI.COMM_WORLD)

Bases: object

This module contains functions related to dividing up the set of MPI processes into groups, each of which can work together. For more information, see MPI Partitions and worker groups.

Parameters
  • ngroups – The number of worker groups desired. If None, a worker group will be created for each MPI process. If a value is supplied that is larger than the number of processes, the number will be lowered to the number of processes.

  • comm_world – The MPI communicator containing all processes to split into worker groups.

ngroups

The number of worker groups.

Type

int

group

Index giving the worker group that this MPI process belongs to.

Type

int

comm_world

The MPI communicator that includes all processes together.

Type

mpi4py.MPI.Intracomm

comm_groups

The MPI communicator representing the worker groups.

Type

mpi4py.MPI.Intracomm

comm_leaders

The MPI communicator that includes only leaders of worker groups.

Type

mpi4py.MPI.Intracomm

rank_world

The MPI rank in the comm_world communicator.

Type

int

rank_groups

The MPI rank in the comm_groups communicator.

Type

int

rank_leaders

The MPI rank in the comm_leaders communicator, or -1 for processes that are not group leaders.

Type

int

nprocs_world

The number of MPI processes in the comm_world communicator.

Type

int

nprocs_groups

The number of MPI processes in this process’s worker group.

Type

int

nprocs_leaders

The number of group leaders, if this process is a group leader, otherwise -1.

Type

int

proc0_world

Whether this MPI process has rank 0 in comm_world.

Type

bool

proc0_groups

Whether this MPI process has rank 0 in comm_groups, i.e. whether this process is a group leader.

Type

bool

.

apart(leaders_action, workers_action)

Send workers and group leaders off to their respective loops to wait for instructions from their group leader or proc0_world, respectively.

leaders_loop(action)

actions should be a dict where the keys are possible integer constants, and the values are callable functions that are called when the corresponding key is sent from mobilize_leaders.

mobilize_leaders(action_const)

This function is called by proc0_world to tell the other group leaders that it is time to begin some action, e.g. starting to calculat a finite difference Jacobian.

mobilize_workers(action_const)
stop_leaders()
stop_workers()
together()

Bring workers and group leaders back from their respective loops.

worker_loop(action)

actions should be a dict where the keys are possible integer constants, and the values are callable functions that are called when the corresponding key is sent from mobilize_workers.

write()

Print info about the MPI configuration

simsopt.util.mpi.log(level: int = 20)

Turn on logging. If MPI is available, the processor number will be added to all logging entries.

Parameters

level – Typically logging.INFO for regular output, or logging.DEBUG for more extensive output.

simsopt.util.types module

This module contains small utility functions and classes.

Module contents