RuntimeHandle.submit

RuntimeHandle.submit(fn, *args, task_name=None, log_context={}, **kwargs)[source]

Submit a function to the runtime for execution.

This method schedules the function fn to be executed by the runtime with the provided arguments args and keyword arguments kwargs. The execution may happen asynchronously.

Parameters:
  • fn (Callable[..., Any]) – The function to be executed.

  • *args (Any) – Variable length argument list to be passed to the function fn.

  • task_name (str | None) – An optional name for the task, which can be used for logging or tracking purposes. Defaults to None, which will use the function name as the task name.

  • log_context (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.

  • **kwargs (Any) – Arbitrary keyword arguments to be passed to the function fn.

Returns:

An object representing the future result of the function execution. This can be used to retrieve the result by `await`ing it.

Return type:

RuntimeFuture

Example

>>> from bqskit.runtime import get_runtime
>>>
>>> def add(x, y):
...     return x + y
>>>
>>> future = get_runtime().submit(add, 1, 2)
>>> result = await future
>>> print(result)
3

See also

  • map() for submitting multiple tasks in parallel.

  • cancel() for cancelling tasks.

  • RuntimeFuture for more

    information on how to interact with the future object.