parallel

Multi-threaded functions for parameter sweeps

Functions

ndsweep(factory[, plot, labels, tags, silent]) Do a multi-threaded n-dimensional parameter sweep
parallel_for(factory[, make_result]) Multi-threaded loop feed by the factory function
parallelize([num_threads, queue_size]) A decorator which creates factory functions for parallel_for()
sweep(factory[, plot, labels, tags, silent]) Do a multi-threaded parameter sweep
parallel_for(factory, make_result=None)

Multi-threaded loop feed by the factory function

Parameters:
factory : Factory

Factory function created with the parallelize() decorator.

make_result : callable, optional

Creates the final result from raw data. This result is also the final return value of parallel_for().

Returns:
array_like

A result for each loop iteration.

Examples

@parallelize(x=np.linspace(0, 1, 10))
def factory(x):
    pb.Model(...)  # depends on `x`
    greens = pb.greens.kpm(model)
    return greens.deferred_ldos(...)  # may also depend on `x`

results = parallel_for(factory)
parallelize(num_threads=num_cores, queue_size=num_cores, **kwargs)

A decorator which creates factory functions for parallel_for()

The decorated function must return a Deferred compute kernel.

Parameters:
num_threads : int

Number of threads that will run in parallel. Defaults to the number of cores in the current machine.

queue_size : int

Number of Deferred jobs to be queued up for consumption by the worker threads. The maximum number of jobs that will be kept in memory at any one time will be queue_size + num_threads.

**kwargs

Variables which will be iterated over in parallel_for() and passed to the decorated function. See example.

Examples

@parallelize(a=np.linspace(0, 1, 10), b=np.linspace(-2, 2, 10))
def factory(a, b):
    pb.Model(...)  # depends on `a` and `b`
    greens = pb.greens.kpm(model)
    return greens.deferred_ldos(...)  # may also depend on `a` and `b`

results = parallel_for(factory)
sweep(factory, plot=<function <lambda>>, labels=None, tags=None, silent=False)

Do a multi-threaded parameter sweep

Parameters:
factory : Factory

Factory function created with the parallelize() decorator.

plot : callable

Plotting functions which takes a Sweep result as its only argument.

labels, tags : dict

Forwarded to Sweep object.

silent : bool

Don’t print status messages.

Returns:
Sweep
ndsweep(factory, plot=None, labels=None, tags=None, silent=False)

Do a multi-threaded n-dimensional parameter sweep

Parameters:
factory : Factory

Factory function created with the parallelize() decorator.

plot : callable

Plotting functions which takes a NDSweep result as its only argument.

labels, tags : dict

Forwarded to NDSweep object.

silent : bool

Don’t print status messages.

Returns:
NDSweep