def test_all_schedulers(): for scheduler in (ThreadedScheduler(max_threads=8), LinearizedScheduler(), NaiveScheduler()): for wf_scheduler in (ThreadedScheduler(max_threads=8), LinearizedScheduler(), NaiveScheduler()): for case in (_call_workflow, _run_workflow, _test_workflow_chain): yield case, scheduler, wf_scheduler
def test_map_run(): func = lambda x: x * 2 inp = range(5) map_act = Map(FuncActor, args=(func, ), kwargs={'inports': ('inp', )}, scheduler=LinearizedScheduler()) map_act.inports.inp.put(inp) result = map_act.run() assert all(a == b for a, b in zip_longest(result['out'], map(func, inp)))
def test_map_multiport(): actor_class = ConstructorWrapper(FuncActor, swap, inports=('a', 'b'), outports=('a', 'b')) amap = Map(actor_class, scheduler=LinearizedScheduler()) inputs = dict(a=[1, 2], b=[10, 20]) res = amap(**inputs) print(res) assert_sequence_equal(res['a'], inputs['b'])
def test_map_linear(): ra = FuncActor(range) func = math.sin map_act = Map(FuncActor, args=(func, )) map_act.inports['inp'] += ra.outports['out'] wf = ra.get_workflow() sch = LinearizedScheduler() inp = 5 sch.run_workflow(wf, inp=inp) result = wf.outports.out.pop_all() assert len(result) == 1 assert all((a, b) for a, b in zip_longest(result[0], map(func, range(inp))))
def test_map_shell(): from wowp.actors import ShellRunner cmd = "echo {number}" sch = LinearizedScheduler() map_actor = Map(ShellRunner, args=(cmd, ), kwargs=dict(shell=True, format_inp='kwargs', single_out=True), scheduler=sch) # TODO Map needs a single output # possible solution -> specify output (and input) port for Map n = 5 inp = [{'number': i} for i in range(n)] res = map_actor(inp=inp) assert all((a == b for a, b in zip( (int(d['stdout'].strip()) for d in res['out']), range(n))))
def test_LinearizedScheduler_loop1000(): def condition(x): return x < 1000 def func(x): return x + 1 scheduler = LinearizedScheduler() fa = FuncActor(func, outports=('x', )) lw = LoopWhile("a_loop", condition) fa.inports['x'] += lw.outports['loop'] lw.inports['loop'] += fa.outports['x'] scheduler.put_value(lw.inports['init'], 0) scheduler.execute() result = lw.outports['exit'].pop() assert (result == 1000)
for i in range(max_): scheduler.put_value(orig_actor.inports["x"], i) scheduler.execute() new_sequence = list(new_actor.outports['x'].pop_all()) try: assert new_sequence == original_sequence except AssertionError: print("Received: ", new_sequence) print("Expected: ", original_sequence) raise if __name__ == '__main__': # TODO use pytest + fixtures (get inspired by ipyparallel tests) tests = ( _run_tree_512_test, lambda scheduler: _run_linearity_test(scheduler, size=100, ntimes=5), ) logger.level = 20 for case in (tests): print('testing {}'.format(case)) for scheduler in (LinearizedScheduler(), FuturesScheduler('distributed'), FuturesScheduler('ipyparallel', timeout=1), ): # FuturesScheduler('multiprocessing'), ): print('using {}'.format(type(scheduler))) case(scheduler)
def test_all_schedulers(): for scheduler in (ThreadedScheduler(max_threads=8), LinearizedScheduler()): for case in (_run_tree_512_test, _run_linearity_test): yield case, scheduler