cellml/libcellml

Unit Warning bug when using millis_per_s and abs

Opened this issue ยท 11 comments

I get the following warning message:

image

when analysing the following model:

SN_to_cAMP.zip

It's saying there is a milliV_per_V_1 unit, which shouldn't be there.

I tried to recreate the warning with a simpler model here:

test_units.zip

But it doesn't have the same warning, so something strange is going on.

Don't worry about the other warnings, I need to go through and fix them.

Changing

tau_m*0.001{s_per_millis}

to

tau_m/1000{millis_per_s}

fixes the warning, but we should be able to do both.

Thanks @FinbarArgus, I will have a look at it sometime next week. (Otherwise, don't put screenshots of messages. Just copy/paste the message... :))

Okay, will do, sorry.

Also, to add to this... Only one type of error/warning gets shown at once, i.e. my model currently has an error where something is uninitialised, which I am trying to determine. However, only the units warnings are being shown.

As an example of only outputting one type of warning, if I change the following in the above model:

var i_NaCa_ter: nanoA {pub: out};

to

var i_NaCa_ter: nanoA;

I only get the following warning, without the many unit warnings

Recorded 1 issues:
Issue 0 is an ERROR:
Description: Variable 'i_NaCa_ter' in component 'SN_module' has no interface type set. The interface type required is 'public'.
See section 3.10.8 in the CellML specification.
More information is available at: https://cellml-specification.readthedocs.io/en/latest/reference/formal_and_informative/specC10.html?issue=MAP_VARIABLES_AVAILABLE_INTERFACE
Stored item type: variable

As an example of only outputting one type of warning, if I change the following in the above model:

var i_NaCa_ter: nanoA {pub: out};

to

var i_NaCa_ter: nanoA;

I only get the following warning, without the many unit warnings

Yes, I think that's a pure CellML validation issue. Unit checking is done by the analyser only if there are no CellML validation issues.

Okay, also, after fixing the unit issues (hacky fix changing the equations, not fixing this original issue), I still don't get any error messages detailing where my underconstraint is happening. Do you know of any ways to use libcellml to help debug what variable is underconstrained. The message that I get in opencor is:

Error: the model is underconstrained (i.e. some variables need to be initialised or computed).

Okay, also, after fixing the unit issues (hacky fix changing the equations, not fixing this original issue), I still don't get any error messages detailing where my underconstraint is happening. Do you know of any ways to use libcellml to help debug what variable is underconstrained. The message that I get in opencor is:

Error: the model is underconstrained (i.e. some variables need to be initialised or computed).

Yeah, you won't get much help from OpenCOR (well, the CellML API in this instance). As for libCellML, I guess I will need to have a proper look at your issue before I can comment further. Early next week. :) (I am working on getting libOpenCOR to run some ODE models from JavaScript, i.e. from the Web...)

Finally found it!

I had
var tau_c: millis {pub: in};
tau_c = ...

instead of

var tau_c: millis {pub: out};
tau_c = ...

Which is interesting, because I would have thought this would be an overconstrained issue, not underconstrained... Either way it would be very useful to have this kind of error detected by the analyser.

No rush for the above unit issues, and thanks! Good luck with libOpenCOR!

I have tried out the SN_to_cAMP model given above and I have not been able to reproduce an error with units. Here is a shortened output of the errors reported by the analyser for the model:

Validation errors:  0
Analyser errors: 171
[  0] - The type of variable 'stim_flag_SN_stim' in component 'parameters' is unknown.
[  1] - The type of variable 't_start_SN_stim' in component 'parameters' is unknown.
[  2] - The type of variable 't_end_SN_stim' in component 'parameters' is unknown.
...
[169] - The type of variable 'tau_hIP3' in component 'SN_module' is unknown.
[170] - The type of variable 'Q_2' in component 'SN_module' is unknown.

I used the latest developer version of libCellML to execute this script. What version did you use to get the units error?

I'm using this version

farg967:~/software/OpenCOR-0-7-1-Linux/python/bin$ ./pip freeze | grep libcellml
libcellml==0.5.0

And this is how I check for errors:

https://github.com/FinbarArgus/circulatory_autogen/blob/7b0b6fb6e5a60e40fd65448dada09553f4d56bf4/src/generators/CVSCellMLGenerator.py#L74-L93

I have tried out the SN_to_cAMP model given above and I have not been able to reproduce an error with units. Here is a shortened output of the errors reported by the analyser for the model:

@hsorby, I think you forgot to flatten @FinbarArgus' model before analysing it.

Anyway, I have just tried the following using my copy of libCellML (which is up to date with regards to the main codebase):

TEST(Analyser, finbar)
{
    auto parser = libcellml::Parser::create(false);
    auto model = parser->parseModel(fileContents("analyser/SN_to_cAMP/SN_to_cAMP.cellml"));

    std::cout << "---[ANALYSER ISSUES]---[BEGIN]" << std::endl;
    printIssues(parser);
    std::cout << "---[ANALYSER ISSUES]---[END]" << std::endl;

    auto importer = libcellml::Importer::create(false);

    importer->resolveImports(model, resourcePath("analyser/SN_to_cAMP"));

    std::cout << "---[IMPORTER ISSUES]---[BEGIN]" << std::endl;
    printIssues(importer);
    std::cout << "---[IMPORTER ISSUES]---[END]" << std::endl;

    auto analyser = libcellml::Analyser::create();

    model = importer->flattenModel(model);
    analyser->analyseModel(model);

    std::cout << "---[ANALYSER ISSUES]---[BEGIN]" << std::endl;
    printIssues(analyser);
    std::cout << "---[ANALYSER ISSUES]---[END]" << std::endl;
}

and here is the output I got:

1: [ RUN      ] Analyser.finbar
1: ---[PARSER ISSUES]---[BEGIN]
1: Message 1:
1: Given model is a CellML 1.1 model, the parser will try to represent this model in CellML 2.0.
1: ---[PARSER ISSUES]---[END]
1: ---[IMPORTER ISSUES]---[BEGIN]
1: Message 1:
1: Given model is a CellML 1.1 model, the parser will try to represent this model in CellML 2.0.
1: Message 2:
1: Given model is a CellML 1.1 model, the parser will try to represent this model in CellML 2.0.
1: Message 3:
1: Given model is a CellML 1.1 model, the parser will try to represent this model in CellML 2.0.
1: ---[IMPORTER ISSUES]---[END]
1: ---[ANALYSER ISSUES]---[BEGIN]
1: Warning 1:
1: The units in 'ek1 = R*T/F*ln(ko/ki)*1000.0' in component 'SN_module' are not equivalent. 'ek1' is in 'milliV' (i.e. '10^-3 x ampere^-1 x kilogram x metre^2 x second^-3') while 'R*T/F*ln(ko/ki)*1000.0' is in 'C_per_mol^-1 x J_per_mol_K x kelvin x s_per_millis' (i.e. '10^3 x ampere^-1 x kilogram x metre^2 x second^-3').
1: Warning 2:
1: The units in 'ena1 = R*T/F*ln(Nao/Nai)*1000.0' in component 'SN_module' are not equivalent. 'ena1' is in 'milliV' (i.e. '10^-3 x ampere^-1 x kilogram x metre^2 x second^-3') while 'R*T/F*ln(Nao/Nai)*1000.0' is in 'C_per_mol^-1 x J_per_mol_K x kelvin x s_per_millis' (i.e. '10^3 x ampere^-1 x kilogram x metre^2 x second^-3').
1: Warning 3:
1: The units in 'j_SERCA = k_SERCA*(pow(Ca_ter/K_mf, H_SERCA)-pow(Ca_ER/K_mr, H_SERCA))/(1.0+pow(Ca_ter/K_mf, H_SERCA)+pow(Ca_ER/K_mr, H_SERCA))' in component 'SN_module' may not be equivalent. 'j_SERCA' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while '1.0+pow(Ca_ter/K_mf, H_SERCA)+pow(Ca_ER/K_mr, H_SERCA)' may result in 'k_SERCA*(pow(Ca_ter/K_mf, H_SERCA)-pow(Ca_ER/K_mr, H_SERCA))/(1.0+pow(Ca_ter/K_mf, H_SERCA)+pow(Ca_ER/K_mr, H_SERCA))' having different units.
1: Warning 4:
1: The units in 'k_oERCa*pow(Ca_ter, 2.0)*Rstate-k_om*Ca_ter*Ostate' in 'k_oERCa*pow(Ca_ter, 2.0)*Rstate-k_om*Ca_ter*Ostate-(k_iERCa*pow(Ca_ter, 2.0)*Ostate-k_im*Istate)' in equation 'dOstate/dt = k_oERCa*pow(Ca_ter, 2.0)*Rstate-k_om*Ca_ter*Ostate-(k_iERCa*pow(Ca_ter, 2.0)*Ostate-k_im*Istate)' in component 'SN_module' are not equivalent. 'k_oERCa*pow(Ca_ter, 2.0)*Rstate' is in 'mol_per_m3^2 x per_millimolar2_s_2' (i.e. 'second^-1') while 'k_om*Ca_ter*Ostate' is in 'Hz x mol_per_m3' (i.e. 'metre^-3 x mole x second^-1').
1: Warning 5:
1: The units in 'j_Ca_N_ter = -iCa_N_ter/(2.0*F*Vol_ter)*1.0e9' in component 'SN_module' are not equivalent. 'j_Ca_N_ter' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while '-iCa_N_ter/(2.0*F*Vol_ter)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 6:
1: The units in 'j_NaCa_ter = i_NaCa_ter/(F*Vol_ter)*1.0e9' in component 'SN_module' are not equivalent. 'j_NaCa_ter' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'i_NaCa_ter/(F*Vol_ter)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 7:
1: The units in 'j_Ca_N_soma = -iCa_N_soma/(2.0*F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_Ca_N_soma' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while '-iCa_N_soma/(2.0*F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 8:
1: The units in 'j_NaCa_soma = i_NaCa_soma/(F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_NaCa_soma' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'i_NaCa_soma/(F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 9:
1: The units in 'j_Na_N = iNa_N/(F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_Na_N' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'iNa_N/(F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 10:
1: The units in 'j_kA = iA/(F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_kA' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'iA/(F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 11:
1: The units in 'j_kv = ikv/(F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_kv' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'ikv/(F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 12:
1: The units in 'j_kCa = ikCa/(F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_kCa' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'ikCa/(F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 13:
1: The units in 'j_kM = iM/(F*Vol_soma)*1.0e9' in component 'SN_module' are not equivalent. 'j_kM' is in 'millimolar_per_s_2' (i.e. 'metre^-3 x mole x second^-1') while 'iM/(F*Vol_soma)*1.0e9' is in 'C_per_mol^-1 x microm3_2^-1 x nC_per_s' (i.e. '10^9 x metre^-3 x mole x second^-1').
1: Warning 14:
1: The units in 'koff*B1-5.0*kon*Ca_ter*B0' in equation 'dB0/dt = koff*B1-5.0*kon*Ca_ter*B0' in component 'SN_module' are not equivalent. 'koff*B1' is in 'Hz' (i.e. 'second^-1') while '5.0*kon*Ca_ter*B0' is in 'mol_per_m3 x per_milliM_s' (i.e. '10^3 x metre^-3 x second^-1').
1: Warning 15:
1: The units in '5.0*kon*Ca_ter*B0+2.0*koff*B2*pow(b, 1.0)' in '5.0*kon*Ca_ter*B0+2.0*koff*B2*pow(b, 1.0)-(koff*pow(b, 0.0)+4.0*kon*Ca_ter)*B1' in equation 'dB1/dt = 5.0*kon*Ca_ter*B0+2.0*koff*B2*pow(b, 1.0)-(koff*pow(b, 0.0)+4.0*kon*Ca_ter)*B1' in component 'SN_module' are not equivalent. '5.0*kon*Ca_ter*B0' is in 'mol_per_m3 x per_milliM_s' (i.e. '10^3 x metre^-3 x second^-1') while '2.0*koff*B2*pow(b, 1.0)' is in 'Hz x picoF' (i.e. '10^-12 x ampere^2 x kilogram^-1 x metre^-2 x second^3').
1: Warning 16:
1: The units in '4.0*kon*Ca_ter*B1+3.0*koff*B3*pow(b, 2.0)' in '4.0*kon*Ca_ter*B1+3.0*koff*B3*pow(b, 2.0)-(2.0*koff*pow(b, 1.0)+3.0*kon*Ca_ter)*B2' in equation 'dB2/dt = 4.0*kon*Ca_ter*B1+3.0*koff*B3*pow(b, 2.0)-(2.0*koff*pow(b, 1.0)+3.0*kon*Ca_ter)*B2' in component 'SN_module' are not equivalent. '4.0*kon*Ca_ter*B1' is in 'mol_per_m3 x per_milliM_s' (i.e. '10^3 x metre^-3 x second^-1') while '3.0*koff*B3*pow(b, 2.0)' is in 'Hz x picoF^2' (i.e. '10^-24 x ampere^4 x kilogram^-2 x metre^-4 x second^7').
1: Warning 17:
1: The units in '3.0*kon*Ca_ter*B2+4.0*koff*B4*pow(b, 3.0)' in '3.0*kon*Ca_ter*B2+4.0*koff*B4*pow(b, 3.0)-(3.0*koff*pow(b, 2.0)+2.0*kon*Ca_ter)*B3' in equation 'dB3/dt = 3.0*kon*Ca_ter*B2+4.0*koff*B4*pow(b, 3.0)-(3.0*koff*pow(b, 2.0)+2.0*kon*Ca_ter)*B3' in component 'SN_module' are not equivalent. '3.0*kon*Ca_ter*B2' is in 'mol_per_m3 x per_milliM_s' (i.e. '10^3 x metre^-3 x second^-1') while '4.0*koff*B4*pow(b, 3.0)' is in 'Hz x picoF^3' (i.e. '10^-36 x ampere^6 x kilogram^-3 x metre^-6 x second^11').
1: Warning 18:
1: The units in '2.0*kon*Ca_ter*B3+5.0*koff*B5*pow(b, 4.0)' in '2.0*kon*Ca_ter*B3+5.0*koff*B5*pow(b, 4.0)-(4.0*koff*pow(b, 3.0)+kon*Ca_ter)*B4' in equation 'dB4/dt = 2.0*kon*Ca_ter*B3+5.0*koff*B5*pow(b, 4.0)-(4.0*koff*pow(b, 3.0)+kon*Ca_ter)*B4' in component 'SN_module' are not equivalent. '2.0*kon*Ca_ter*B3' is in 'mol_per_m3 x per_milliM_s' (i.e. '10^3 x metre^-3 x second^-1') while '5.0*koff*B5*pow(b, 4.0)' is in 'Hz x picoF^4' (i.e. '10^-48 x ampere^8 x kilogram^-4 x metre^-8 x second^15').
1: Warning 19:
1: The units in 'kon*Ca_ter*B4-5.0*koff*pow(b, 4.0)*B5' in equation 'dB5/dt = kon*Ca_ter*B4-5.0*koff*pow(b, 4.0)*B5' in component 'SN_module' are not equivalent. 'kon*Ca_ter*B4' is in 'mol_per_m3 x per_milliM_s' (i.e. '10^3 x metre^-3 x second^-1') while '5.0*koff*pow(b, 4.0)*B5' is in 'Hz x picoF^4' (i.e. '10^-48 x ampere^8 x kilogram^-4 x metre^-8 x second^15').
1: Warning 20:
1: The units in 'E = gamma*B5' in component 'SN_module' are not equivalent. 'E' is 'dimensionless' while 'gamma*B5' is in 'Hz' (i.e. 'second^-1').
1: Warning 21:
1: The units in '1.0e-1*Ca_ter-10.0*(NE-NE_init)' in equation 'dNE/dt = 1.0e-1*Ca_ter-10.0*(NE-NE_init)' in component 'SN_module' are not equivalent. '1.0e-1*Ca_ter' is in 'mol_per_m3' (i.e. 'metre^-3 x mole') while '10.0*(NE-NE_init)' is 'dimensionless'.
1: ---[ANALYSER ISSUES]---[END]
1: [       OK ] Analyser.finbar (1370 ms)

So, as far as I can tell, there is no warning in the dm/dt equation for me, not to mention that I am getting fewer issues (21 vs. 41) than @FinbarArgus. So, I get the feeling that @FinbarArgus' issue has been fixed since we released libCellML 0.5.

I can confirm @agarny's work, for libCellML 0.5.0 I get 41 warnings from analysing the flattened model, but with the latest development codebase from the main branch I get 21 warnings. I think the original issue is because of a bug found (and subsequently fixed) to do with imported units not being recognised as equivalent.