def test_get_subgraph_blocks(): total_read_roi = Roi((0, 0), (16, 16)) block_read_roi = Roi((0, 0), (4, 4)) block_write_roi = Roi((1, 1), (2, 2)) sub_roi = Roi((6, 6), (3, 3)) graph = BlockwiseDependencyGraph( "test", block_read_roi, block_write_roi, True, "valid", total_read_roi=total_read_roi, ) blocks = graph.get_subgraph_blocks(sub_roi) expected_blocks = [ Block( total_read_roi, Roi((4, 4), (4, 4)), Roi((5, 5), (2, 2)), task_id="test", ), Block( total_read_roi, Roi((6, 4), (4, 4)), Roi((7, 5), (2, 2)), task_id="test", ), Block( total_read_roi, Roi((4, 6), (4, 4)), Roi((5, 7), (2, 2)), task_id="test", ), Block( total_read_roi, Roi((6, 6), (4, 4)), Roi((7, 7), (2, 2)), task_id="test", ), ] assert set(blocks) == set(expected_blocks)
def test_check_function(self): step_name = 'predict' roi = Roi((0, 0, 0, 0), (10, 10, 10, 10)) block = Block(roi, roi, roi) self.assertFalse(check_function( block, step_name, self.db_name, self.db_host)) write_done(block, step_name, self.db_name, self.db_host) self.assertTrue(check_function( block, step_name, self.db_name, self.db_host))
def test_simple_acquire_block(task_1d): scheduler = Scheduler([task_1d]) block = scheduler.acquire_block(task_1d.task_id) expected_block = Block(Roi((1, ), (3, )), Roi((1, ), (3, )), Roi((2, ), (1, )), task_id="test_1d", block_id=2) assert block.read_roi == expected_block.read_roi assert block.write_roi == expected_block.write_roi assert block.block_id == expected_block.block_id
def test_simple_release_block(task_1d): scheduler = Scheduler([task_1d]) block = scheduler.acquire_block(task_1d.task_id) block.status = BlockStatus.SUCCESS scheduler.release_block(block) block = scheduler.acquire_block(task_1d.task_id) expected_block = Block(Roi((0, ), (3, )), Roi((0, ), (3, )), Roi((1, ), (1, )), task_id="test_1d", block_id=1) assert block.read_roi == expected_block.read_roi assert block.write_roi == expected_block.write_roi assert block.block_id == expected_block.block_id
def test_simple_no_conflicts(task_no_conflicts): scheduler = Scheduler([task_no_conflicts]) block = scheduler.acquire_block(task_no_conflicts.task_id) expected_block = Block(Roi((0, ), (3, )), Roi((0, ), (3, )), Roi((1, ), (1, )), task_id="test_1d", block_id=1) assert block.read_roi == expected_block.read_roi assert block.write_roi == expected_block.write_roi assert block.block_id == expected_block.block_id block = scheduler.acquire_block(task_no_conflicts.task_id) expected_block = Block(Roi((1, ), (3, )), Roi((1, ), (3, )), Roi((2, ), (1, )), task_id="test_1d", block_id=2) assert block.read_roi == expected_block.read_roi assert block.write_roi == expected_block.write_roi assert block.block_id == expected_block.block_id
def test_upstream(chained_task): first_task, second_task = chained_task scheduler = Scheduler([second_task]) test_block = Block( Roi((0, 0), (6, 6)), Roi((2, 2), (3, 3)), Roi((3, 3), (1, 1)), task_id=first_task.task_id, ) downstream_blocks = scheduler.dependency_graph.downstream(test_block) downstream_ids = set([block.block_id for block in downstream_blocks]) assert downstream_ids == set([ ("second", 4), ("second", 7), ("second", 8), ("second", 12), ])
def test_downstream(chained_task): first_task, second_task = chained_task scheduler = Scheduler([second_task]) test_block = Block( Roi((1, 1), (4, 4)), Roi((2, 2), (3, 3)), Roi((3, 3), (1, 1)), task_id=second_task.task_id, ) upstream_blocks = scheduler.dependency_graph.upstream(test_block) upstream_ids = set([block.block_id for block in upstream_blocks]) assert upstream_ids == set([ ("first", 12), ("first", 17), ("first", 23), ("first", 18), ("first", 24), ("first", 31), ("first", 25), ("first", 32), ("first", 40), ])