# Buggy code
def tile(cls, op):
    ctx = get_context()
    if ctx.running_mode != RunningMode.distributed:
        assert all(len(inp.chunks) == 1 for inp in op.inputs)

        chunk_op = op.copy().reset_key()
        out_chunk = chunk_op.new_chunk(
            [inp.chunks[0] for inp in op.inputs], shape=(1,), index=(0,)
        )
        new_op = op.copy()
        return new_op.new_tileables(op.inputs, chunks=[out_chunk], nsplits=((1,),))
    else:
        inp = op.inputs[0]
        in_chunks = inp.chunks
        workers = cls._get_dmatrix_chunks_workers(ctx, inp)
        tracker_chunk = StartTracker(n_workers=len(in_chunks)).new_chunk(
            in_chunks, shape=()
        )
        out_chunks = []
        worker_to_evals = defaultdict(list)
        if op.evals is not None:
            for dm, ev in op.evals:
                worker_to_chunk = cls._get_dmatrix_worker_to_chunk(dm, workers, ctx)
                for worker, chunk in worker_to_chunk.items():
                    worker_to_evals[worker].append((chunk, ev))
        for in_chunk, worker in zip(in_chunks, workers):
            chunk_op = op.copy().reset_key()
            chunk_op._expect_worker = worker
            chunk_op._tracker = tracker_chunk
            chunk_evals = list(worker_to_evals.get(worker, list()))
            chunk_op._evals = chunk_evals
            input_chunks = (
                [in_chunk] + [pair[0] for pair in chunk_evals] + [tracker_chunk]
            )
            out_chunk = chunk_op.new_chunk(
                input_chunks, shape=(np.nan,), index=in_chunk.index[:1]
            )
            out_chunks.append(out_chunk)

        new_op = op.copy()
        return new_op.new_tileables(
            op.inputs, chunks=out_chunks, nsplits=((np.nan for _ in out_chunks),)
        )


# Traceback (TimeoutError)
2021-01-26 15:39:43,801 mars.scheduler.operands.base 474 DEBUG    Operand e3036e9fb2b4f84911306f8fa9cf3e03(StartTracker) state from OperandState.UNSCHEDULED to OperandState.READY.
2021-01-26 15:39:43,802 mars.scheduler.assigner 476 DEBUG    Operand e3036e9fb2b4f84911306f8fa9cf3e03 enqueued

2021-01-26 15:49:43,403 mars.scheduler.assigner 473 ERROR    Unexpected exception occurred in AssignEvaluationActor._allocate_resource. op_key=e3036e9fb2b4f84911306f8fa9cf3e03
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.6.2.zip/mars/utils.py", line 377, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 414, in _allocate_resource
raise TimeoutError(f'Assign resources to operand {op_key} timed out')
TimeoutError: Assign resources to operand e3036e9fb2b4f84911306f8fa9cf3e03 timed out
2021-01-26 15:49:43,404 mars.scheduler.assigner 473 ERROR    Unexpected error occurred in s:0:AssignEvaluationActor$eb2a35c62f8cfb405cc15245e0d1cf02
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 315, in allocate_top_resources
reject_workers=reject_workers)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/utils.py", line 377, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 414, in _allocate_resource
raise TimeoutError(f'Assign resources to operand {op_key} timed out')
TimeoutError: Assign resources to operand e3036e9fb2b4f84911306f8fa9cf3e03 timed out
2021-01-26 15:49:43,407 mars.scheduler.operands.common 474 ERROR    Attempt 1: Unexpected error TimeoutError occurred in executing operand e3036e9fb2b4f84911306f8fa9cf3e03 in None
Traceback (most recent call last):
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 315, in allocate_top_resources
reject_workers=reject_workers)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/utils.py", line 377, in _wrapped
return func(*args, **kwargs)
File "/home/admin/work/_public-mars-0.6.2.zip/mars/scheduler/assigner.py", line 414, in _allocate_resource
raise TimeoutError(f'Assign resources to operand {op_key} timed out')
TimeoutError: Assign resources to operand e3036e9fb2b4f84911306f8fa9cf3e03 timed out

# Fixed code
def tile(cls, op):
    ctx = get_context()
    if ctx.running_mode != RunningMode.distributed:
        assert all(len(inp.chunks) == 1 for inp in op.inputs)

        chunk_op = op.copy().reset_key()
        out_chunk = chunk_op.new_chunk(
            [inp.chunks[0] for inp in op.inputs], shape=(1,), index=(0,)
        )
        new_op = op.copy()
        return new_op.new_tileables(op.inputs, chunks=[out_chunk], nsplits=((1,),))
    else:
        inp = op.inputs[0]
        in_chunks = inp.chunks
        workers = cls._get_dmatrix_chunks_workers(ctx, inp)
        n_chunk = len(in_chunks)
        tracker_chunk = StartTracker(
            n_workers=n_chunk, pure_depends=[True] * n_chunk
        ).new_chunk(in_chunks, shape=())
        out_chunks = []
        worker_to_evals = defaultdict(list)
        if op.evals is not None:
            for dm, ev in op.evals:
                worker_to_chunk = cls._get_dmatrix_worker_to_chunk(dm, workers, ctx)
                for worker, chunk in worker_to_chunk.items():
                    worker_to_evals[worker].append((chunk, ev))
        for in_chunk, worker in zip(in_chunks, workers):
            chunk_op = op.copy().reset_key()
            chunk_op._expect_worker = worker
            chunk_op._tracker = tracker_chunk
            chunk_evals = list(worker_to_evals.get(worker, list()))
            chunk_op._evals = chunk_evals
            input_chunks = (
                [in_chunk] + [pair[0] for pair in chunk_evals] + [tracker_chunk]
            )
            out_chunk = chunk_op.new_chunk(
                input_chunks, shape=(np.nan,), index=in_chunk.index[:1]
            )
            out_chunks.append(out_chunk)

        new_op = op.copy()
        return new_op.new_tileables(
            op.inputs, chunks=out_chunks, nsplits=((np.nan for _ in out_chunks),)
        )