Logic Operators


The MI 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:

  1. Click Download code to download a code file.

  2. Upload the code file to the internal storage as described in Uploading Model Code Files to the Internal Storage.

  3. Drag and drop a ParallelFor operator to the editing canvas.

  4. 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
  5. Select the ParallelFor operator, and reference the loop_args parameter in the Input Parameter item of its parameter configuration.

    ../_images/parallelfor_config_2.png
  6. 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
  7. After saving the pipeline, click Run. You can view the running results of the pipeline after it runs successfully.

    ../_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, 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

  1. 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 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.

  1. Locate the sample pipeline wind-power-forecast and click Pipeline View.

  2. Double-click the Condition for Training operator, you can find a Recursion operator on the sub-canvas.

  3. Double-click the Recursion operator to open its sub-canvas, there is a PythonEx operator used to generate a random number between 1-10.

    ../_images/recursion_config_1.png
  4. 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.

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

    ../_images/recursion_config_3.png