adaptive.utils module#

class adaptive.utils.SequentialExecutor[source]#

Bases: concurrent.futures._base.Executor

A trivial executor that runs functions synchronously.

This executor is mainly for testing.

map(fn, *iterable, timeout=None, chunksize=1)[source]#

Returns an iterator equivalent to map(fn, iter).

Parameters
  • fn – A callable that will take as many arguments as there are passed iterables.

  • timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.

  • chunksize – The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.

Returns

map(func, *iterables) but the calls may be evaluated out-of-order.

Return type

An iterator equivalent to

Raises
  • TimeoutError – If the entire result iterator could not be generated before the given timeout.

  • Exception – If fn(*args) raises for any values.

shutdown(wait=True)[source]#

Clean-up the resources associated with the Executor.

It is safe to call this method several times. Otherwise, no other methods can be called after this one.

Parameters
  • wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.

  • cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.

submit(fn: Callable, *args, **kwargs) concurrent.futures._base.Future[source]#

Submits a callable to be executed with the given arguments.

Schedules the callable to be executed as fn(*args, **kwargs) and returns a Future instance representing the execution of the callable.

Returns

A Future representing the given call.

adaptive.utils.assign_defaults(function, df, function_prefix: str = 'function.')[source]#
adaptive.utils.cache_latest(f: Callable) Callable[source]#

Cache the latest return value of the function and add it as ‘self._cache[f.__name__]’.

adaptive.utils.copy_docstring_from(other: Callable) Callable[source]#
adaptive.utils.load(fname: str, compress: bool = True) Any[source]#
adaptive.utils.named_product(**items: Mapping[str, Sequence[Any]])[source]#
adaptive.utils.partial_function_from_dataframe(function, df, function_prefix: str = 'function.')[source]#
adaptive.utils.restore(*learners) contextlib._GeneratorContextManager[source]#
adaptive.utils.save(fname: str, data: Any, compress: bool = True) bool[source]#