def wrapper(*args, **kwargs): params = { param: ro.Constant(default) for param, default in zip(arg_names, arg_defaults) } for key, value in kwargs.items(): if key in params: params[key] = ro.Constant(value) experiment = ro.Experiment(name=name, directory=directory, params=params) result = fn(*args, **kwargs) if isinstance(result, collections.Iterable): if len(result) == 2: experiment.add_result(result[0], data=result[1]) elif len(result) == 3: experiment.add_result(result[0], data=result[1], attachment=result[2]) else: experiment.add_result(result)
def dict_to_constants(dictionary): return {str(k): ro.Constant(dictionary[k]) for k in dictionary}
#!/usr/bin/env python3 import argparse import randopt as ro def parse(): parser = argparse.ArgumentParser() parser.add_argument('--abcd', type=float) parser.add_argument('--qwer', type=float) parser.add_argument('--asdf', type=float) return parser.parse_args() def loss(x, y, z): return x**2 + y**2 + z**2 if __name__ == '__main__': args = parse() exp = ro.Experiment('ropt_test', params={ 'abcd': ro.Constant(args.abcd), 'qwer': ro.Constant(args.qwer), 'asdf': ro.Constant(args.asdf), }) exp.add_result(loss(args.abcd, args.asdf, args.qwer))