def AuxVars(self, t, xdict, pdict=None, asarray=True): """asarray is an unused, dummy argument for compatibility with Model.AuxVars""" # also, ensure xdict doesn't contain elements like array([4.1]) instead of 4 x = [float(val) for val in sortedDictValues(filteredDict(self._FScompatibleNames(xdict), self.funcspec.vars))] if pdict is None: pdict = self.pars # internal self.pars already is FS-compatible p = sortedDictValues(pdict) else: p = sortedDictValues(self._FScompatibleNames(pdict)) i = _pollInputs(sortedDictValues(self.inputs), t, self.checklevel) return apply(getattr(self, self.funcspec.auxspec[1]), [t, x, p+i]) def __del__(self): ODEsystem.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(Vode_ODEsystem, symbolMapDict, 'python')
raise IOError, e # Write the vfield.m file # vfdefines = self._prepareVfieldDefines() # allfilestr = self._prepareVfieldContents(vfdefines) allfilestr = self.funcspec.spec[0] + self._prepareAuxContents() vffile = os.path.join(self._target_dir, self._vfield_file) try: file = open(vffile, 'w') file.write(allfilestr) file.close() except IOError, e: print "Error opening file "+self._vfield_file+" for writing" raise IOError, e # We have omitted methods: RHS, compute, etc. because this # class is intended solely to generate code for ADMC++, not do any integrations # etc. def __del__(self): ODEsystem.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(ADMC_ODEsystem, symbolMapDict, 'matlab')
i = sortedDictValues(dict([(n, i(t)) for n, i in self.inputs.iteritems()])) return apply(eval("self." + self.funcspec.auxfns["Jacobian"][1]), [t, x, p + i]) else: raise PyDSTool_ExistError, "Jacobian not defined" def JacobianP(self, t, xdict, pdict): if self.haveJacobian_pars(): x = sortedDictValues(xdict) p = sortedDictValues(pdict) i = sortedDictValues(dict([(n, i(t)) for n, i in self.inputs.iteritems()])) return apply(eval("self." + self.funcspec.auxfns["Jacobian_pars"][1]), [t, x, p + i]) else: raise PyDSTool_ExistError, "Jacobian w.r.t. parameters not defined" def AuxVars(self, t, xdict, pdict): x = sortedDictValues(xdict) p = sortedDictValues(pdict) i = sortedDictValues(dict([(n, i(t)) for n, i in self.inputs.iteritems()])) return apply(eval("self." + self.funcspec.auxspec[1]), [t, x, p + i]) def __del__(self): discGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(MapSystem, symbolMapDict, "python")
self.validateSpec() self.defined = True def compute(self, trajname): return Trajectory(trajname, [copy(v) for v in self.variables.values()], self.globalt0, self.checklevel) computeTraj = compute def validateSpec(self): ctsGen.validateSpec(self) try: assert isoutputcts(self.indepvariable) for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): ctsGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(InterpolateTable, symbolMapDict, 'python')
if self.defined: self.validateSpec() self.clearWarnings() self.clearErrors() return Trajectory(trajname, [copy(v) for v in self.variables.values()], self.globalt0, self.checklevel) computeTraj = compute def validateSpec(self): discGen.validateSpec(self) try: assert isoutputdiscrete(self.indepvariable) for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): discGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(LookupTable, symbolMapDict, 'python')
# pass up to generic treatment for this ctsGen.set(self, checklevel=kw['checklevel']) if 'globalt0' in kw: # pass up to generic treatment for this ctsGen.set(self, globalt0=kw['globalt0']) def validateSpec(self): ctsGen.validateSpec(self) try: assert isoutputcts(self.indepvariable) for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): ctsGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(InterpolateTable, symbolMapDict, 'python')
' at bound') else: raise PyDSTool_ValueError('Parameter value out of' ' bounds') else: raise PyDSTool_AttributeError('Illegal parameter name') def validateSpec(self): ctsGen.validateSpec(self) try: for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): ctsGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(EmbeddedSysGen, symbolMapDict, 'python', None)
for k, v in kw['algparams'].iteritems(): self.algparams[k] = v if 'solvemethod' in self.algparams: if self.algparams['solvemethod'] not in _implicitSolveMethods: raise PyDSTool_ValueError('Invalid implicit solver type') def validateSpec(self): ctsGen.validateSpec(self) try: for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): ctsGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(ImplicitFnGen, symbolMapDict, 'python', 'ImpFuncSpec')
# pass up to generic treatment for this ctsGen.set(self, checklevel=kw['checklevel']) if 'globalt0' in kw: # pass up to generic treatment for this ctsGen.set(self, globalt0=kw['globalt0']) def validateSpec(self): ctsGen.validateSpec(self) try: assert isoutputcts(self.indepvariable) for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): ctsGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(ExtrapolateTable, symbolMapDict, 'python')
checklevel=self.checklevel, FScompatibleNames=self._FScompatibleNames, FScompatibleNamesInv=self._FScompatibleNamesInv, modelNames=self.name, modelEventStructs=self.eventstruct) def validateSpec(self): discGen.validateSpec(self) try: assert isoutputdiscrete(self.indepvariable) for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): discGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(LookupTable, symbolMapDict, 'python')
if 'algparams' in kw: for k, v in kw['algparams'].iteritems(): self._algparams[k] = v if 'solvemethod' in self._algparams: if self._algparams['solvemethod'] not in _implicitSolveMethods: raise PyDSTool_ValueError, 'Invalid implicit solver type' # for backwards compatibility setPars = set def validateSpec(self): ctsGen.validateSpec(self) try: for v in self.variables.values(): assert isinstance(v, Variable) assert not self.inputs except AssertionError: print 'Invalid system specification' raise def __del__(self): ctsGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(ImplicitFnGen, symbolMapDict, 'python', 'ImpFuncSpec')
def JacobianP(self, t, xdict, pdict): if self.haveJacobian_pars(): x = sortedDictValues(xdict) p = sortedDictValues(pdict) i = sortedDictValues(dict([(n,i(t)) for n,i in self.inputs.iteritems()])) return apply(eval("self."+self.funcspec.auxfns["Jacobian_pars"][1]), \ [t, x, p+i]) else: raise PyDSTool_ExistError, "Jacobian w.r.t. parameters not defined" def AuxVars(self, t, xdict, pdict): x = sortedDictValues(xdict) p = sortedDictValues(pdict) i = sortedDictValues(dict([(n,i(t)) for n,i in self.inputs.iteritems()])) return apply(eval("self."+self.funcspec.auxspec[1]), [t, x, p+i]) def __del__(self): discGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(MapSystem, symbolMapDict, 'python')
def _pollInputs(inputVarList, t, checklevel): ilist = [] try: for f in inputVarList: f.clearWarnings ilist.append(f(t, checklevel)) except AssertionError: print 'External input call has t out of range: t = ', t print 'Maybe checklevel is 3 and initial time is not', \ 'completely inside valid time interval' raise except ValueError: print 'External input call has value out of range: t = ', t print 'Check beginning and end time of integration' for f in inputVarList: if len(f.warnings): print 'External input %s out of range:' % f.name print ' t = ', repr(f.warnings[-1][0]), ', ', \ f.name, ' = ', repr(f.warnings[-1][1]) raise return ilist # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(Vode_ODEsystem, symbolMapDict, 'python')
raise PyDSTool_ExistError("Jacobian w.r.t. parameters not defined") def AuxVars(self, t, xdict, pdict=None, asarray=True): """asarray is an unused, dummy argument for compatibility with Model.AuxVars""" x = [float(val) for val in sortedDictValues(filteredDict(self._FScompatibleNames(xdict), self.funcspec.vars))] if pdict is None: pdict = self.pars # internal self.pars already is FS-compatible p = sortedDictValues(pdict) else: p = sortedDictValues(self._FScompatibleNames(pdict)) i = _pollInputs(sortedDictValues(self.inputs), t, self.checklevel) return apply(getattr(self,self.funcspec.auxspec[1]), [t, x, p+i]) def __del__(self): discGen.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(MapSystem, symbolMapDict, 'python')
print "Error opening file " + self._set_file + " for writing" raise IOError, e # Write the vfield.m file # vfdefines = self._prepareVfieldDefines() # allfilestr = self._prepareVfieldContents(vfdefines) allfilestr = self.funcspec.spec[0] + self._prepareAuxContents() vffile = os.path.join(self._target_dir, self._vfield_file) try: file = open(vffile, 'w') file.write(allfilestr) file.close() except IOError, e: print "Error opening file " + self._vfield_file + " for writing" raise IOError, e # We have omitted RHS, computeTraj, etc. because this # class is intended solely to generate code for ADMC++, not do any integrations # etc. def __del__(self): ODEsystem.__del__(self) # Register this Generator with the database symbolMapDict = {} # in future, provide appropriate mappings for libraries math, # random, etc. (for now it's left to FuncSpec) theGenSpecHelper.add(ADMC_ODEsystem, symbolMapDict, 'matlab')