Skip to content

AlgorithmTimeLimitManager

QuantConnect.Lean.Engine.AlgorithmTimeLimitManager

AlgorithmTimeLimitManager(
    additional_time_bucket: ITokenBucket,
    time_loop_maximum: timedelta,
)

Bases: Object, IIsolatorLimitResultProvider

Provides an implementation of IIsolatorLimitResultProvider that tracks the algorithm manager's time loops and enforces a maximum amount of time that each time loop may take to execute. The isolator uses the result provided by is_within_limit to determine if it should terminate the algorithm for violation of the imposed limits.

Initializes a new instance of AlgorithmTimeLimitManager to manage the creation of IsolatorLimitResult instances as it pertains to the algorithm manager's time loop

Parameters:

Name Type Description Default
additional_time_bucket ITokenBucket

Provides a bucket of additional time that can be requested to be spent to give execution time for things such as training scheduled events

required
time_loop_maximum timedelta

Specifies the maximum amount of time the algorithm is permitted to spend in a single time loop. This value can be overriden if certain actions are taken by the algorithm, such as invoking the training methods.

required

additional_time_bucket

additional_time_bucket: ITokenBucket

Gets the additional time bucket which is responsible for tracking additional time requested for processing via long-running scheduled events. In LEAN, we use the LeakyBucket

is_within_limit

is_within_limit() -> IsolatorLimitResult

Determines whether or not the algorithm time loop is considered within the limits

request_additional_time

request_additional_time(minutes: int) -> None

Requests additional time to continue executing the current time step. At time of writing, this is intended to be used to provide training scheduled events additional time to allow complex training models time to execute while also preventing abuse by enforcing certain control parameters set via the job packet.

Each time this method is invoked, this time limit manager will increase the allowable execution time by the specified number of whole minutes

start_new_time_step

start_new_time_step() -> None

Invoked by the algorithm at the start of each time loop. This resets the current time step elapsed time.

try_request_additional_time

try_request_additional_time(minutes: int) -> bool

Attempts to requests additional time to continue executing the current time step. At time of writing, this is intended to be used to provide training scheduled events additional time to allow complex training models time to execute while also preventing abuse by enforcing certain control parameters set via the job packet.

Each time this method is invoked, this time limit manager will increase the allowable execution time by the specified number of whole minutes