Unit verification in OpenCOR

19 views
Skip to first unread message

Karim RAQBI

unread,
Apr 9, 2024, 5:11:06 AM4/9/24
to OpenCOR Users
Hello,
First of all, if I am submiting my question in the wrong place, could you please tell me where I should ask?

I am going through the tutorial of OpenCOR to try to reproduce a model published in an article.
Going through this tutorial (https://tutorial-on-cellml-opencor-and-pmr.readthedocs.io/en/latest/cellml_units.html), I was wondering if OpenCOR allows unit verifications and if so, where can it be found?

I tried this example :
```
def model first_order_model as

    def unit millisec as
        unit second {pref: milli};
    enddef;
    def unit per_millisec as
        unit second {pref: milli, expo: -1};
     enddef;
    def unit millivolt as
        unit volt {pref: milli};
    enddef;
    def unit microA_per_cm2 as
        unit ampere {pref: micro};
        unit metre {pref: centi, expo: -2};
    enddef;
    def unit milliS_per_cm2 as
        unit siemens {pref: milli};
        unit metre {pref: centi, expo: -2};
    enddef;

    def comp ion_channel as
        var V: millivolt {init: 0};
        var t: millisec {init: 0};
        var y: dimensionless {init: 0};
        var E_y: millivolt {init: -85};
        var i_y: microA_per_cm2;
        var g_y: milliS_per_cm2 {init: 36};
        var gamma: dimensionless {init: 4};
        var alpha_y: per_millisec {init: 1};
        var beta_y: per_millisec {init: 2};

        ode(y, t) = alpha_y*(1{dimensionless}-y)-beta_y*y;

        i_y = g_y*pow(y, gamma)*(V-E_y);
     enddef;

enddef;
```

And switching the unit of alpha_y from per_millisec to dimensionless did not return an error and I was still able to run the simulation without warning.
Cheers,
--
Karim

Alan Garny

unread,
Apr 9, 2024, 5:40:41 AM4/9/24
to OpenCOR Users
Hi Karim,

Yes, OpenCOR (through a third-party library that it uses to handle CellML files) can tell you whether a model's units are consistent. However, for this, you need to:
  1. switch to the Raw CellML​ view (on the right hand side of the editor);
  2. right click on the editor and click on the CellML Validation​ menu item.

If you changed the unit of alpha_y​ from per_millisec​ to dimensionless​ then you should see the following two messages:

[Warning] [32:18] MathML equals element has inconsistent units between the sides.
[Warning] [41:22] Expected all arguments to operator "minus" to have the same units.

I agree, those messages are not super useful, but they at least highlight an issue with units. I also agree that it would be much better if this check could be done from the CellML Text​ view, but... yeah, that's the way it is unfortunately (there are some technical limitations unfortunately).

Otherwise, although the model is clearly not sound anymore (when it comes to units), CellML allows a model to have inconsistent units. This is to make a model developer's life easier when developing a model otherwise it could very quickly become very tedious (talking from experience here). Still, needless to say that you should always ensure that units are consistent before publishing a model!

HTH, Alan.

From: openco...@googlegroups.com <openco...@googlegroups.com> on behalf of Karim RAQBI <karim...@gmail.com>
Sent: Tuesday, 9 April 2024 9:11 pm
To: OpenCOR Users <openco...@googlegroups.com>
Subject: [OpenCOR Users] Unit verification in OpenCOR
 
--
You received this message because you are subscribed to the Google Groups "OpenCOR Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opencor-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/opencor-users/bb5adb52-8fbf-4ab0-bc1a-edc6b4619552n%40googlegroups.com.

Karim RAQBI

unread,
Apr 9, 2024, 5:58:56 AM4/9/24
to OpenCOR Users
Thank you for your answer. It was quite helpful.
It would be great if such advice were to be added in the tutorial or the documentation for future users (although I might have missed it.)

Best,
--
Karim

Alan Garny

unread,
Apr 9, 2024, 9:09:54 PM4/9/24
to OpenCOR Users
Hi Karim,

Just to let you know that the tutorial has been updated to account for your suggestion. It just needs to be reviewed by my colleagues before it gets pushed to Read the Docs.

Cheers, Alan.

Sent: Tuesday, 9 April 2024 9:58 pm
To: OpenCOR Users <openco...@googlegroups.com>
Subject: Re: [OpenCOR Users] Unit verification in OpenCOR
 
Reply all
Reply to author
Forward
0 new messages