Implementation:Interpretml Interpret Powerlift Executor
| Knowledge Sources | |
|---|---|
| Domains | Benchmarking, Execution |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
Abstract base class defining the executor interface for Powerlift trial execution, along with utility functions for timed execution and error handling.
Description
This module provides the foundational abstractions for all Powerlift executors:
- Executor class -- An abstract base class that defines the three core lifecycle methods for trial execution:
submit()to start asynchronous execution,join()to block until completion, andcancel()to abort execution. All methods raiseNotImplementedErrorby default and must be overridden by concrete implementations.
- timed_run() function -- A utility that executes a callable with a configurable timeout (default 3600 seconds) using
stopit.ThreadingTimeout. Returns a tuple of (result, duration, timed_out). If the function times out, the result is set to None.
- handle_err() function -- A simple error callback that re-raises a provided exception. Used as the
error_callbackparameter in multiprocessing pool submissions across executor implementations.
Usage
Use this module as the base for implementing custom Powerlift executors. All concrete executor classes (LocalMachine, AzureContainerInstance, AzureVMInstance, InsecureDocker, BicepAzureContainerInstance) extend this base class. The timed_run function is used by the trial runner to enforce execution time limits.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File:
python/powerlift/powerlift/executors/base.py
Signature
class Executor:
def submit(
self,
experiment_id,
timeout: Optional[int] = None,
):
raise NotImplementedError()
def join(self):
raise NotImplementedError()
def cancel(self):
raise NotImplementedError()
def timed_run(f: FunctionType, timeout_seconds: int = 3600) -> Tuple[Any, Number, bool]:
...
def handle_err(err: Exception):
raise err
Import
from powerlift.executors.base import Executor, timed_run, handle_err
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| experiment_id | int | Yes | Identifier of the experiment to execute (for submit) |
| timeout | int | No | Timeout in seconds for trial execution (for submit) |
| f | FunctionType | Yes | Function to execute with time limit (for timed_run) |
| timeout_seconds | int | No | Maximum execution time in seconds (default: 3600, for timed_run) |
| err | Exception | Yes | Exception to re-raise (for handle_err) |
Outputs
| Name | Type | Description |
|---|---|---|
| timed_run return | Tuple[Any, Number, bool] | Tuple of (function result, duration in seconds, whether timeout occurred) |
Usage Examples
from powerlift.executors.base import Executor, timed_run
# Using timed_run to execute a function with timeout
def expensive_computation():
# ... long-running computation
return result
result, duration, timed_out = timed_run(expensive_computation, timeout_seconds=300)
if timed_out:
print(f"Computation timed out after {duration:.1f}s")
else:
print(f"Completed in {duration:.1f}s with result: {result}")
# Implementing a custom executor
class MyExecutor(Executor):
def submit(self, experiment_id, timeout=None):
# Custom submission logic
pass
def join(self):
# Block until complete
pass
def cancel(self):
# Cancel running execution
pass
Related Pages
- Interpretml_Interpret_Powerlift_LocalMachine -- Concrete executor for local machine execution
- Interpretml_Interpret_Powerlift_AzureContainerInstance -- Concrete executor for Azure Container Instances
- Interpretml_Interpret_Powerlift_AzureVMInstance -- Concrete executor for Azure Virtual Machines
- Interpretml_Interpret_Powerlift_InsecureDocker -- Concrete executor for local Docker containers
- Interpretml_Interpret_Powerlift_BicepAzureContainerInstance -- Concrete executor using Bicep for ACI provisioning
- Interpretml_Interpret_Powerlift_RunTrials -- Trial worker that uses timed_run for execution