class CommandSelector: commands = { descendant.command.lower(): descendant for descendant in descendants(Command) } commands.update({ alias.lower(): descendant for descendant in descendants(Command) for alias in descendant.aliases }) command_logger.info('Loaded commands, CommandSelector.commands = ' + str(commands))
def execute(self, controller, args): return (str( [descendant.command for descendant in descendants(Command)]))
self.G, self.H, x, corners_A=self.corners_A, corners_B=self.corners_B) return self.apply_bias(out) class LDRTridiagonalC(LDRTridiagonal): class_type = 'tridiagonal_corner' abbrev = 'tdc' def reset_parameters(self): super().reset_parameters() self.corners_A = (Parameter(torch.tensor(0.0)), Parameter(torch.tensor(0.0))) self.corners_B = (Parameter(torch.tensor(0.0)), Parameter(torch.tensor(0.0))) # create a map from class names to the Python class class_map = {} for cls in descendants(Layer): if cls.class_type is None: continue class_map[cls.class_type] = cls class_map[cls.abbrev] = cls def StructuredLinear(class_type, **kwargs): return class_map[class_type](**kwargs)
train.train(dataset, model, optimizer, lr_scheduler, args.epochs, args.log_freq, log_path, checkpoint_path, result_path, args.test, args.save_model) ## Parse parser.set_defaults(task=mlp) # subparsers = parser.add_subparsers() # mlp_parser = subparsers.add_parser('MLP') # mlp_parser.set_defaults(task=mlp) # MLP models model_options = [] nets = {} for model in descendants(ArghModel): # Change the names so argh can create parsers model.args.__name__ = model.__name__ model_options.append(model.args) nets[model.__name__] = model argh.add_commands(parser, model_options, namespace='model', namespace_kwargs={'dest': 'model'}) for model in ArghModel.__subclasses__(): # Change names back model.args.__name__ = 'args' args = parser.parse_args() args.task(args)
def __init__(self, commandManager: CommandManager): self.command_list = [] for command in descendants(Command): if len(command.aliases): self.command_list.append(command.aliases[0]) super().__init__(commandManager)
def __init__(self, adventureManager): self.adventureManager = adventureManager self.commands_dict = { alias: command(self) for command in descendants(Command) for alias in command.aliases }