def __init__(self, cwd, model_name, name_base, gen_type, gen_version=0): """ Internal utility to manage versions of Generator objects within single session. cwd = current working directory (string) Option to set known gen version # to reuse: Version 0 means not yet created. Works across saved and restarted sessions """ self.cwd = cwd self.model_name = model_name self.name_base = name_base self.gen_version = gen_version self.gen_type = gen_type # keyed by version self.used_dsargs = {} self.logfile = os.path.join(self.cwd, 'models', 'gen_dsargs_log.sav') if os.path.exists(self.logfile): # reload previous list of versions self.used_dsargs = dst.loadObjects(self.logfile)[0] self.classes = {'vode': dst.Generator.Vode_ODEsystem, 'dopri': dst.Generator.Dopri_ODEsystem, 'radau': dst.Generator.Radau_ODEsystem, 'euler': dst.Generator.Euler_ODEsystem} self.targetlang = self._targetlangs[gen_type]
def __init__(self, cwd, model_name, name_base, gen_type, gen_version=0): """ Internal utility to manage versions of Generator objects within single session. cwd = current working directory (string) Option to set known gen version # to reuse: Version 0 means not yet created. Works across saved and restarted sessions """ self.cwd = cwd self.model_name = model_name self.name_base = name_base self.gen_version = gen_version self.gen_type = gen_type # keyed by version self.used_dsargs = {} self.logfile = os.path.join(self.cwd, 'models', 'gen_dsargs_log.sav') if os.path.exists(self.logfile): # reload previous list of versions self.used_dsargs = dst.loadObjects(self.logfile)[0] self.classes = { 'vode': dst.Generator.Vode_ODEsystem, 'dopri': dst.Generator.Dopri_ODEsystem, 'radau': dst.Generator.Radau_ODEsystem, 'euler': dst.Generator.Euler_ODEsystem } self.targetlang = self._targetlangs[gen_type]
def make(self, dsargs): # use cache if available for gen_ver, prev_dsargs in self.used_dsargs.items(): if dst.filteredDict(dsargs, 'name', True) == dst.filteredDict(prev_dsargs, 'name', True): # compare everything but the name, but check all up to final '_ver<X>' parts1 = dsargs.name.split('_') parts2 = prev_dsargs.name.split('_') # will have one more part if parts1 == parts2[:-2]: print("Reusing identical build") return dst.loadObjects(os.path.join(self.cwd, 'models', prev_dsargs.name+'.sav'))[0] # no matches return self.build(dsargs)
def make(self, dsargs): # use cache if available for gen_ver, prev_dsargs in self.used_dsargs.items(): if dst.filteredDict(dsargs, 'name', True) == dst.filteredDict( prev_dsargs, 'name', True): # compare everything but the name, but check all up to final '_ver<X>' parts1 = dsargs.name.split('_') parts2 = prev_dsargs.name.split('_') # will have one more part if parts1 == parts2[:-2]: print("Reusing identical build") return dst.loadObjects( os.path.join(self.cwd, 'models', prev_dsargs.name + '.sav'))[0] # no matches return self.build(dsargs)
def load_gen(self, name): if self.gen_version == 0: raise ValueError("No current version known: set gen_version") return dst.loadObjects(os.path.join(self.cwd, 'models', name + '_' + \ self.gen_type + \ '_ver%i'%self.gen_version+'.sav'))[0]