ModellingWebLab / project_issues

An issues-only repository for issues that cut across multiple repositories
1 stars 0 forks source link

Create replacement for PyCml #12

Closed jonc125 closed 5 years ago

jonc125 commented 6 years ago

The existing code is unmaintainable, and based on XML libraries (Amara) that haven't been supported in years. Converting it to support Python 3 would probably require a rewrite anyway!

Options:

What I’d really like to see in this space is a collection of small well-tested Python packages that work together. Where the components should be split is an open question. Some aspects are:

  1. Core equation representation – SymPy plus variable RDF annotations & units plus extra info needed to track ODEs & DAEs, …
  2. Core code generation support – perhaps using a templating library like Jinja to tidy up ‘boilerplate’
  3. Specific parsers: CellML, Melodee
  4. Specific code generators: Web Lab, Chaste, Cardioid, ...
  5. Web Lab protocol support – extensive model manipulation, Cython code generation for solving with CVODE in the context of a protocol
    • This is basically what protocol.py currently does, using more low-level operations from processors.py. We need to consider how to split these up. Probably this middle layer becomes the equivalent of processors.py, supporting generic manipulations while tracking annotations, and the protocol-specific bits go into https://github.com/ModellingWebLab/weblab-fc - i.e. parsing the protocol to figure out what changes to make.
  6. Other kinds of model analysis, e.g. lookup tables, (generalised) Rush Larsen – providing extra info to support specialised code generators
mirams commented 6 years ago

I'm not sure what all the extra bits are! Various things related to removing singularities, analytic solutions where appropriate, perhaps even DAE systems for Markov ion currents etc.??

MichaelClerx commented 6 years ago

I think the various optimisations etc. that are available via PyCML at the moment and used in Chaste

MichaelClerx commented 6 years ago

Just updated the description a bit. Still a few questions:

  1. Is it feasible (or a good idea) to only implement CellML 2.0 parsing and handle older versions via an XSLT transform?
  2. Are we planning to support imports? (and if yes then how)
jonc125 commented 6 years ago

Andre & I did a bit of work on an XSLT transform to generate test cases for libCellML, so we could use that. But then you need an XSLT processor installed to handle any existing model, which isn't ideal! I don't think there's a pure Python one available... you have to use lxml probably.

Haven't thought much about imports. If they're local you can do them by including all files within the model repo - just the same as you'd package it up in a COMBINE Archive. If not you have to worry about whether the model definition might change without you noticing, which we probably want to disallow!

jonc125 commented 6 years ago

Email thread re libCellML:

Hi all,

I would indeed like OpenCOR to generate various formats such as C/C++, Fortran, MATLAB, etc., but also Word and LaTeX.

I am currently thinking of adding Andrew Miller's idea (of having a file that specifies the target format) to the way I did code generation in COR. I reckon this should be possible using LLVM/Clang. On the CellML side of things, I would indeed like to use libCellML, but that will likely require using SymEngine. So, I will have to see how that goes since SymEngine still doesn't have a MathML printer/parser.

Once I have got all of that working, I will focus on DAE models. I haven't had time to look properly at DAEs until now, so OpenCOR can only run basic DAE models at the moment.

Alan

From: David Nickerson d.nickerson@auckland.ac.nz Date: Friday 13 October 2017 at 21:30 To: "Cooper, Jonathan" j.p.cooper@ucl.ac.uk Cc: "Tamuri, Asif" a.tamuri@ucl.ac.uk, Michael Clerx michael.clerx@cs.ox.ac.uk, "Klapaukh, Roma" r.klapaukh@ucl.ac.uk, Alan Garny alan.garny@inria.fr Subject: Re: Extracting mathematics from CellML

Hi Jonathan,

Just adding Alan in since we were talking about CellML and math yesterday.

The vague plan is still to try and use something like SymEngine (in C++) to help with handling the systems of equations represented in CellML models and the idea of my cellml-math code was to start playing around with this. Unfortunately, I haven’t managed to get as far as I wanted with this. What I was initially trying to achieve was something that would let me either evaluate models in a run-time interpreter style or generate JIT llvm/clang objects for better performance (which it seems to be what SymEngine does as well). While doing this I kept jumping between trying to work out how to use SymEngine and how to extract equations from CellML and never really had the time to do either :) I am hoping to get some time over Christmas to work on this some more, but if there is already a python code it would make things much easier!

Everything I kept finding on SymEngine always started with: first do it in SymPy and then convert across to SymEngine. So I think having an initial python code that will let us start working with math from CellML 2.0 models is going to be the best way to really get this started. Apart from a desire in Auckland to have this working, there is no real timeline or resource dedicated to this work. Hugh has been focused on trying to get the libCellML object model complete and validation rules implemented. Alan is thinking about doing an initial re-implementation of his original COR math handling based on libCellML. We’re keen to get the Smith cardiovascular model (DAE) up and running in OpenCOR for that annotation example for the COMBINEd annotation paper.

Not sure if that helps, and maybe Alan might want to comment on his plans with OpenCOR – but that is also “off the books” so to speak, as his main priorities don’t involve this ;-)

Cheers, Andre.

From: Jonathan Cooper j.p.cooper@ucl.ac.uk Date: Friday, 13 October 2017 at 17:13 To: David Nickerson d.nickerson@auckland.ac.nz Cc: "Tamuri, Asif" a.tamuri@ucl.ac.uk, Michael Clerx michael.clerx@cs.ox.ac.uk, "Klapaukh, Roma" r.klapaukh@ucl.ac.uk Subject: Extracting mathematics from CellML

Hi Andre,

Asif and I are starting to look at re-writing pycml into something saner and more maintainable for the Web Lab project, to do the mathematical manipulations. We’re planning to make it into 2 Python packages: one that starts from equations (probably in SymPy) and does the transformations & code generation, and one for going from CellML -> mathematics. For the latter, I was wondering if you could give us a quick update on the status of https://github.com/nickerso/cellml-math and what plans/timelines are in Auckland for processing maths in CellML models. Is the thinking still to contribute MathML parsing to SymEngine and/or SymPy? Or are there new ideas?

Many thanks, Jonathan

agarny commented 6 years ago

Quick comment so that GitHub will keep me updated on this issue...

nickerso commented 6 years ago

just for reference: https://github.com/cellml/cellml1to2

jonc125 commented 6 years ago

Created https://github.com/ModellingWebLab/cellmlmanip to start work on this. Specific issues will go there.

MichaelClerx commented 5 years ago

Guess we can close this in favour of:

@jonc125 ?