pySimBlocks.core.task

class pySimBlocks.core.task.Task(sample_time: float, period_ticks: int, blocks: List[Block], global_output_order: List[Block])[source]

Bases: object

A group of blocks sharing the same sample time.

Manages the scheduling and execution of output updates, state updates, and state commits for all blocks in the group.

Scheduling is tick-based: the task maintains an integer countdown reset to period_ticks - 1 after each activation. This avoids floating-point time comparisons and works correctly with both fixed and external clocks.

sample_time

Sampling period of this task in seconds.

period_ticks

Number of base ticks between two activations.

ticks_until_next

Countdown to the next activation.

accumulated_dt

Accumulated time since the last activation.

output_blocks

Blocks ordered for output computation, filtered from the global output order.

state_blocks

Subset of output_blocks that carry internal state.

update_state_blocks() None[source]

Refresh the list of stateful blocks from output_blocks.

should_run() bool[source]

Return True if the task is due to run at time t.

Returns:

True if ticks_until_next is zero, indicating that the task should run at the current time step.

advance() None[source]

Advance the countdown by one tick.

accumulate(dt: float) None[source]

Accumulate the time step dt since the last activation.

Parameters:

dt – Time step in seconds to accumulate.

reset_accumulated_dt() None[source]

Reset the accumulated time to zero after an activation.