Bad indexing in Matlab export

22 views
Skip to first unread message

Kevin Green

unread,
Nov 26, 2020, 12:34:07 PM11/26/20
to OpenCOR Users
Greetings!

Our group has been playing around with the Grandi model as found here: https://models.physiomeproject.org/e/96/grandi_pasqualini_bers_2010.cellml/view (in particular the grandi_2010_none.cellml variant)

I've been able to use OpenCOR-2020-06-19-Linux to export successfully to C code. However, when I use the MATLAB.xml format, the index of the final entry in the CONSTANTS array gets messed up in the initConsts function. The matlab export produces

    CONSTANTS(:,124) = 0.00000;
...
    CONSTANTS(:,124) =  (1.00000./CONSTANTS(:,111)).*log(CONSTANTS(:,117)./CONSTANTS(:,118));

When the correct variant should be

    CONSTANTS(:,125) = 0.00000;
...
    CONSTANTS(:,124) =  (1.00000./CONSTANTS(:,111)).*log(CONSTANTS(:,117)./CONSTANTS(:,118));

This then propagates into the computeRates function, only ever using CONSTANTS(:,124) and not having a CONSTANTS(:,125) at all.

I'm not sure if this is a problem with OpenCOR (maybe something set to use nconstants-1 for the last entry even in the matlab export?) or with the CellML spec of the model. 

I've been able to manually fix it for this model, but would like some input on whether this is an OpenCOR export or a CellML spec problem. 

Cheers,
Kevin

Alan Garny

unread,
Nov 26, 2020, 5:42:55 PM11/26/20
to OpenCOR Users
Hi Kevin,

Sorry about this issue with the Matlab export. I am going to update the README.txt file in the formats folder. Indeed, there is nothing wrong with the CellML file, but there is one with the Matlab export.

The issue arises from the fact that the K_Concentration component has the following ODE:

    ode(K_i, time) = 0{mM_per_msec};

This equation is fine, but for some reasons the exporter (which is part of the CellML API, a third-party library used by OpenCOR) exports the zero value as a constant of value zero (!!). Then, the Matlab-specific exporter somehow gets confused due to 0- vs. 1-based indexing, resulting in the constant variable for that zero value to be "computed" twice (!!).

As I said, all of this is done through the CellML API and it's not being maintained anymore. Instead, we are nowadays working on libCellMLits replacement. Unfortunately, it's not quite ready so we can't yet drop the CellML API, but it will at some point.

In the meantime, I would recommend deleting the ODE. It's of no use as it stands.

Cheers, Alan.

P.S.: for what it is worth, libCellML doesn't export the zero value as a constant of value zero.

From: openco...@googlegroups.com <openco...@googlegroups.com> on behalf of Kevin Green <kevin.ric...@gmail.com>
Sent: 27 November 2020 6:34 AM
To: OpenCOR Users <openco...@googlegroups.com>
Subject: [OpenCOR Users] Bad indexing in Matlab export
 
--
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/b9549f91-f823-43f4-8d8d-d41d3882a1e3n%40googlegroups.com.

Kevin Green

unread,
Nov 27, 2020, 9:20:38 AM11/27/20
to OpenCOR Users
Thanks very much for the quick response Alan. Follow up question: Do you have advice on how to get a better feel for the capabilities of libCellML? The documentation is currently quite sparse, and there are broken links floating around. It seems quite unapproachable to me right now, so even just pointing me to a good starting point for its usage would be very helpful.

Alan Garny

unread,
Nov 29, 2020, 6:34:33 PM11/29/20
to OpenCOR Users
Hi Kevin,

We have some preliminary user documentation available at https://libcellml-tutorials.readthedocs.io/en/develop/. So, please feel free to have a look through it and if you find anything wrong/missing/etc. then please create an issue at https://github.com/kerimoyle/libcellml-tutorials/issues.

Otherwise, be aware that libCellML only works with CellML 2.0 files while, at this stage, 99.9% of the models on the Physiome Model Repository are CellML 1.0/1.1 files. So, to use libCellML, you will first need to convert your model to CellML 2.0. This can be done using a non-official feature of OpenCOR (which I probably ought to release at some point!) or using an XSL transformation (see https://github.com/cellml/cellml1to2). Finally, libCellML can currently generate C and Python code, but not yet MATLAB code.

HTH, Alan.

Sent: 28 November 2020 3:20 AM
To: OpenCOR Users <openco...@googlegroups.com>
Subject: Re: [OpenCOR Users] Bad indexing in Matlab export
 
Reply all
Reply to author
Forward
0 new messages