本文整理汇总了Python中artiq.master.worker_db.DeviceManager.close_devices方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceManager.close_devices方法的具体用法?Python DeviceManager.close_devices怎么用?Python DeviceManager.close_devices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类artiq.master.worker_db.DeviceManager
的用法示例。
在下文中一共展示了DeviceManager.close_devices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
args = get_argparser().parse_args()
init_logger(args)
dmgr = DeviceManager(FlatFileDB(args.ddb))
pdb = FlatFileDB(args.pdb)
try:
module = file_import(args.file)
exp = get_experiment(module, args.experiment)
arguments = parse_arguments(args.arguments)
exp_inst = exp(dmgr, pdb, **arguments)
if not hasattr(exp.run, "k_function_info") or not exp.run.k_function_info:
raise ValueError("Experiment entry point must be a kernel")
core_name = exp.run.k_function_info.core_name
core = getattr(exp_inst, core_name)
binary, rpc_map, _ = core.compile(exp.run.k_function_info.k_function, [exp_inst], {}, with_attr_writeback=False)
finally:
dmgr.close_devices()
if rpc_map:
raise ValueError("Experiment must not use RPC")
output = args.output
if output is None:
output = args.file
if output.endswith(".py"):
output = output[:-3]
output += ".elf"
with open(output, "wb") as f:
f.write(binary)
示例2: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
args = get_argparser().parse_args()
device_mgr = DeviceManager(DeviceDB(args.device_db))
try:
comm = device_mgr.get("comm")
if args.action == "log":
print(comm.get_log())
elif args.action == "cfg-read":
value = comm.flash_storage_read(args.key)
if not value:
print("Key {} does not exist".format(args.key))
else:
print(value)
elif args.action == "cfg-write":
for key, value in args.string:
comm.flash_storage_write(key, value)
for key, filename in args.file:
with open(filename, "rb") as fi:
comm.flash_storage_write(key, fi.read())
elif args.action == "cfg-delete":
for key in args.key:
comm.flash_storage_remove(key)
elif args.action == "cfg-erase":
comm.flash_storage_erase()
finally:
device_mgr.close_devices()
示例3: run
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
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))
示例4: ExperimentCase
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
class ExperimentCase(unittest.TestCase):
def setUp(self):
self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.pyon"))
self.dataset_db = DatasetDB(os.path.join(artiq_root, "dataset_db.pyon"))
self.device_mgr = DeviceManager(self.device_db,
virtual_devices={"scheduler": DummyScheduler()})
self.dataset_mgr = DatasetManager(self.dataset_db)
def create(self, cls, **kwargs):
try:
exp = cls(self.device_mgr, self.dataset_mgr, **kwargs)
exp.prepare()
return exp
except KeyError as e:
# skip if ddb does not match requirements
raise unittest.SkipTest(*e.args)
def execute(self, cls, *args, **kwargs):
expid = {
"file": sys.modules[cls.__module__].__file__,
"class_name": cls.__name__,
"arguments": kwargs
}
self.device_mgr.virtual_devices["scheduler"].expid = expid
try:
exp = self.create(cls, **kwargs)
exp.run()
exp.analyze()
return exp
except CompileError as error:
# Reduce amount of text on terminal.
raise error from None
finally:
self.device_mgr.close_devices()
示例5: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
args = get_argparser().parse_args()
init_logger(args)
if not args.print_decoded and args.write_vcd is None and args.write_dump is None:
print("No action selected, use -p, -w and/or -d. See -h for help.")
sys.exit(1)
device_mgr = DeviceManager(DeviceDB(args.device_db))
try:
if args.read_dump:
with open(args.read_dump, "rb") as f:
dump = f.read()
else:
comm = device_mgr.get("comm")
dump = comm.get_analyzer_dump()
decoded_dump = decode_dump(dump)
if args.print_decoded:
print("Log channel:", decoded_dump.log_channel)
print("DDS one-hot:", decoded_dump.dds_onehot_sel)
for message in decoded_dump.messages:
print(message)
if args.write_vcd:
with open(args.write_vcd, "w") as f:
decoded_dump_to_vcd(f, device_mgr.get_device_db(), decoded_dump)
if args.write_dump:
with open(args.write_dump, "wb") as f:
f.write(dump)
finally:
device_mgr.close_devices()
示例6: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
args = get_argparser().parse_args()
init_logger(args)
device_mgr = DeviceManager(DeviceDB(args.device_db))
try:
comm = device_mgr.get("comm")
comm.check_ident()
if args.action == "read":
value = comm.flash_storage_read(args.key)
if not value:
print("Key {} does not exist".format(args.key))
else:
print(value)
elif args.action == "write":
for key, value in args.string:
comm.flash_storage_write(key, value.encode("utf-8"))
for key, filename in args.file:
with open(filename, "rb") as fi:
comm.flash_storage_write(key, fi.read())
elif args.action == "delete":
for key in args.key:
comm.flash_storage_remove(key)
elif args.action == "erase":
comm.flash_storage_erase()
finally:
device_mgr.close_devices()
示例7: ExperimentCase
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
class ExperimentCase(unittest.TestCase):
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()
def execute(self, cls, **kwargs):
expid = {
"file": sys.modules[cls.__module__].__file__,
"class_name": cls.__name__,
"arguments": kwargs
}
self.dmgr.virtual_devices["scheduler"].expid = expid
try:
try:
exp = cls(self.dmgr, self.pdb, self.rdb, **kwargs)
except KeyError as e:
# skip if ddb does not match requirements
raise unittest.SkipTest(*e.args)
exp.prepare()
exp.run()
exp.analyze()
return exp
finally:
self.dmgr.close_devices()
示例8: run
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def run(with_file=False):
args = get_argparser(with_file).parse_args()
init_logger(args)
device_mgr = DeviceManager(DeviceDB(args.device_db),
virtual_devices={"scheduler": DummyScheduler()})
dataset_db = DatasetDB(args.dataset_db)
dataset_mgr = DatasetManager(dataset_db)
try:
exp_inst = _build_experiment(device_mgr, dataset_mgr, args)
exp_inst.prepare()
exp_inst.run()
exp_inst.analyze()
except CompileError as error:
return
except Exception as exn:
if hasattr(exn, "artiq_core_exception"):
print(exn.artiq_core_exception, file=sys.stderr)
raise exn
finally:
device_mgr.close_devices()
if args.hdf5 is not None:
with h5py.File(args.hdf5, "w") as f:
dataset_mgr.write_hdf5(f)
else:
for k, v in sorted(dataset_mgr.local.items(), key=itemgetter(0)):
print("{}: {}".format(k, v))
dataset_db.save()
示例9: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
args = get_argparser().parse_args()
init_logger(args)
device_mgr = DeviceManager(DeviceDB(args.device_db))
try:
comm = device_mgr.get("comm")
comm.check_ident()
print(comm.get_log(), end="")
finally:
device_mgr.close_devices()
示例10: ExperimentCase
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
class ExperimentCase(unittest.TestCase):
def setUp(self):
self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.pyon"))
self.dataset_db = DatasetDB(
os.path.join(artiq_root, "dataset_db.pyon"))
self.device_mgr = DeviceManager(
self.device_db, virtual_devices={"scheduler": DummyScheduler()})
self.dataset_mgr = DatasetManager(self.dataset_db)
def tearDown(self):
self.device_mgr.close_devices()
def create(self, cls, *args, **kwargs):
try:
exp = cls(
(self.device_mgr, self.dataset_mgr, None),
*args, **kwargs)
exp.prepare()
return exp
except KeyError as e:
# skip if ddb does not match requirements
raise unittest.SkipTest(
"device_db entry `{}` not found".format(*e.args))
def execute(self, cls, *args, **kwargs):
expid = {
"file": sys.modules[cls.__module__].__file__,
"class_name": cls.__name__,
"arguments": dict()
}
self.device_mgr.virtual_devices["scheduler"].expid = expid
try:
exp = self.create(cls, *args, **kwargs)
exp.run()
exp.analyze()
return exp
except CompileError as error:
# Reduce amount of text on terminal.
raise error from None
except Exception as exn:
if hasattr(exn, "artiq_core_exception"):
exn.args = "{}\n{}".format(exn.args[0],
exn.artiq_core_exception),
raise exn
示例11: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
args = get_argparser().parse_args()
init_logger(args)
device_mgr = DeviceManager(DeviceDB(args.device_db))
dataset_mgr = DatasetManager(DatasetDB(args.dataset_db))
try:
module = file_import(args.file, prefix="artiq_run_")
exp = get_experiment(module, args.experiment)
arguments = parse_arguments(args.arguments)
argument_mgr = ProcessArgumentManager(arguments)
exp_inst = exp((device_mgr, dataset_mgr, argument_mgr))
if not hasattr(exp.run, "artiq_embedded"):
raise ValueError("Experiment entry point must be a kernel")
core_name = exp.run.artiq_embedded.core_name
core = getattr(exp_inst, core_name)
object_map, kernel_library, _, _ = \
core.compile(exp.run, [exp_inst], {},
attribute_writeback=False, print_as_rpc=False)
except CompileError as error:
return
finally:
device_mgr.close_devices()
if object_map.has_rpc():
raise ValueError("Experiment must not use RPC")
output = args.output
if output is None:
basename, ext = os.path.splitext(args.file)
output = "{}.elf".format(basename)
with open(output, "wb") as f:
f.write(kernel_library)
示例12: run
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def run(with_file=False):
args = get_argparser(with_file).parse_args()
init_logger(args)
device_mgr = DeviceManager(DeviceDB(args.device_db),
virtual_devices={"scheduler": DummyScheduler()})
dataset_db = DatasetDB(args.dataset_db)
dataset_mgr = DatasetManager(dataset_db)
try:
exp_inst = _build_experiment(device_mgr, dataset_mgr, args)
exp_inst.prepare()
exp_inst.run()
exp_inst.analyze()
finally:
device_mgr.close_devices()
if args.hdf5 is not None:
with h5py.File(args.hdf5, "w") as f:
dataset_mgr.write_hdf5(f)
else:
for k, v in sorted(dataset_mgr.local.items(), key=itemgetter(0)):
print("{}: {}".format(k, v))
dataset_db.save()
示例13: GenericControllerCase
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
class GenericControllerCase(unittest.TestCase):
def get_device_db(self):
raise NotImplementedError
def setUp(self):
self.device_db = self.get_device_db()
self.device_mgr = DeviceManager(self.device_db)
self.controllers = {}
def tearDown(self):
self.device_mgr.close_devices()
for name in list(self.controllers):
self.stop_controller(name)
def start_controller(self, name, sleep=1):
if name in self.controllers:
raise ValueError("controller `{}` already started".format(name))
try:
entry = self.device_db.get(name)
except KeyError:
raise unittest.SkipTest(
"controller `{}` not found".format(name))
entry["command"] = entry["command"].format(
name=name, bind=entry["host"], port=entry["port"])
proc = subprocess.Popen(shlex.split(entry["command"]))
self.controllers[name] = entry, proc
time.sleep(sleep)
def stop_controller(self, name, default_timeout=1):
desc, proc = self.controllers[name]
t = desc.get("term_timeout", default_timeout)
target_name = desc.get("target_name", None)
if target_name is None:
target_name = AutoTarget
try:
try:
client = Client(desc["host"], desc["port"], target_name, t)
try:
client.terminate()
finally:
client.close_rpc()
proc.wait(t)
return
except (socket.timeout, subprocess.TimeoutExpired):
logger.warning("Controller %s failed to exit on request", name)
try:
proc.terminate()
except ProcessLookupError:
pass
try:
proc.wait(t)
return
except subprocess.TimeoutExpired:
logger.warning("Controller %s failed to exit on terminate",
name)
try:
proc.kill()
except ProcessLookupError:
pass
try:
proc.wait(t)
return
except subprocess.TimeoutExpired:
logger.warning("Controller %s failed to die on kill", name)
finally:
del self.controllers[name]
示例14: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
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()
示例15: main
# 需要导入模块: from artiq.master.worker_db import DeviceManager [as 别名]
# 或者: from artiq.master.worker_db.DeviceManager import close_devices [as 别名]
def main():
global ipc
multiline_log_config(level=int(sys.argv[2]))
ipc = pipe_ipc.ChildComm(sys.argv[1])
start_time = None
rid = None
expid = None
exp = None
exp_inst = None
repository_path = None
device_mgr = DeviceManager(ParentDeviceDB)
device_mgr.virtual_devices["scheduler"] = Scheduler(device_mgr)
dataset_mgr = DatasetManager(ParentDatasetDB)
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
experiment_file = os.path.join(obj["wd"], expid["file"])
repository_path = obj["wd"]
else:
experiment_file = expid["file"]
repository_path = None
setup_diagnostics(experiment_file, repository_path)
exp = get_exp(experiment_file, expid["class_name"])
device_mgr.virtual_devices["scheduler"].set_run_info(
rid, obj["pipeline_name"], expid, obj["priority"])
dirname = os.path.join("results",
time.strftime("%Y-%m-%d", start_time),
time.strftime("%H", start_time))
os.makedirs(dirname, exist_ok=True)
os.chdir(dirname)
argument_mgr = ProcessArgumentManager(expid["arguments"])
exp_inst = exp((device_mgr, dataset_mgr, argument_mgr))
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":
filename = "{:09}-{}.h5".format(rid, exp.__name__)
with h5py.File(filename, "w") as f:
dataset_mgr.write_hdf5(f.create_group("datasets"))
f["artiq_version"] = artiq_version
f["rid"] = rid
f["start_time"] = int(time.mktime(start_time))
f["expid"] = pyon.encode(expid)
put_object({"action": "completed"})
elif action == "examine":
examine(ExamineDeviceMgr, ParentDatasetDB, obj["file"])
put_object({"action": "completed"})
elif action == "terminate":
break
except Exception as exc:
# When we get CompileError, a more suitable diagnostic has already
# been printed.
if not isinstance(exc, CompileError):
short_exc_info = type(exc).__name__
exc_str = str(exc)
if exc_str:
short_exc_info += ": " + exc_str.splitlines()[0]
lines = ["Terminating with exception ("+short_exc_info+")\n"]
if hasattr(exc, "artiq_core_exception"):
lines.append(str(exc.artiq_core_exception))
if hasattr(exc, "parent_traceback"):
lines += exc.parent_traceback
lines += traceback.format_exception_only(type(exc), exc)
logging.error("".join(lines).rstrip(),
exc_info=not hasattr(exc, "parent_traceback"))
put_object({"action": "exception"})
finally:
device_mgr.close_devices()
ipc.close()