From 5ee09d7454e5e316b98e0536a1ddb3e8fbe08e09 Mon Sep 17 00:00:00 2001 From: Peter Schubert <Peter.Schubert@hhu.de> Date: Sun, 12 Jun 2022 12:42:16 +0200 Subject: [PATCH] Cache last values of reaction rate related functions (v 0.3.2) --- xbanalysis/_version.py | 2 +- xbanalysis/problems/gba_problem.py | 63 ++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/xbanalysis/_version.py b/xbanalysis/_version.py index 88646c9..8c2bc5b 100644 --- a/xbanalysis/_version.py +++ b/xbanalysis/_version.py @@ -1,5 +1,5 @@ """ Definition of version string. """ -__version__ = "0.3.1" +__version__ = "0.3.2" program_name = 'xbanalysis' diff --git a/xbanalysis/problems/gba_problem.py b/xbanalysis/problems/gba_problem.py index ee30540..0e5dba8 100644 --- a/xbanalysis/problems/gba_problem.py +++ b/xbanalysis/problems/gba_problem.py @@ -110,14 +110,63 @@ class GbaProblem: self.model_params['mws'] = np.array([xba_model.species[sid].mw for sid in self.var_sids]) # create functions - self.mras, self.mras_jac, self.mras_hesss = self.get_reactions(self.mr_rids, inv=False) - self.pstmas, self.pstmas_jac, self.pstmas_hesss = self.get_reactions(self.ps_rids, inv=True) - self.degradas, self.degradas_jac, self.degradas_hesss = self.get_reactions(enz_degrad_rids, inv=False) - self.enz_transas, self.enz_transas_jac, self.enz_transas_hesss = self.get_reactions(enz_trans_rids, inv=False) + self.fmras, self.fmras_jac, self.fmras_hesss = self.get_reactions(self.mr_rids, inv=False) + self.fpstmas, self.fpstmas_jac, self.fpstmas_hesss = self.get_reactions(self.ps_rids, inv=True) + self.fdegradas, self.fdegradas_jac, self.fdegradas_hesss = self.get_reactions(enz_degrad_rids, inv=False) + self.fenz_tras, self.fenz_tras_jac, self.fenz_tras_hesss = self.get_reactions(enz_trans_rids, inv=False) self.n_constraints = {'heq_mass_balance': len(self.var_metab_sids), 'heq_enz_trans': self.subenz_x_trans.shape[0], 'heq_density': 1} + # TODO implement a factory method + @cache_last + def mras(self, x): + return self.fmras(x) + + @cache_last + def mras_jac(self, x): + return self.fmras_jac(x) + + @cache_last + def mras_hesss(self, x): + return self.fmras_hesss(x) + + @cache_last + def pstmas(self, x): + return self.fpstmas(x) + + @cache_last + def pstmas_jac(self, x): + return self.fpstmas_jac(x) + + @cache_last + def pstmas_hesss(self, x): + return self.fpstmas_hesss(x) + + @cache_last + def degradas(self, x): + return self.fdegradas(x) + + @cache_last + def degradas_jac(self, x): + return self.fdegradas_jac(x) + + @cache_last + def degradas_hesss(self, x): + return self.fdegradas_hesss(x) + + @cache_last + def enz_tras(self, x): + return self.fenz_tras(x) + + @cache_last + def enz_tras_jac(self, x): + return self.fenz_tras_jac(x) + + @cache_last + def enz_tras_hesss(self, x): + return self.fenz_tras_hesss(x) + def get_stoic_matrix(self, sids, rids): """retrieve stoichiometric sub-matrix [sids x rids]. @@ -640,7 +689,7 @@ class GbaProblem: :returns: Jacobian of mass balance equations at x :rtype: numpy.ndarray (1D) with shape (len(subenz_x_trans.shape[1]), 1) """ - return self.subenz_x_trans.dot(self.enz_transas(x)) + return self.subenz_x_trans.dot(self.enz_tras(x)) @cache_last def heq_enz_trans_jac(self, x): @@ -651,7 +700,7 @@ class GbaProblem: :returns: Jacobian of mass balance equations at x :rtype: numpy.ndarray (2D) """ - return self.subenz_x_trans.dot(self.enz_transas_jac(x)) + return self.subenz_x_trans.dot(self.enz_tras_jac(x)) @cache_last def heq_enz_trans_hess(self, x): @@ -662,7 +711,7 @@ class GbaProblem: :returns: Hessians of mass balance equations at x :rtype: numpy.ndarray (3D) with shape [n,x,x] """ - return np.array([(row.reshape((-1, 1, 1)) * self.enz_transas_hesss(x)).sum(axis=0) + return np.array([(row.reshape((-1, 1, 1)) * self.enz_tras_hesss(x)).sum(axis=0) for row in self.subenz_x_trans]) @cache_last -- GitLab