ModellingWebLab / cellmlmanip

CellML loading and model equation manipulation
Other
3 stars 1 forks source link

Misusing booleans in inequalities leads to cryptic error messages #342

Closed MichaelClerx closed 2 years ago

MichaelClerx commented 3 years ago

At the moment, if we have a condition such as 3 > true, we get quite a cryptic error from sympy:

<?xml version="1.0" encoding="UTF-8"?>
<!-- CellML Test Suite. https://github.com/MichaelClerx/cellml-validation -->
<!-- CellML 1.0, C.3.3: The operands of geq must have the same type -->
<model name="boolean_compare_geq_operand_error"
       xmlns="http://www.cellml.org/cellml/1.0#"
       xmlns:cellml="http://www.cellml.org/cellml/1.0#">
  <component name="A">
    <variable name="x" units="dimensionless" />
    <math xmlns="http://www.w3.org/1998/Math/MathML">
      <apply>
        <eq/>
        <ci>x</ci>
        <piecewise>
          <piece>
            <cn cellml:units="dimensionless">1</cn>
            <apply>
              <geq />
              <cn cellml:units="dimensionless">1</cn>
              <true />
            </apply>
          </piece>
          <otherwise>
            <cn cellml:units="dimensionless">0</cn>
          </otherwise>
        </piecewise>
      </apply>
    </math>
  </component>
</model>

leads to

Can only compare inequalities with Expr

In addition, we get these errors for <, >, <=, and >=, but not for == or !=.

So we should probably

  1. Catch these errors and raise something more use friendly, or
  2. Do a detection ourselves so that this doesn't arise (and catch == and != issues in the process)