RuntimeHandle.map
- RuntimeHandle.map(fn, *args, task_name=None, log_context={}, **kwargs)[source]
Map a function over a sequence of arguments and execute in parallel.
This method schedules the function fn to be executed by the runtime for each set of arguments provided in args. Each invocation of fn will be executed potentially in parallel, depending on the runtime’s capabilities and current load.
- Parameters:
fn (
Callable[...,Any]) – The function to be executed.*args (
Any) – Variable length argument list to be passed to the function fn. Each argument is expected to be a sequence of arguments to be passed to a separate invocation. The sequences should be of equal length.task_name (
Sequence[str | None] | str | None) – An optional name for the task group, which can be used for logging or tracking purposes. Defaults to None, which will use the function name as the task name. If a string is provided, it will be used as the prefix for all task names. If a sequence of strings is provided, each task will be named with the corresponding string in the sequence.log_context (
Sequence[dict[str,str]]) | dict[str,str]) – A dictionary containing logging context information. All log messages produced by the fn and any children tasks will contain this context if the appropriate level (logging.DEBUG) is set on the logger. Defaults to an empty dictionary for no added context. Can be a sequence of contexts, one for each task, or a single context to be used for all tasks.**kwargs (
Any) – Arbitrary keyword arguments to be passed to each invocation of the function fn.
- Returns:
An object representing the future result of the function executions. This can be used to retrieve the results by `await`ing it, which will return a list.
- Return type:
Example
>>> from bqskit.runtime import get_runtime >>> >>> def add(x, y): ... return x + y >>> >>> args_list = [(1, 2, 3), (4, 5, 6)] >>> future = get_runtime().map(add, *args_list) >>> results = await future >>> print(results) [5, 7, 9]
See also
submit()for submitting a single task.cancel()for cancelling tasks.next()for retrieving results incrementally.RuntimeFuturefor moreinformation on how to interact with the future object.