TTExecuteProcess

The TTExecuteProcess is one of the primary processes that handles runtime mechanisms on a TTEnsemble; specifically, this handles the execution portion of a TTSQ. It implements the TTSQExecute portion, which runs the code within the SQ. When an SQ has executed, this process sends the output token to the TTNetworkManager, where it will be forwarded to downstream SQs. For some types of SQs/Firing Rules, this SQ will also send a control token back to the TTInputTokenProcess

All TT*Process classes follows the same design pattern. They implement a singular input queue from which they read new Messages, which self-identify their function. After processes are created, they exchange interfacing information, primarily in the form of callback functions. After configuring interfaces, the processes start. Each of these processes spends its idle time waiting for new inputs within a ‘run loop’, responding to messages as they arrive; the responses will modify internal process state and produce new messages for other processes implemented on the Ensemble, which ‘owns’ the processes.

class ticktalkpython.ExecuteProcess.TTExecuteProcess(input_queue, ensemble_name=None)

A process to handle the execution of SQ’s specifically the TTSQExecute portion. This process is owned and managed by the TTEnsemble.

The process maintains a dictionary of these and the relevant clocks; these are populated as SQs are instantiated at runtime. It is fed data via an input queue from other processes (TTNetworkManager for instantiating clocks & SQs and TTInputTokenProcess for sets of inputs to execute an SQ on).

This process also maintains a singular root clock that it uses to read ‘real’ time.

Parameters:

input_queue (queue.Queue | multiprocessing.Queue) – The input queue that this process will receive inputs on

execute(execute_context: TTExecutionContext)

Execute a TTSQExecute on a new execution context. This will provide the inputs (in the execute_context) and set of stored keyword arguments (within the TTSQExecute) to be executed in a private namespace with access this SQ’s state

get_next_input()

Pull the next input off the input queue.

get_sq(sq_name)

Retreive an SQ based on its name

Parameters:

sq_name (string) – The name of an SQ

Returns:

The SQ of interest; return None if not present

Return type:

TTSQExecute | None

handle_message(msg)

This will handle IPC (Inter Process Communication) messages arriving to this process via the singular input queue. This will include messages at the data, control, and management planes, which will have designators to specify how they should be handled (using process-specific enumeration)

The execution process will handle messages to instantiate/remove SQs (only the execution portion) and to run an SQ’s execution section on a TTExecutionContext received from the synchronization (input token) process. When this completes, it will stamp tokens with a new tag and send to the network manager process, which will communicate them to downstream SQs on whichever ensembles they are mapped

Parameters:

msg (Message) – A message read off of the input queue. This must be an Message with a msg_type of ExecuteMsg and process_recipient of ProcessExecute, else it will be ignored without notification

Returns:

None; any ‘return-like’ behavior will produce an IPC message for another process

input_msg(message)

Input an Message to this process. If running in a simulation environment, this will interrupt

Parameters:

message (Message) – A message to provide to this process. Does not need to be called within the same process (i.e. it is not only thread-safe but inter-process safe)

remove_sq(sq_name)

Evict an SQ from the process; use the SQ’s name to identify it

Parameters:

sq_name (string) – The name of an SQ

run_phy()

The main run loop for a runtime environment using physical processes, which can take advantage of multi-core processors.

It is expected that this will run in its own distinct multiprocessing.Process (at the level of the OS with its own virtual memory).

This will listen to the input queue and call a handler for any messages that arrive.

run_sim(sim)

The main run loop for a runtime environment using simulated processes, which runs on a single core and can implement many ensembles. This will listen to the input queue and call a handler for any messages that arrive

This must be instantiated using the sim.process() interface, as this function is technically a generator due to its usage of ‘yield’ (an essential component of simpy event processing)

This will listen to the input queue and call a hanlder for any messages that arrive.

setup_proc_intfc(input_token_func, input_network_func, sim_process=None)

Configure the interface to this process, meaning the callback functions for sending outputs to the TTInputTokenProcess or TTNetworkManager

Parameters:
  • input_token_func (function) – A callback function for providing Message inputs to the TTInputTokenProcess

  • input_network_func (function) – A callback function for providing Message inputs to the TTNetworkManager

  • sim_process (simpy.Process | None) – A reference to the simulated process that this class runs inside of. Mainly used for interrupting the simulated variant on input messages. Defaults to None

class ticktalkpython.ExecuteProcess.TTExecutionContext(sq_name, inputs, input_time_overlap, estimate_runtime=0)

A TTExecutionContext contains all necessary information to invoke and execute an SQ (TTSQExecute) at runtime. This is entirely free of direct memory references, instead relying on consistent naming to identify the SQ to run the provided set of inputs on.

Parameters:
  • sq_name (string) – The name of the SQ

  • inputs (list(TTToken)) – A list of TTTokens that the SQ will operate on.

  • input_time_overlap (TTTime) – The time overlap of the input tokens as determined during synchronization (within TTInputTokenProcess and TTSQSync)

  • estimate_runtime (int) – An estimate of how long it will take to execute an SQ, default as 0

dereference_token_times()

Convert the TTTime```objects within the tag to ``TTTimeSpecs, which are free of memory references that make inter-process and inter-device exchange of tokens less efficient (we wish to avoid serializing the entire clock tree for every single passed token).

rereference_token_times(clocks)

Convert the TTTimeSpec objects within the tokens to TTTime; the TTExecuteProcess` will expect ``TTTimes. To do this conversion, we provide a set of clocks to revert the TTClockSpec within the TTTimeSpec to an actual TTClock

The main purpose of this is to prevent clocks from being copied. This is problematic w.r.t. consistency, the relation between the root-clock and hardware time. It may also increase the size of messages send, thus requiring more bytes be serialized & deserialized