WSE Loops Module
WSE Loops are implemented as context managers. Portions of the computation graph that exist within the context manager are tracked so that the RPC seqeunce can be managed to enact a loop. It is important to remember that this is not a python loop but a computational graph element that is executed on the WSE at runtime, not at script execution time.
- class WFA.WSE_Loops.WSE_For_Loop(name, iterations, conditional=True)
A context manager to manage a for loop execution.
The following will execute the code in the loop 100 times
# Code before loop with WSE_For_Loop('time_loop', 100) as fl: # Code in loop # Code after loop
- Parameters:
name (str) – A unique name for the loop
iterations (int) – The number of iterations to execute.
conditional (bool, optional) – Enable the loop. The default is True.
- Return type:
None.
- conditional_exit(tolerance, scalar)
Allows for the conditional exit from a for loop based on a tolerance and scalar based on a defined tolerance and scalar.
In the example below, a WSE_Global_Scalar is populated from a reduce max. The reduced value is then compared to 10. If the value is less than ten, the loop will exit and not do anything after the graph within the WSE_for_Loop context manager.
exit_criteria = WSE_Global_Scalar(value=0.01) with WSE_For_Loop('time_loop', 100) as fl: # Do something my_wse_array._reduce_max_2_control(exit_criteria) fl.conditional_exit(10,exit_criteria) # Do more things
- Parameters:
tolerance (float) – The tolerance to stop iterating.
scalar (WSE_Global_Scalar) – The integer handle to the scalar memory position in the controller where value is stored to compare to tolerance.
- Return type:
None.
- conditional_pause()
Sets a pause point in the program so that the host can interact with data. On the WSE, a reduction is enacted to ensure all workers are at the same program state. A control bit is flipped into “pause” on the controller. Program execution stopps until the host unflipps the pause bit. Currently, the program pause parameters are controlled from the launch script so that data can be extracted from the WSE and saved.
with WSE_For_Loop('time_loop', 100) as fl: # Do something fl.conditional_pause() # Do more things
- Return type:
None.
- class WFA.WSE_Loops.WSE_While_Loop(name, tolerance, scalar, conditional=True)
A context manager to manage a while loop execution.
The following will execute the code in the loop 10 times.
exit_scalar = WSE_Global_Scalar(value=10.0) # Code before loop with WSE_While_Loop('time_loop', 0.0, exit_scalar) as wl: exit_scalar[0] = exit_scalar - 1 # Code in loop # Code after loop
- Parameters:
name (str) – A unique name for the loop.
tolerance (float) – The tolerance to stop iterating.
scalar (WSE_Global_Scalar) – Global Scalar to compare to tolerance for loop exit.
conditional (bool, optional) – Enable the loop. The default is True.
- Return type:
None.