forked from M-Labs/artiq
master,client,gui: factor timeout into run_params
This commit is contained in:
parent
cca6a17cfb
commit
4d21b78314
|
@ -104,19 +104,20 @@ def _action_submit(remote, args):
|
||||||
run_params = {
|
run_params = {
|
||||||
"file": args.file,
|
"file": args.file,
|
||||||
"unit": args.unit,
|
"unit": args.unit,
|
||||||
|
"timeout": args.timeout,
|
||||||
"arguments": arguments,
|
"arguments": arguments,
|
||||||
"rtr_group": args.rtr_group if args.rtr_group is not None \
|
"rtr_group": args.rtr_group if args.rtr_group is not None \
|
||||||
else args.file
|
else args.file
|
||||||
}
|
}
|
||||||
if args.timed is None:
|
if args.timed is None:
|
||||||
rid = remote.run_queued(run_params, args.timeout)
|
rid = remote.run_queued(run_params)
|
||||||
print("RID: {}".format(rid))
|
print("RID: {}".format(rid))
|
||||||
else:
|
else:
|
||||||
if args.timed == "now":
|
if args.timed == "now":
|
||||||
next_time = None
|
next_time = None
|
||||||
else:
|
else:
|
||||||
next_time = time.mktime(parse_date(args.timed).timetuple())
|
next_time = time.mktime(parse_date(args.timed).timetuple())
|
||||||
trid = remote.run_timed(run_params, args.timeout, next_time)
|
trid = remote.run_timed(run_params, next_time)
|
||||||
print("TRID: {}".format(trid))
|
print("TRID: {}".format(trid))
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,9 +148,9 @@ def _show_queue(queue):
|
||||||
clear_screen()
|
clear_screen()
|
||||||
if queue:
|
if queue:
|
||||||
table = PrettyTable(["RID", "File", "Unit", "Timeout", "Arguments"])
|
table = PrettyTable(["RID", "File", "Unit", "Timeout", "Arguments"])
|
||||||
for rid, run_params, timeout in queue:
|
for rid, run_params in queue:
|
||||||
row = [rid, run_params["file"]]
|
row = [rid, run_params["file"]]
|
||||||
for x in run_params["unit"], timeout:
|
for x in run_params["unit"], run_params["timeout"]:
|
||||||
row.append("-" if x is None else x)
|
row.append("-" if x is None else x)
|
||||||
row.append(format_run_arguments(run_params["arguments"]))
|
row.append(format_run_arguments(run_params["arguments"]))
|
||||||
table.add_row(row)
|
table.add_row(row)
|
||||||
|
@ -164,10 +165,10 @@ def _show_timed(timed):
|
||||||
table = PrettyTable(["Next run", "TRID", "File", "Unit",
|
table = PrettyTable(["Next run", "TRID", "File", "Unit",
|
||||||
"Timeout", "Arguments"])
|
"Timeout", "Arguments"])
|
||||||
sp = sorted(timed.items(), key=lambda x: (x[1][0], x[0]))
|
sp = sorted(timed.items(), key=lambda x: (x[1][0], x[0]))
|
||||||
for trid, (next_run, run_params, timeout) in sp:
|
for trid, (next_run, run_params) in sp:
|
||||||
row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)),
|
row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)),
|
||||||
trid, run_params["file"]]
|
trid, run_params["file"]]
|
||||||
for x in run_params["unit"], timeout:
|
for x in run_params["unit"], run_params["timeout"]:
|
||||||
row.append("-" if x is None else x)
|
row.append("-" if x is None else x)
|
||||||
row.append(format_run_arguments(run_params["arguments"]))
|
row.append(format_run_arguments(run_params["arguments"]))
|
||||||
table.add_row(row)
|
table.add_row(row)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class DummyScheduler:
|
||||||
self.next_rid = 0
|
self.next_rid = 0
|
||||||
self.next_trid = 0
|
self.next_trid = 0
|
||||||
|
|
||||||
def run_queued(self, run_params, timeout):
|
def run_queued(self, run_params):
|
||||||
rid = self.next_rid
|
rid = self.next_rid
|
||||||
self.next_rid += 1
|
self.next_rid += 1
|
||||||
print("Queuing: {}, RID={}".format(run_params, rid))
|
print("Queuing: {}, RID={}".format(run_params, rid))
|
||||||
|
@ -48,7 +48,7 @@ class DummyScheduler:
|
||||||
def cancel_queued(self, rid):
|
def cancel_queued(self, rid):
|
||||||
print("Cancelling RID {}".format(rid))
|
print("Cancelling RID {}".format(rid))
|
||||||
|
|
||||||
def run_timed(self, run_params, timeout, next_run):
|
def run_timed(self, run_params, next_run):
|
||||||
trid = self.next_trid
|
trid = self.next_trid
|
||||||
self.next_trid += 1
|
self.next_trid += 1
|
||||||
next_run_s = time.strftime("%m/%d %H:%M:%S", time.localtime(next_run))
|
next_run_s = time.strftime("%m/%d %H:%M:%S", time.localtime(next_run))
|
||||||
|
|
|
@ -147,7 +147,8 @@ class ExplorerWindow(Window):
|
||||||
run_params = {
|
run_params = {
|
||||||
"file": data["file"],
|
"file": data["file"],
|
||||||
"unit": data["unit"],
|
"unit": data["unit"],
|
||||||
|
"timeout": None,
|
||||||
"arguments": arguments,
|
"arguments": arguments,
|
||||||
"rtr_group": data["file"]
|
"rtr_group": data["file"]
|
||||||
}
|
}
|
||||||
asyncio.Task(self.schedule_ctl.run_queued(run_params, None))
|
asyncio.Task(self.schedule_ctl.run_queued(run_params))
|
||||||
|
|
|
@ -10,9 +10,9 @@ from artiq.tools import format_run_arguments
|
||||||
|
|
||||||
class _QueueStoreSyncer(ListSyncer):
|
class _QueueStoreSyncer(ListSyncer):
|
||||||
def convert(self, x):
|
def convert(self, x):
|
||||||
rid, run_params, timeout = x
|
rid, run_params = x
|
||||||
row = [rid, run_params["file"]]
|
row = [rid, run_params["file"]]
|
||||||
for e in run_params["unit"], timeout:
|
for e in run_params["unit"], run_params["timeout"]:
|
||||||
row.append("-" if e is None else str(e))
|
row.append("-" if e is None else str(e))
|
||||||
row.append(format_run_arguments(run_params["arguments"]))
|
row.append(format_run_arguments(run_params["arguments"]))
|
||||||
return row
|
return row
|
||||||
|
@ -24,10 +24,10 @@ class _TimedStoreSyncer(DictSyncer):
|
||||||
return (kv_pair[1][0], kv_pair[0])
|
return (kv_pair[1][0], kv_pair[0])
|
||||||
|
|
||||||
def convert(self, trid, x):
|
def convert(self, trid, x):
|
||||||
next_run, run_params, timeout = x
|
next_run, run_params = x
|
||||||
row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)),
|
row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)),
|
||||||
trid, run_params["file"]]
|
trid, run_params["file"]]
|
||||||
for e in run_params["unit"], timeout:
|
for e in run_params["unit"], run_params["timeout"]:
|
||||||
row.append("-" if e is None else str(e))
|
row.append("-" if e is None else str(e))
|
||||||
row.append(format_run_arguments(run_params["arguments"]))
|
row.append(format_run_arguments(run_params["arguments"]))
|
||||||
return row
|
return row
|
||||||
|
|
|
@ -37,14 +37,14 @@ class Scheduler:
|
||||||
del self.task
|
del self.task
|
||||||
yield from self.worker.end_process()
|
yield from self.worker.end_process()
|
||||||
|
|
||||||
def run_queued(self, run_params, timeout):
|
def run_queued(self, run_params):
|
||||||
rid = self.new_rid()
|
rid = self.new_rid()
|
||||||
self.queue.append((rid, run_params, timeout))
|
self.queue.append((rid, run_params))
|
||||||
self.queue_modified.set()
|
self.queue_modified.set()
|
||||||
return rid
|
return rid
|
||||||
|
|
||||||
def cancel_queued(self, rid):
|
def cancel_queued(self, rid):
|
||||||
idx = next(idx for idx, (qrid, _, _)
|
idx = next(idx for idx, (qrid, _)
|
||||||
in enumerate(self.queue.read)
|
in enumerate(self.queue.read)
|
||||||
if qrid == rid)
|
if qrid == rid)
|
||||||
if idx == 0:
|
if idx == 0:
|
||||||
|
@ -52,11 +52,11 @@ class Scheduler:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
del self.queue[idx]
|
del self.queue[idx]
|
||||||
|
|
||||||
def run_timed(self, run_params, timeout, next_run):
|
def run_timed(self, run_params, next_run):
|
||||||
if next_run is None:
|
if next_run is None:
|
||||||
next_run = time()
|
next_run = time()
|
||||||
trid = self.new_trid()
|
trid = self.new_trid()
|
||||||
self.timed[trid] = next_run, run_params, timeout
|
self.timed[trid] = next_run, run_params
|
||||||
self.timed_modified.set()
|
self.timed_modified.set()
|
||||||
return trid
|
return trid
|
||||||
|
|
||||||
|
@ -64,10 +64,10 @@ class Scheduler:
|
||||||
del self.timed[trid]
|
del self.timed[trid]
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _run(self, rid, run_params, timeout):
|
def _run(self, rid, run_params):
|
||||||
self.run_cb(rid, run_params)
|
self.run_cb(rid, run_params)
|
||||||
try:
|
try:
|
||||||
yield from self.worker.run(run_params, timeout)
|
yield from self.worker.run(run_params)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("RID {} failed:".format(rid))
|
print("RID {} failed:".format(rid))
|
||||||
print(e)
|
print(e)
|
||||||
|
@ -92,12 +92,12 @@ class Scheduler:
|
||||||
if min_next_run > 0:
|
if min_next_run > 0:
|
||||||
return min_next_run
|
return min_next_run
|
||||||
|
|
||||||
next_run, run_params, timeout = self.timed.read[min_trid]
|
next_run, run_params = self.timed.read[min_trid]
|
||||||
del self.timed[min_trid]
|
del self.timed[min_trid]
|
||||||
|
|
||||||
rid = self.new_rid()
|
rid = self.new_rid()
|
||||||
self.queue.insert(0, (rid, run_params, timeout))
|
self.queue.insert(0, (rid, run_params))
|
||||||
yield from self._run(rid, run_params, timeout)
|
yield from self._run(rid, run_params)
|
||||||
del self.queue[0]
|
del self.queue[0]
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -105,8 +105,8 @@ class Scheduler:
|
||||||
while True:
|
while True:
|
||||||
next_timed = yield from self._run_timed()
|
next_timed = yield from self._run_timed()
|
||||||
if self.queue.read:
|
if self.queue.read:
|
||||||
rid, run_params, timeout = self.queue.read[0]
|
rid, run_params = self.queue.read[0]
|
||||||
yield from self._run(rid, run_params, timeout)
|
yield from self._run(rid, run_params)
|
||||||
del self.queue[0]
|
del self.queue[0]
|
||||||
else:
|
else:
|
||||||
self.queue_modified.clear()
|
self.queue_modified.clear()
|
||||||
|
|
|
@ -60,13 +60,13 @@ class Worker:
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def run(self, run_params, result_timeout):
|
def run(self, run_params):
|
||||||
yield from self._send(run_params, self.send_timeout)
|
yield from self._send(run_params, self.send_timeout)
|
||||||
obj = yield from self._recv(self.start_reply_timeout)
|
obj = yield from self._recv(self.start_reply_timeout)
|
||||||
if obj != "ack":
|
if obj != "ack":
|
||||||
raise WorkerFailed("Incorrect acknowledgement")
|
raise WorkerFailed("Incorrect acknowledgement")
|
||||||
while True:
|
while True:
|
||||||
obj = yield from self._recv(result_timeout)
|
obj = yield from self._recv(run_params["timeout"])
|
||||||
action = obj["action"]
|
action = obj["action"]
|
||||||
if action == "report_completed":
|
if action == "report_completed":
|
||||||
if obj["status"] != "ok":
|
if obj["status"] != "ok":
|
||||||
|
|
|
@ -59,11 +59,10 @@ def publish_rt_results(notifier, data):
|
||||||
|
|
||||||
|
|
||||||
class Scheduler:
|
class Scheduler:
|
||||||
run_queued = make_parent_action("scheduler_run_queued",
|
run_queued = make_parent_action("scheduler_run_queued", "run_params")
|
||||||
"run_params timeout")
|
|
||||||
cancel_queued = make_parent_action("scheduler_cancel_queued", "rid")
|
cancel_queued = make_parent_action("scheduler_cancel_queued", "rid")
|
||||||
run_timed = make_parent_action("scheduler_run_timed",
|
run_timed = make_parent_action("scheduler_run_timed",
|
||||||
"run_params timeout next_run")
|
"run_params next_run")
|
||||||
cancel_timed = make_parent_action("scheduler_cancel_timed", "trid")
|
cancel_timed = make_parent_action("scheduler_cancel_timed", "trid")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,11 @@ class FloppingF(AutoDB):
|
||||||
run_params = {
|
run_params = {
|
||||||
"file": "flopping_f_simulation.py",
|
"file": "flopping_f_simulation.py",
|
||||||
"unit": None,
|
"unit": None,
|
||||||
|
"timeout": None,
|
||||||
"arguments": dict(),
|
"arguments": dict(),
|
||||||
"rtr_group": "flopping_f_simulation.py"
|
"rtr_group": "flopping_f_simulation.py"
|
||||||
}
|
}
|
||||||
self.scheduler.run_timed(run_params, None, time.time() + 20)
|
self.scheduler.run_timed(run_params, time.time() + 20)
|
||||||
|
|
||||||
def analyze(self):
|
def analyze(self):
|
||||||
popt, pcov = curve_fit(model_numpy,
|
popt, pcov = curve_fit(model_numpy,
|
||||||
|
|
Loading…
Reference in New Issue