Skip to content

Commit e9c4444

Browse files
committed
fix replacement code to calculate assignment rules from simulation data (don't replace _init attributes)
1 parent 8ebbcb3 commit e9c4444

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

pysces/PyscesModel.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,7 @@ def InitialiseRules(self):
19331933
self.__HAS_FORCED_FUNCS__ = False
19341934
self.__HAS_RATE_RULES__ = False
19351935
self._CVODE_extra_output = []
1936+
self._CVODE_XOUT = False
19361937
rate_rules = {}
19371938
assignment_rules = {}
19381939
for ar in self.__rules__:
@@ -3010,6 +3011,22 @@ def InitialiseModel(self):
30103011
)
30113012
print(
30123013
'Assimulo may be installed from conda-forge or compiled from source.\n\
3014+
See: https://jmodelica.org/assimulo'
3015+
)
3016+
if self.__HAS_FORCED_FUNCS__:
3017+
if _HAVE_ASSIMULO:
3018+
print(
3019+
'INFO: Assignment Rules detected and Assimulo installed,\n\
3020+
switching to CVODE (mod.mode_integrator=\'CVODE\').\n'
3021+
)
3022+
self.mode_integrator = 'CVODE'
3023+
else:
3024+
print(
3025+
'\nWARNING: Assignment Rules detected! PySCeS prefers CVODE but will continue with LSODA\n\
3026+
(NOTE: THE VALUES OF ASSIGNMENT RULES DURING THE SIMULATION CANNOT BE TRACKED WITH LSODA!)'
3027+
)
3028+
print(
3029+
'Assimulo may be installed from conda-forge or compiled from source.\n\
30133030
See: https://jmodelica.org/assimulo'
30143031
)
30153032

@@ -3952,6 +3969,13 @@ def LSODA(self, initial):
39523969
initial: vector containing initial species concentrations
39533970
39543971
"""
3972+
if self.mode_integrate_all_odes:
3973+
print("""
3974+
NOTE: Integration of all ODEs is not supported with LSODA. PySCeS will integrate
3975+
a reduced set of ODEs and the dependent conserved species will be calculated from the L-matrix.
3976+
The `mod.mode_integrate_all_odes` flag is ignored. To explicitly integrate all ODEs, switch
3977+
to CVODE (mod.mode_integrator='CVODE')"""
3978+
)
39553979
Vtemp = numpy.zeros((self.__Nshape__[1]), 'd')
39563980

39573981
def function_sim(s, t):
@@ -4724,7 +4748,7 @@ def Simulate(self, userinit=0):
47244748
name = self._CVODE_extra_output[i]
47254749
self._update_assignment_rule_code(ars[name])
47264750
self._CVODE_xdata[:, i] = eval(ars[name]['data_sim_string'])
4727-
self.data_sim.setXData(self._CVODE_xdata, lbls=self._CVODE_extra_output)
4751+
self.data_sim.setXData(self._CVODE_xdata, lbls=self._CVODE_extra_output)
47284752
self._CVODE_xdata = None
47294753
if not simOK:
47304754
print('Simulation failure')
@@ -4734,11 +4758,14 @@ def _update_assignment_rule_code(self, rule):
47344758
replacements = []
47354759
rule['data_sim_string'] = rule['code_string']
47364760
for s in rule['symbols']:
4737-
if s in self.__reactions__ or s in self.__rate_rules__:
4738-
replacements.append((s, 'data_sim.getSimData("' + s + '")[:,1]'))
4739-
elif s in self.__species__:
4740-
replacements.append(('(self.' + s + ')',
4741-
'(self.data_sim.getSimData("' + s + '")[:,1])'))
4761+
if s in self.__reactions__ or s in self.__rules__ or s in self.__species__:
4762+
# catch any _init so it doesn't get replaced
4763+
replacements.append((s + '_init', '_zzzz_'))
4764+
# replace symbol to get sim data
4765+
replacements.append(('self.' + s, 'self.data_sim.getSimData("' + s + '")[:,1]'))
4766+
# revert the _init
4767+
replacements.append(('_zzzz_', s + '_init'))
4768+
47424769
for old, new in replacements:
47434770
rule['data_sim_string'] = rule['data_sim_string'].replace(old, new)
47444771

0 commit comments

Comments
 (0)