cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
17 stars 21 forks source link

Where should mismatched units in equations be tested? #481

Open kerimoyle opened 4 years ago

kerimoyle commented 4 years ago

Related to #459 ... I can now generate (wahoo!) garbage code (bummer!) ... see:

The CellML (which passes validator and generator checks):

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="quickstart_model" id="quickstart">
  <component name="i_am_a_component" id="my_component_id">
    <variable name="a" units="metre" interface="public_and_private"/>
    <variable name="b" units="dimensionless" initial_value="20" interface="public_and_private"/>
    <variable name="c" units="second" initial_value="20"/>
    <math xmlns="http://www.w3.org/1998/Math/MathML">
                <apply><eq/>
                    <ci>a</ci>
                    <apply><plus/>
                        <ci>b</ci>
                        <ci>c</ci>
                    </apply>
                </apply>
            </math>
  </component>
</model>

Happily creates these output files:
Archive.zip

Either we need to change the spec to say that MathML must be dimensionally consistent (in which case we can then check in the Validator) or the Generator needs to check this... thoughts?

agarny commented 4 years ago

This is something that @hsorby quickly discussed last week after he came across an issue with OpenCOR (well, the CellML API).

The validation as it stands is correct, i.e. it validates a model against the CellML specifications. So, there is nothing wrong with your CellML code. However, when it comes to code generation, we need to make sure that the CellML code corresponds to a runnable model. In your example, this is not the case and I would expect libCellML's generator to return an error message telling you that much.

In summary, there are two levels of "validation" for me:

  1. to ensure that it respects the CellML specifications (i.e. what we currently have); and
  2. to ensure that it corresponds to a model that can be run.

In order to generate code, we need both levels of "validation" to pass.