PySCeS / pysces

The official PySCeS project source code repository.
https://pysces.github.io
Other
34 stars 10 forks source link

CVODE not compatible with __HAS_MOIETY_CONSERVATION__ #38

Closed jonrkarr closed 3 years ago

jonrkarr commented 3 years ago

CVODE appears to not be compatible with __HAS_MOIETY_CONSERVATION__.

This leads to two questions:

Failure

Example model:

Environment

Trying to run BIOMD0000000002 with CVODE

import os
import pysces
import tempfile

interfaces = pysces.PyscesInterfaces.Core2interfaces()
fid, model_filename = tempfile.mkstemp(suffix='.psc')
os.close(fid)
interfaces.convertSBML2PSC(sbmlfile='/tmp/biomd0000000002.xml', pscfile=model_filename)
model = pysces.model(model_filename)

model.mode_integrator = 'CVODE'
model.sim_start = 0.
model.sim_end = 10.
model.sim_points = 100 + 1
model.Simulate()

generates this error

/opt/conda/envs/py2/lib/python2.7/site-packages/pysces/PyscesModel.pyc in Simulate(self, userinit)
   4259             sim_res, rates, simOK = self.LSODA(copy.copy(s0_sim_init))
   4260         elif self.mode_integrator == 'CVODE':
-> 4261             sim_res, rates, simOK = self.CVODE(copy.copy(s0_sim_init))
   4262         Tsim1 = time.time()
   4263         if self.__settings__['lsoda_mesg']:

/opt/conda/envs/py2/lib/python2.7/site-packages/pysces/PyscesModel.pyc in CVODE(***failed resolving arguments***)
   3349 
   3350             if not self.mode_integrate_all_odes:
-> 3351                 self._EvalODE(out0.copy(),self.__CVODE_Vtemp)
   3352             else:
   3353                 self._EvalODE_CVODE(out0.copy(),self.__CVODE_Vtemp)

/opt/conda/envs/py2/lib/python2.7/site-packages/pysces/PyscesModel.pyc in _EvalODE(self, s, Vtemp)
   3152         if self.__HAS_MOIETY_CONSERVATION__ == True:
   3153             for x in range(len(s)):
-> 3154                 self.__SALL__[self.nrmatrix_row[x]] = s[x]
   3155             for x in range(len(self.lzeromatrix_row)):
   3156                 self.__SALL__[self.lzeromatrix_row[x]] = self.__tvec_a__[x] + numpy.add.reduce(self.__lzeromatrix__[x,:]*s)
jmrohwer commented 3 years ago

Hi Jonathan,

Thanks for your interest in our PySCeS project! Python 2.x is no longer supported, having reached EOL. The original PySundials developed in our group more than a decade ago was based on ctypes, and the interface was very cumbersome to maintain. We also do not have the bandwidth to continue supporting it and the latest stable Sundials version supported is 2.3.0, which is very old.

Instead we have opted to make use of Assimulo which provides up-to-date Python binding to the most recent Sundials version, and it is packaged and distributed for conda via conda-forge.

For us the main reason for using CVODE is to be able to do event handling. There is a rudimentary framework available that implements the current event-handling framework in Python 3, but it is very much a work in progress. You can check out the assimulo branch of the pysces repo for that.

In addition I have given you read access to the private https://github.com/PySCeS/pyscesdev repo, which contains some playground stuff and Jupyter Notebooks testing the events framework within Assimulo. As I said, all very much WIP and pull requests are always welcome...

I'll be away for the holidays and only able to reply again in the second week of January.

jonrkarr commented 3 years ago

Thanks for the detailed response. To clarify, I'm just looking to use PySCeS with CVODE. Is CVODE support in development, and a feature that isn't expected to currently work?

I would prefer to use a recent version of python and recent version of sundials. I only explored older versions because the PySCeS documentation says to use PySundials, which isn't maintained and only seems to work with old versions of Sundials.

Can you clarify how to use PySCeS with recent python and CVODE? Should I install assimulo from conda-forge and install PySCeS from the assimulo branch?

jonrkarr commented 3 years ago

I figured out how to get PySCeS working with CVODE. Updating the documentation would likely be very helpful to others. I would never have figured this out without the information you shared.