Skip to main content

Synchronous Base Executor Class

class covalent.executor.base.BaseExecutor

#

Base executor class to be used for defining any executor plugin. Subclassing this class will allow you to define your own executor plugin which can be used in covalent.

log_stdout

The path to the file to be used for redirecting stdout.

log_stderr

The path to the file to be used for redirecting stderr.

cache_dir

The location used for cached files in the executor.

time_limit

time limit for the task

retries

Number of times to retry execution upon failure.

Methods

cancel(task_metadata, job_handle)

Method to cancel the job identified uniquely by the job_handle (base class)

execute(function, args, kwargs, dispatch_id, …)

Execute the function with the given arguments.

from_dict (object_dict)

Rehydrate a dictionary representation

Check if the task was requested to be canceled

get_dispatch_context(dispatch_info)

Start a context manager that will be used to access the dispatch info for the executor.

run(function, args, kwargs, task_metadata)

Abstract method to run a function in the executor.

Save the job_id/handle returned by the backend executing the task

setup(task_metadata)

Placeholder to run any executor specific tasks

teardown(task_metadata)

Placeholder to run nay executor specific cleanup/teardown actions

Return a JSON-serializable dictionary representation of self

write_streams_to_file(stream_strings, …)

Executor specific teardown method

cancel

#

Method to cancel a job (base class)

Arg(s)

task_metadata

Metadata of the task to be canceled.

job_handle

Unique ID of the job assigned by the backend

Return

False by default

Return Type

Literal[False]

execute

#

Execute the function with the given arguments.

This calls the executor-specific run() method.

Parameters

function (Callable) – The input python function which will be executed and whose result is ultimately returned by this function.

args (List) – List of positional arguments to be used by the function.

kwargs (Dict) – Dictionary of keyword arguments to be used by the function.

dispatch_id (str) – The unique identifier of the external lattice process which is calling this function.

results_dir (str) – The location of the results directory.

node_id (int) – ID of the node in the transport graph which is using this executor (default is -1).

Return(s)

The result of the function execution.

Return Type

output

from_dict

#

Rehydrate a dictionary representation.

Instance attributes will be overwritten.

Parameters

object_dict (dict) - A dictionary representation returned by to_dict.

Return Type

BaseExecutor

Returns

self

Instance attributes will be overwritten.

get_cancel_requested

#

Check if the task was requested to be canceled by the user.

Arg(s)

None

Return(s)

True/False whether task cancellation was requested.

Return Type

bool

get_dispatch_context

#

Start a context manager that will be used to access the dispatch info for the executor.

Parameters

dispatch_info (DispatchInfo) - The dispatch info to be used inside the current context.

Return Type

AbstractContextManager[DispatchInfo]

Return(s)

A context manager object that handles the dispatch info.

abstract run

#

Abstract method to run a function in the executor.

Parameters

function (Callable) – The function to run in the executor.

args (List) – List of positional arguments to be used by the function.

kwargs (Dict) – Dictionary of keyword arguments to be used by the function.

task_metadata (Dict) – Dictionary of metadata for the task. Current keys are dispatch_id and node_id.

Returns

A context manager object that handles the dispatch info.

Return Type

output

set_job_handle

#

Save the job_id/handle returned by the backend executing the task.

Arg(s)

handle

Any JSONable type to identify the task being executed by the backend.

Return(s)

Response from saving the job handle to the database.

Return Type

Any

setup

#

Placeholder to run any executor specific tasks.

Return Type

Any

teardown

#

Placeholder to run any executor-specific tasks.

Return Type

Any

to_dict

#

Return a JSON-serializable dictionary representation of self.

Return Type

dict

write_streams_to_file

#

Write the contents of stdout and stderr to respective files.

Parameters

stream_strings (Iterable[str]) – The stream_strings to be written to files.

filepaths (Iterable[str]) – The location of the results directory.

dispatch_id (str) – The ID of the dispatch which initiated the request.

results_dir (str) – The location of the results directory.

Return Type

None