Logic Operators¶
The AI Pipelines provides the following logical operators:
Condition operator
ParallelFor operator
Recursion operator
Condition Operator¶
The Condition operator is used to implement logical judgments, which can perform different tasks according to the set condition expressions. Currently, it supports single operators such as greater than, less than, greater than or equal to, less than or equal to, equal to, and not equal to.
Expression Format and Description¶
The expression format of the Condition operator is given as follows:
Left operand type | Left operand | Operator | Right operand type | Right operand
Expression elements |
Description |
---|---|
Left operand type |
Two types, i.e. declaration and reference, are available |
Left operand |
When the left operand is of declaration type, the left operand is the inputted fixed value, such as the string abc and the number 15. When the left operand is of reference type, a global parameter or the output of the previous operator can be selected as the left operand. |
Operator |
Expression operators, which support single operators such as greater than, less than, greater than or equal to, less than or equal to, equal to, and not equal to. |
Right operand type |
Two types, i.e. declaration and reference, are available |
Right operand |
When the right operand is of declaration type, the right operand is the inputted fixed value, such as the string abc and the number 15. When the right operand is of reference type, a global parameters or the output of the previous operator can be selected as the right operand. |
Precautions¶
You should try to avoid using invalid conditional expressions, such as
1==1
.It does not currently support compound conditional expressions, such as the combination of multiple conditional expressions with “and” or “or” relations.
Configuration and Samples¶
For more information about the configuration and usage samples of the Condition operator, see the samples given in Developing Pipelines.
ParallelFor Operator¶
The ParallelFor operator is used to implement the loop processing logic and only supports reference type. The elements in the list can be cyclically processed according to the referenced parameters of global list type or the list type parameters outputted by the previous operator.
Input Parameters and Description¶
The input parameter format of the ParallelFor operator is:
List source type | Referenced list | Item name
Parameter |
Description |
---|---|
List source type |
Only the reference type is supported currently. The reference type means that the List Constant or Reference column in the input parameters uses a List type reference. The reference can come from the global parameters of the pipeline or the output parameters of the previous operator. |
Referenced list |
The reference can come from the global parameters of the pipeline or the output parameters of the previous operator. |
Item name |
It is used to point to each element in the List. Its default value is item, but it can also be modified to other names. |
Precautions¶
The item name used in the ParallelFor operator must be consistent with that defined in the ParallelFor logical operator.
The referenced list must be of List type, such as:
["a","b","c"]
or[1,2,3]
.
Configuration and Samples¶
The following sample shows the configuration and usage instructions of the ParallelFor operator:
Select
Download code
to download a code file.Upload the code file to the internal storage as described in Uploading Model Code Files to the Internal Storage.
Drag and drop a ParallelFor operator to the editing canvas.
Select the blank area of the editing canvas, add the
loop_args
parameter in the pipeline parameter configuration, and configure a global variable[{"A_a":1,"B_b":2},{"A_a":10,"B_b":20}]
for the parameters.Select the ParallelFor operator, and reference the
loop_args
parameter in the Input Parameter item of its parameter configuration.Double-select the ParallelFor operator to open its sub-canvas, and drag the print-op operator to the editing canvas for outputting
item.A_a
.After saving the pipeline, select Run. You can view the running results of the pipeline after it runs successfully.
Recursion Operator¶
The Recursion operator can implement the do ... while
function that is similar to that in the programming language. The conditional expression defined in the Recursion operator is the condition for exiting from the loop.
Expression Format and Description¶
The expression format of the Recursion operator is given as follows:
Left operand type | Left operand | Operator | Right operand type | Right operand
Expression elements |
Description |
---|---|
Left operand type |
Two types, i.e. declaration and reference, are available |
Left operand |
When the left operand is of declaration type, the left operand is the inputted fixed value, such as the string abc and the number 15. When the left operand is of reference type, a global parameters or the output of the previous operator can be selected as the left operand. |
Operator |
Expression operators, which support single operators such as greater than, less than, greater than or equal to, less than or equal to, equal to, and not equal to. |
Right operand type |
Two types, i.e. declaration and reference, are available |
Right operand |
When the right operand is of declaration type, the right operand is the inputted fixed value, such as the string abc and the number 15. When the right operand is of reference type, a global parameter or the output of the previous operator can be selected as the right operand. |
Precautions¶
Avoid infinite loop logic, such as invalid conditional expressions. For example, the expression
1==1
will make it impossible to exit the loop when the pipeline is running.When the reference type is selected for the operand, only the output parameters in the sub-canvas of the Recursion operator canvas can be used. Generally, the Recursion operator is used in such a way: the left operand references the output parameter of the sub-canvas operator, and the right operand uses the constant of the declaration type.
It does not currently support compound conditional expressions, such as the combination of multiple conditional expressions with “and” or “or” relations.
Configuration and Samples¶
This section uses the trigger condition in the sample pipeline wind-power-forecast as an example, where the Recursion operator exists only when the generated number is less than 5.
Locate the sample pipeline wind-power-forecast and select Pipeline View.
Double-select the Condition for Training operator, you can find a Recursion operator on the sub-canvas.
Double-select the Recursion operator to open its sub-canvas, there is a PythonEx operator used to generate a random number between 1-10.
Go back to the Recursion operator and check its parameter, you can find that it references the
result_number
value of the PythonEx operator as the expression of the Recursion operator:Generate a number between 1-10.result_number < 5
.After saving the pipeline, select Run. You can view the running results of the pipeline after it runs successfully.