forked from M-Labs/artiq
artiq_run: use new dpdb, report changed parameters, remove function parameter, support run arguments
This commit is contained in:
parent
b63b46786e
commit
492ce1632b
|
@ -8,23 +8,23 @@ from operator import itemgetter
|
|||
from artiq.management.file_import import file_import
|
||||
from artiq.language.context import *
|
||||
from artiq.management import pyon
|
||||
from artiq.management.dpdb import DeviceParamDB
|
||||
from artiq.management.dpdb import DeviceParamDB, DeviceParamSupplier
|
||||
|
||||
|
||||
class ELFRunner(AutoContext):
|
||||
comm = Device("comm")
|
||||
implicit_core = False
|
||||
|
||||
def run(self, filename, function):
|
||||
def run(self, filename):
|
||||
with open(filename, "rb") as f:
|
||||
binary = f.read()
|
||||
comm.load(binary)
|
||||
comm.run(function)
|
||||
comm.run("run")
|
||||
comm.serve(dict(), dict())
|
||||
|
||||
|
||||
def _get_args():
|
||||
parser = argparse.ArgumentParser(description="Experiment running tool")
|
||||
parser = argparse.ArgumentParser(description="Local running tool")
|
||||
|
||||
parser.add_argument("-d", "--ddb", default="ddb.pyon",
|
||||
help="device database file")
|
||||
|
@ -33,26 +33,36 @@ def _get_args():
|
|||
|
||||
parser.add_argument("-e", "--elf", default=False, action="store_true",
|
||||
help="run ELF binary")
|
||||
parser.add_argument("-f", "--function", default="run",
|
||||
help="function to run")
|
||||
parser.add_argument("-u", "--unit", default=None,
|
||||
help="unit to run")
|
||||
parser.add_argument("file",
|
||||
help="file containing the unit to run")
|
||||
parser.add_argument("arguments", nargs="*",
|
||||
help="run arguments")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = _get_args()
|
||||
def _parse_arguments(arguments):
|
||||
d = {}
|
||||
for argument in arguments:
|
||||
name, value = argument.split("=")
|
||||
d[name] = pyon.decode(value)
|
||||
return d
|
||||
|
||||
devices = pyon.load_file(args.ddb)
|
||||
parameters = pyon.load_file(args.pdb)
|
||||
dpdb = DeviceParamDB(devices, parameters)
|
||||
|
||||
def main():
|
||||
args = _get_args()
|
||||
|
||||
dpdb = DeviceParamDB(args.ddb, args.pdb)
|
||||
dps = DeviceParamSupplier(dpdb.req_device, dpdb.req_parameter)
|
||||
try:
|
||||
if args.elf:
|
||||
unit_inst = ELFRunner(dpdb)
|
||||
unit_inst.run(args.file, args.function)
|
||||
if args.arguments:
|
||||
print("Run arguments are not supported in ELF mode")
|
||||
sys.exit(1)
|
||||
unit_inst = ELFRunner(dps)
|
||||
unit_inst.run(args.file)
|
||||
else:
|
||||
module = file_import(args.file)
|
||||
if args.unit is None:
|
||||
|
@ -75,11 +85,22 @@ def main():
|
|||
unit = units[0][1]
|
||||
else:
|
||||
unit = getattr(module, args.unit)
|
||||
unit_inst = unit(dpdb)
|
||||
f = getattr(unit_inst, args.function)
|
||||
f()
|
||||
|
||||
try:
|
||||
arguments = _parse_arguments(args.arguments)
|
||||
except:
|
||||
print("Failed to parse run arguments")
|
||||
sys.exit(1)
|
||||
|
||||
unit_inst = unit(dps)
|
||||
unit_inst.run(**arguments)
|
||||
|
||||
if dps.parameter_wb:
|
||||
print("Modified parameters:")
|
||||
for requester, name in dps.parameter_wb:
|
||||
print("{}: {}".format(name, getattr(requester, name)))
|
||||
finally:
|
||||
dpdb.close()
|
||||
dps.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue