debug_print
Description
The tik.tikdb object defines the debug_print statement to facilitate data printing at operator run time. When the debugger executes this line of code, it evaluates the expression and prints the result on the screen.
This API applies only to the scenario where start_debug is enabled in the simulation environment.
Prototype
def debug_print(expr)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
expr |
Input |
A valid Python expression in string format. The supported variables are Scalar, Expr, ScalarArray, and Tensor in the current scope of TIK DSL. Scalar and Expr are evaluated and replaced with values of the float or int type in Python. Each element in ScalarArray is evaluated and replaced, which will be returned in a list. A Tensor is replaced with numpy.ndarray equivalent to the Tensor, with consistent shape, type, and data of the Tensor. |
Applicability
Returns
None
Restrictions
- The debug_print function prints the variables defined by TIK. The variables are enclosed in single or double quotation marks. You can directly pass the defined variable name into them. For example:
tensor = tik_instance.Tensor(...)
tik_instance.tikdb.debug_print("tensor")
- The string printed by debug_print is enclosed in single quotation marks ('') and then double quotation marks (""). For example:
tik_instance.tikdb.debug_print('"printed string"')
- The debug_print function prints the combination of strings and TIK variables. Multiple combinations are separated by commas (,). For example:
tik_instance.tikdb.debug_print('"string"+str(variable name),"string"')
- When the to-be-printed TIK variable appears as a class attribute, if the attribute is assigned twice and is written in code 1 style, getattr(self,'tensor') will point to tensor2 when debug_print parses the class attribute at run time, resulting in a wrong printed result. It is advised not to assign values to class attributes to be printed repeatedly or follow the code 2 writing style.
# Code 1: printing result not as expected
self.tensor = tik_instance.Tensor(...) # tensor1
tik_instance.tikdb.debug_print("self.tensor")
self.tensor = tik_instance.Tensor(...) # tensor2
# Code 2: printing result as expected
self.tensor = tik_instance.Tensor(...) # tensor1
tmp = self.tensor
tik_instance.tikdb.debug_print("tmp")
self.tensor = tik_instance.Tensor(...) # tensor2
- The debug_print() statement must be defined in the operator code. After the operator program is called, tik_instance is returned. After the start_debug() call, the debug_print() function can be correctly executed to print the expected output.
Example
tik_instance.tikdb.debug_print('characters')