def main(): sys.stdout = sys.stderr = LogForwarder() start_time = None rid = None expid = None exp = None exp_inst = None dmgr = DeviceManager(ParentDDB, virtual_devices={"scheduler": Scheduler()}) rdb = ResultDB() rdb.rt.publish = update_rt_results try: while True: obj = get_object() action = obj["action"] if action == "build": start_time = time.localtime() rid = obj["rid"] expid = obj["expid"] if obj["wd"] is not None: # Using repository expf = os.path.join(obj["wd"], expid["file"]) else: expf = expid["file"] exp = get_exp(expf, expid["class_name"]) dmgr.virtual_devices["scheduler"].set_run_info( obj["pipeline_name"], expid, obj["priority"]) exp_inst = exp(dmgr, ParentPDB, rdb, **expid["arguments"]) put_object({"action": "completed"}) elif action == "prepare": exp_inst.prepare() put_object({"action": "completed"}) elif action == "run": exp_inst.run() put_object({"action": "completed"}) elif action == "analyze": exp_inst.analyze() put_object({"action": "completed"}) elif action == "write_results": f = get_hdf5_output(start_time, rid, exp.__name__) try: rdb.write_hdf5(f) if "repo_rev" in expid: rr = expid["repo_rev"] dtype = "S{}".format(len(rr)) dataset = f.create_dataset("repo_rev", (), dtype) dataset[()] = rr.encode() finally: f.close() put_object({"action": "completed"}) elif action == "examine": examine(DummyDMGR(), DummyPDB(), ResultDB(), obj["file"]) put_object({"action": "completed"}) elif action == "terminate": break finally: dmgr.close_devices()
def run(with_file=False): args = get_argparser(with_file).parse_args() init_logger(args) dmgr = DeviceManager(FlatFileDB(args.ddb), virtual_devices={"scheduler": DummyScheduler()}) pdb = FlatFileDB(args.pdb) pdb.hooks.append(SimpleParamLogger()) rdb = ResultDB() try: exp_inst = _build_experiment(dmgr, pdb, rdb, args) exp_inst.prepare() exp_inst.run() exp_inst.analyze() finally: dmgr.close_devices() if args.hdf5 is not None: with h5py.File(args.hdf5, "w") as f: rdb.write_hdf5(f) elif rdb.rt.read or rdb.nrt: r = chain(rdb.rt.read.items(), rdb.nrt.items()) for k, v in sorted(r, key=itemgetter(0)): print("{}: {}".format(k, v))
def setUp(self): self.ddb = FlatFileDB(os.path.join(artiq_root, "ddb.pyon")) self.dmgr = DeviceManager( self.ddb, virtual_devices={"scheduler": DummyScheduler()}) self.pdb = FlatFileDB(os.path.join(artiq_root, "pdb.pyon")) self.rdb = ResultDB()