deepmodeling/dflow

bug(conditional expression): always false when running `test_conditional_outputs.py`

saltball opened this issue · 0 comments

Checklist

  • Checked the syntax is legal within dflow.
  • Tested using the latest version. (pydflow=1.2.1)

Summary

What happened/what you expected to happen?

When I run dflow with conditional expressions, such as examples/test_conditional_outputs.py, it always output with false conditions.

What version are you running?

pydflow=1.2.1

Diagnostics

Paste the smallest python script that reproduces the bug

just examples/test_conditional_outputs.py

Maybe a solution

dflow generate the conditional expression with if_expression as in examples/test_conditional_outputs.py
(https://github.com/deepmodeling/dflow/blob/master/examples/test_conditional_outputs.py)

steps.outputs.parameters["msg"].value_from_expression = if_expression(
_if=random_step.outputs.parameters["is_head"],
_then=random_step.outputs.parameters["msg1"],
_else=random_step.outputs.parameters["msg2"])
steps.outputs.artifacts["res"].from_expression = if_expression(
_if=random_step.outputs.parameters["is_head"],
_then=random_step.outputs.artifacts["foo"],
_else=random_step.outputs.artifacts["bar"])

It seems src/dflow/io.py translate the expression to a string for argo api with

_if = "%s == true" % self._if.expr

However, argo api final submit the job with fromExpression as :

  artifacts:
    - name: res
      fromExpression: >-
        steps['random'].outputs.parameters['is_head'] == true ?
        steps['random'].outputs.artifacts['foo'] :
        steps['random'].outputs.artifacts['bar']

In where steps['random'].outputs.parameters['is_head'] == true compare string 'true' with boolean true, and always return false.

Thus I change

_if = "%s == true" % self._if.expr

to quoted

            _if = "%s == 'true'" % self._if.expr

. Then no more bugs.

A simple test reproduce

set Line60 and Line65 in examples/test_conditional_outputs.py with

        _if="'true'==true",

or

        _if="'true'=='true'",

to skip expr transferring. Running dflow will give totally different results.

But I'm not sure is there any further side-effect of this expression.