Logic Operators


The MI Pipelines provides the following logical operators:

  • Condition operator
  • ParallelFor operator
  • Recursion operator
  • OnExit (an exit operator, which is not included in the logical operator list, and can be set in the parameter configuration for the pipeline editing canvas)

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, the global parameters of the pipeline 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, the global parameters of the pipeline 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 Usage 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 Usage Samples

The following sample shows the configuration and usage instructions of the ParallelFor operator:

  1. Drag and drop the ParallelFor operator to the editing canvas.

  2. Click 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.

    ../_images/parallelfor_config_1.png
  3. Select the ParallelFor operator, and reference the loop_args parameter in the Input Parameter item of its parameter configuration.

    ../_images/parallelfor_config_2.png
  4. Double-click the ParallelFor operator to open its sub-canvas, and drag the print-op operator to the editing canvas for outputting item.A_a.

    ../_images/parallelfor_config_3.png
  5. After saving the pipeline, click Run. You can view the running results of the pipeline after it runs succeessfully.

    ../_images/parallelfor_config_4.png

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, the global parameters of the pipeline 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, the global parameters of the pipeline or the output of the previous operator can be selected as the right operand.

Precautions

  1. You should try to 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.
  2. 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.
  3. It does not currently support compound conditional expressions, such as the combination of multiple conditional expressions with “and” or “or” relations.

Configuration and Usage Samples

In this section, the “Coin Toss” scenario is taken as an example (where, if the result is the upside of the coin, the coin will be tossed unceasingly until the result is the backside of the coin) to introduce the configuration and usage instructions of the Recursion operator:

  1. Drag and drop the Recursion operator to the editing canvas.

  2. Double-click the Recursion operator to open its sub-canvas, add a flip-coin-op operator, and connect a print-op operator to print the output value of the flip-coin-op operator.

    ../_images/recursion_config_1.png
  3. Select the Recursion operator, and reference the output value of the flip-coin-op operator as the expression of the Recursion operator: flip-coin-op.output == tails.

    ../_images/recursion_config_2.png
  4. Connect a print-op operator to the Recursion operator, and the Finish will be outputted after the recursion.

    ../_images/recursion_config_3.png
  5. After saving the pipeline, click Run. You can view the running results of the pipeline after it runs succeessfully.

    ../_images/recursion_config_4.png

OnExit Operator

Exit operator, which is not included in the logical operator list, and can be set in the parameter configuration for the pipeline editing canvas. In this section, the following sample is take to introduce the exit processing logic:

  1. Drag and drop the custom operator gcs-download-op onto the editing canvas, and use the URL gs://ml-pipeline-playground/shakespeare1.txt in its Input Parameter configuration item.

    ../_images/onexit_config_1.png
  2. Connect a print-op operator to the gcs-download-op operator to print the output value of the gcs-download-op operator.

    ../_images/onexit_config_2.png
  3. Add another print-op operator as an exit processing operator.

    ../_images/onexit_config_3.png
  4. After saving the pipeline, click Run. You can view the running results of the pipeline after it runs succeessfully.

    ../_images/onexit_config_4.png