pyRTX.core.parallel_utils

Functions

get_ncores(lst, **kwargs)

Returns the number of cores for parallel computations.

get_unwrapped(*args, **kwargs)

Returns the unwrapped version of a class method.

is_method(func, cls_inst)

Checks if the wrapped object is a method of a class.

parallel(func)

Decorator for parallel computations.

pyRTX.core.parallel_utils.get_ncores(lst, **kwargs)[source]

Returns the number of cores for parallel computations. If not specified, the number of cores is set to the number available on your machine.

pyRTX.core.parallel_utils.is_method(func, cls_inst)[source]

Checks if the wrapped object is a method of a class.

pyRTX.core.parallel_utils.get_unwrapped(*args, **kwargs)[source]

Returns the unwrapped version of a class method.

pyRTX.core.parallel_utils.parallel(func)[source]

Decorator for parallel computations. The decorated object can be a class method or a regular function. It applies the function to every item of an iterable performing the computations in parallel. The output will be an iterator which contains the return value of every function call.

The decorated object can accept multiple arguments, but the last positional argument must be an item of the input iterable (e.g. an item of a list / numpy array / range object …).

If the keyword argument ‘n_cores’ is specified, the decorated object will run on n_cores processes. Otherwise, the number of cores is set to the number available on your machine.

Basic usage:

  • Define the input iterable:

iterable = [2,5,6,7,3,4,1]

  • Define the function that will be applied to every item of the input iterable:

@parallel def target_func( some_inputs, item ):

… perform tasks return result

  • Apply the function to every item of the iterable using 5 cores in parallel:

results = target_func( some_inputs, iterable, n_cores = 5 )

NOTE: In its definition, the decorated object accepts the item of the iterable as last positional argument. However, in the function call, you must pass directly the iterable (the list of integers in this example) in place of the item. Every other positional argument before the iterable must be the same. In the function call it is possible to also pass the number of cores, but only as a keyword argument.