results_folder : str, optional Folder where results are, by default './results' """ print("STAGE: ANALYZE") print(f"Generating plots for {results_folder}") (Path(results_folder) / 'example.png').touch() print() @argbind.bind(without_prefix=True, positional=True) def run(stage: str): """Run stages. Parameters ---------- stages : str Stage to run """ with output(): if stage not in STAGES: raise ValueError( f"Requested stage {stage} not in known stages {STAGES}") stage_fn = globals()[stage] stage_fn() if __name__ == "__main__": args = argbind.parse_args() with argbind.scope(args): run()
def forward(): run = argbind.bind(open_link, positional=True, without_prefix=True) args = argbind.parse_args() with argbind.scope(args): run()
class MyClass: def __init__(self, x: str = "from default"): self.x = x print(self.x) def my_func(x: int = 100): print(x) return x if __name__ == "__main__": import argbind BoundClass = argbind.bind(MyClass, 'pattern') bound_fn = argbind.bind(my_func) argbind.parse_args() # add for help text, though it isn't used here. args = { 'MyClass.x': 'from binding', 'pattern/MyClass.x': 'from binding in scoping pattern', 'my_func.x': 123, 'args.debug': True # for printing arguments passed to each function } # Original objects are not affected by ArgBind print("Original object output") with argbind.scope(args): MyClass() # prints "from default" my_func() # prints 100 print()
def main(): args = argbind.parse_args() with argbind.scope(args): arg = Args() signal.signal(signal.SIGINT, clean_up) app.run(debug=True, host=arg.host, port=arg.port)
ASGD, Adadelta, Adagrad, AdamW, Adamax, LBFGS, NAdam, RAdam, RMSprop, Rprop, SGD, SparseAdam ] class holder: def __init__(self): for o in optimizers: setattr(self, o.__name__, o) optim = holder() args = { "lr": 2e-4, "args.debug": True, } if __name__ == "__main__": argbind.parse_args() net = torch.nn.Linear(1, 1) for fn_name in dir(optim): if fn_name == "Optimizer": continue fn = getattr(optim, fn_name) if hasattr(fn, "step"): args[f"{fn_name}.lr"] = args["lr"] with argbind.scope(args): fn(net.parameters())