def get_mode(orig_string): if orig_string is None: string = config.mode else: string = orig_string if not isinstance(string, basestring): return string # it is hopefully already a mode... global instanciated_default_mode # The default mode is cached. However, config.mode can change # If instanciated_default_mode has the right class, use it. if orig_string is None and instanciated_default_mode: if string in predefined_modes: default_mode_class = predefined_modes[string].__class__.__name__ else: default_mode_class = string if (instanciated_default_mode.__class__.__name__ == default_mode_class): return instanciated_default_mode if string in ['Mode', 'ProfileMode', 'DebugMode']: if string == 'DebugMode': # need to import later to break circular dependency. from debugmode import DebugMode # DebugMode use its own linker. ret = DebugMode(optimizer=config.optimizer) else: # This might be required if the string is 'ProfileMode' from profilemode import ProfileMode # noqa from profilemode import prof_mode_instance_to_print ret = eval(string + '(linker=config.linker, optimizer=config.optimizer)') elif string in predefined_modes: ret = predefined_modes[string] else: raise Exception("No predefined mode exist for string: %s" % string) if orig_string is None: # Build and cache the default mode if theano.config.optimizer_excluding: ret = ret.excluding(*theano.config.optimizer_excluding.split(':')) if theano.config.optimizer_including: ret = ret.including(*theano.config.optimizer_including.split(':')) if theano.config.optimizer_requiring: ret = ret.requiring(*theano.config.optimizer_requiring.split(':')) instanciated_default_mode = ret # must tell python to print the summary at the end. if string == 'ProfileMode': # need to import later to break circular dependency. prof_mode_instance_to_print.append(ret) return ret
def __init__(self): super().__init__() robot = DriveBot(initSuper=False) self.addModule(robot) self.addModule(DebugMode(robot)) self.addModule(Climber(initSuper=False)) self.addModule(Shooter(initSuper=False))
def get_mode(orig_string): if orig_string is None: string = config.mode else: string = orig_string if not isinstance(string, str): return string #it is hopefully already a mode... global instanciated_default_mode # The default mode is cached. However, config.mode can change # If instanciated_default_mode has the right class, use it. if orig_string is None and instanciated_default_mode: if predefined_modes.has_key(string): default_mode_class = predefined_modes[string].__class__.__name__ else: default_mode_class = string if (instanciated_default_mode.__class__.__name__ == default_mode_class): return instanciated_default_mode if string in ['Mode','ProfileMode','DebugMode']: if string == 'DebugMode': #need to import later to break circular dependency. from debugmode import DebugMode #DebugMode use its own linker. ret = DebugMode(optimizer=config.optimizer) else: # The import is needed in case string is ProfileMode from profilemode import ProfileMode,prof_mode_instance_to_print ret = eval(string+'(linker=config.linker, optimizer=config.optimizer)') elif predefined_modes.has_key(string): # 'FAST_RUN_NOGC' and 'STABILIZE' are deprecated if string == 'FAST_RUN_NOGC': warnings.warn("Using the string 'FAST_RUN_NOGC' as a mode is " "deprecated, you should use the object " "Mode(linker='c|py_nogc') instead.", stacklevel=5) elif string == 'STABILIZE': warnings.warn("Using the string 'STABILIZE' as a mode is " "deprecated, you should use the object " "Mode(optimizer='stabilize') instead.", stacklevel=5) ret = predefined_modes[string] else: raise Exception("No predefined mode exist for string: %s"%string) if orig_string is None: # Build and cache the default mode if theano.config.optimizer_excluding: ret = ret.excluding(*theano.config.optimizer_excluding.split(':')) if theano.config.optimizer_including: ret = ret.including(*theano.config.optimizer_including.split(':')) if theano.config.optimizer_requiring: ret = ret.requiring(*theano.config.optimizer_requiring.split(':')) instanciated_default_mode = ret #must tell python to print the summary at the end. if string == 'ProfileMode': #need to import later to break circular dependency. prof_mode_instance_to_print.append(ret) return ret