# nbodykit¶

Functions

 setup_logging([log_level]) Turn on logging, with the specified level. use_distributed([c]) Setup nbodykit to work with dask.distributed. use_mpi([comm]) Setup nbodykit to work with MPI.

Classes

 CurrentMPIComm A class to faciliate getting and setting the current MPI communicator. GlobalCache(cache, *args, **kwargs) A Cache object. set_options(**kwargs) Set global configuration options.
class nbodykit.CurrentMPIComm[source]

A class to faciliate getting and setting the current MPI communicator.

Methods

 enable(func) Decorator to attach the current MPI communicator to the input keyword arguments of func, via the comm keyword. enter(comm) Enters a context where the current default MPI communicator is modified to the argument comm. get() Get the default current MPI communicator. pop() Restore to the previous current default MPI communicator push(comm) Switch to a new current default MPI communicator set(comm) Set the current MPI communicator to the input value.
static enable(func)[source]

Decorator to attach the current MPI communicator to the input keyword arguments of func, via the comm keyword.

classmethod enter(comm)[source]

Enters a context where the current default MPI communicator is modified to the argument comm. After leaving the context manager the communicator is restored.

Example:

with CurrentMPIComm.enter(comm):
cat = UniformCatalog(...)


is identical to

cat = UniformCatalog(..., comm=comm)

classmethod get()[source]

Get the default current MPI communicator. The initial value is MPI.COMM_WORLD.

classmethod pop()[source]

Restore to the previous current default MPI communicator

classmethod push(comm)[source]

Switch to a new current default MPI communicator

classmethod set(comm)[source]

Set the current MPI communicator to the input value.

class nbodykit.GlobalCache(cache, *args, **kwargs)[source]

A Cache object.

Methods

 get() Return the global cache object.
 register unregister
classmethod get()[source]

Return the global cache object. The default size is controlled by the global_cache_size global option; see set_options.

Returns: cache – the cache object, as provided by dask dask.cache.Cache
class nbodykit.set_options(**kwargs)[source]

Set global configuration options.

Parameters: dask_chunk_size (int) – the number of elements for the default chunk size for dask arrays; chunks should usually hold between 10 MB and 100 MB global_cache_size (float) – the size of the internal dask cache in bytes; default is 1e9 paint_chunk_size (int) – the number of objects to paint at the same time. This is independent from dask chunksize.
nbodykit.setup_logging(log_level='info')[source]

Turn on logging, with the specified level.

Parameters: log_level ('info', 'debug', 'warning') – the logging level to set; logging below this level is ignored
nbodykit.use_distributed(c=None)[source]

Setup nbodykit to work with dask.distributed. This will change the default MPI communicator to MPI.COMM_SELF, such that each nbodykit object only reside on a single MPI rank.

This function shall only be used before any nbodykit object is created.

Parameters: c (Client) – the distributed client. If not given, the default client is used. Notice that if you switch a new client then this function must be called again.
nbodykit.use_mpi(comm=None)[source]

Setup nbodykit to work with MPI. This will change the default MPI communicator to MPI.COMM_WORLD, such that each nbodykit object is partitioned to many MPI ranks.

This function shall only be used before any nbodykit object is created.