gurudesh/pytracebugs huggingface dataset:
# Buggy code
def merge_tensor_chunks(input_tensor, ctx):
    from .executor import Executor
    from .tensor.expressions.fetch import TensorFetch

    if len(input_tensor.chunks) == 1:
        return ctx[input_tensor.chunks[0].key]

    chunks = []
    for c in input_tensor.chunks:
        op = TensorFetch(dtype=c.dtype)
        chunk = op.new_chunk(None, c.shape, index=c.index, _key=c.key)
        chunks.append(chunk)

    new_op = TensorFetch(dtype=input_tensor.dtype)
    tensor = new_op.new_tensor(
        None, input_tensor.shape, chunks=chunks, nsplits=input_tensor.nsplits
    )

    executor = Executor(storage=ctx)
    concat_result = executor.execute_tensor(tensor, concat=True)
    return concat_result[0]


# Traceback (mars.error)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, shared_memory='20M',)

In [3]: import mars.tensor as mt

In [4]: import scipy.sparse as sps

In [5]: a = sps.csr_matrix((10000, 10000))

In [6]: b = sps.csr_matrix((10000, 1))

In [7]: t1 = mt.tensor(a)

In [8]: t2 = mt.tensor(b)


In [9]: from mars.session import new_session

In [10]: cluster.session.run(t1 * t2)

Unexpected exception occurred in ChunkHolderActor.spill_size.
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
Unhandled exception in promise call
Traceback (most recent call last):
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/promise.py", line 304, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/utils.py", line 298, in _wrapped
return func(*args, **kwargs)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/worker/chunkholder.py", line 123, in spill_size
raise SpillExhausted
mars.errors.SpillExhausted
....

# Fixed code
def merge_tensor_chunks(input_tensor, ctx):
    from .executor import Executor
    from .tensor.expressions.fetch import TensorFetch

    if len(input_tensor.chunks) == 1:
        return ctx[input_tensor.chunks[0].key]

    chunks = []
    for c in input_tensor.chunks:
        op = TensorFetch(dtype=c.dtype, sparse=c.op.sparse)
        chunk = op.new_chunk(None, c.shape, index=c.index, _key=c.key)
        chunks.append(chunk)

    new_op = TensorFetch(dtype=input_tensor.dtype, sparse=input_tensor.op.sparse)
    tensor = new_op.new_tensor(
        None, input_tensor.shape, chunks=chunks, nsplits=input_tensor.nsplits
    )

    executor = Executor(storage=ctx)
    concat_result = executor.execute_tensor(tensor, concat=True)
    return concat_result[0]
# Buggy code
def main_loop(self):
    if self.args.profile == -1:
        profile_file = None
    else:
        profile_file = self.args.profile or (
            "mars_" + self.__class__.__name__ + ".prof"
        )
    try:
        if profile_file:
            import yappi

            yappi.set_clock_type("wall")
            yappi.start(builtins=False, profile_threads=False)

        with self.pool:
            try:
                self.start()
                self._running = True
                while True:
                    self.pool.join(1)
                    stopped = []
                    for idx, proc in enumerate(self.pool.processes):
                        if not proc.is_alive():
                            stopped.append(idx)
                    if stopped:
                        self.handle_process_down(stopped)
            except:
                self._running = False
                self.stop()
    finally:
        self._running = False
        if profile_file:
            import yappi

            yappi.logger = logging.getLogger(__name__)
            p = yappi.convert2pstats(yappi.get_func_stats())
            p.strip_dirs()
            p.sort_stats("time")
            p.print_stats(40)
            p.dump_stats(profile_file)


# Traceback (ValueError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 444, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 448, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 437, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 442, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 365, in mars.actors.pool.gevent_pool.Connections.connect
File "mars/actors/pool/gevent_pool.pyx", line 380, in mars.actors.pool.gevent_pool.Connections.connect
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/socket.py", line 80, in create_connection
host, port = address
ValueError: not enough values to unpack (expected 2, got 1)

# Fixed code
def main_loop(self):
    try:
        with self.pool:
            try:
                self.start()
                self._running = True
                while True:
                    self.pool.join(1)
                    stopped = []
                    for idx, proc in enumerate(self.pool.processes):
                        if not proc.is_alive():
                            stopped.append(idx)
                    if stopped:
                        self.handle_process_down(stopped)
            except:
                self._running = False
                self.stop()
    finally:
        self._running = False
# Buggy code
def _get_schedulers(self):
    schedulers = [
        s.key.rsplit("/", 1)[1] for s in self._client.read(SCHEDULER_PATH).children
    ]
    logger.debug("Schedulers obtained. Results: %r", schedulers)
    return schedulers


# Traceback (ValueError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 444, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 448, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 437, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 442, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 365, in mars.actors.pool.gevent_pool.Connections.connect
File "mars/actors/pool/gevent_pool.pyx", line 380, in mars.actors.pool.gevent_pool.Connections.connect
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/socket.py", line 80, in create_connection
host, port = address
ValueError: not enough values to unpack (expected 2, got 1)

# Fixed code
def _get_schedulers(self):
    schedulers = [
        s.key.rsplit("/", 1)[1] for s in self._client.read(SCHEDULER_PATH).children
    ]
    logger.debug("Schedulers obtained. Results: %r", schedulers)
    return [to_str(s) for s in schedulers]
# Buggy code
def watch(self):
    for new_schedulers in self._client.eternal_watch(SCHEDULER_PATH):
        self._cluster_info_ref.set_schedulers(new_schedulers)


# Traceback (ValueError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 444, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 448, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 437, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 442, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 365, in mars.actors.pool.gevent_pool.Connections.connect
File "mars/actors/pool/gevent_pool.pyx", line 380, in mars.actors.pool.gevent_pool.Connections.connect
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/socket.py", line 80, in create_connection
host, port = address
ValueError: not enough values to unpack (expected 2, got 1)

# Fixed code
def watch(self):
    for new_schedulers in self._client.eternal_watch(SCHEDULER_PATH):
        self._cluster_info_ref.set_schedulers([to_str(s) for s in new_schedulers])
# Buggy code
def _values_(self):
    return [
        getattr(self, k, None) for k in self.__slots__ if k not in self._no_copy_attrs_
    ]


# Traceback (ValueError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 444, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 448, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 437, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 442, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 365, in mars.actors.pool.gevent_pool.Connections.connect
File "mars/actors/pool/gevent_pool.pyx", line 380, in mars.actors.pool.gevent_pool.Connections.connect
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/socket.py", line 80, in create_connection
host, port = address
ValueError: not enough values to unpack (expected 2, got 1)

# Fixed code
def _values_(self):
    return [
        getattr(self, k, None) for k in self._keys_ if k not in self._no_copy_attrs_
    ]
# Buggy code
def update_key(self):
    object.__setattr__(
        self,
        "_key",
        tokenize(
            type(self),
            *(getattr(self, k, None) for k in self.__slots__ if k != "_index"),
        ),
    )


# Traceback (ValueError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 444, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 448, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 437, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 442, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 365, in mars.actors.pool.gevent_pool.Connections.connect
File "mars/actors/pool/gevent_pool.pyx", line 380, in mars.actors.pool.gevent_pool.Connections.connect
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/socket.py", line 80, in create_connection
host, port = address
ValueError: not enough values to unpack (expected 2, got 1)

# Fixed code
def update_key(self):
    object.__setattr__(
        self,
        "_key",
        tokenize(
            type(self), *(getattr(self, k, None) for k in self._keys_ if k != "_index")
        ),
    )
# Buggy code
def update_key(self):
    args = tuple(getattr(self, k, None) for k in self.__slots__)
    if self.state is None:
        args += (np.random.random(),)
    self._key = tokenize(type(self), *args)


# Traceback (ValueError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 444, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 448, in mars.actors.pool.gevent_pool.ActorRemoteHelper._send_remote
File "mars/actors/pool/gevent_pool.pyx", line 437, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 442, in mars.actors.pool.gevent_pool.ActorRemoteHelper._new_connection
File "mars/actors/pool/gevent_pool.pyx", line 365, in mars.actors.pool.gevent_pool.Connections.connect
File "mars/actors/pool/gevent_pool.pyx", line 380, in mars.actors.pool.gevent_pool.Connections.connect
File "/Users/wenjun.swj/miniconda3/lib/python3.7/site-packages/gevent/socket.py", line 80, in create_connection
host, port = address
ValueError: not enough values to unpack (expected 2, got 1)

# Fixed code
def update_key(self):
    args = tuple(getattr(self, k, None) for k in self._keys_)
    if self.state is None:
        args += (np.random.random(),)
    self._key = tokenize(type(self), *args)
# Buggy code
def execute_graph(self):
    """
    Start graph execution
    """

    def _detect_cancel(callback=None):
        if self.reload_state() == GraphState.CANCELLING:
            logger.info("Cancel detected, stopping")
            if callback:
                callback()
            else:
                self._end_time = time.time()
                self.state = GraphState.CANCELLED
            raise ExecutionInterrupted

    self._start_time = time.time()
    self.state = GraphState.PREPARING

    try:
        self.prepare_graph()
        _detect_cancel()

        self.scan_node()
        _detect_cancel()

        self.place_initial_chunks()
        _detect_cancel()

        self.create_operand_actors()
        _detect_cancel(self.stop_graph)
    except ExecutionInterrupted:
        pass
    except:
        logger.exception("Failed to start graph execution.")
        self.stop_graph()
        self.state = GraphState.FAILED
        raise


# Traceback (IndexError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 421, in prepare_graph
for n in tensor_to_tiled[tk][-1].chunks:
IndexError: list index out of range

# Fixed code
def execute_graph(self):
    """
    Start graph execution
    """

    def _detect_cancel(callback=None):
        if self.reload_state() == GraphState.CANCELLING:
            logger.info("Cancel detected, stopping")
            if callback:
                callback()
            else:
                self._end_time = time.time()
                self.state = GraphState.CANCELLED
            raise ExecutionInterrupted

    self._start_time = time.time()
    self.state = GraphState.PREPARING

    try:
        self.prepare_graph()
        _detect_cancel()

        self.scan_node()
        _detect_cancel()

        self.place_initial_chunks()
        _detect_cancel()

        self.create_operand_actors()
        _detect_cancel(self.stop_graph)
    except ExecutionInterrupted:
        pass
    except:  # noqa: E722
        logger.exception("Failed to start graph execution.")
        self.stop_graph()
        self.state = GraphState.FAILED
        raise
# Buggy code
def stop_graph(self):
    """
    Stop graph execution
    """
    from .operand import OperandActor

    if self.state == GraphState.CANCELLED:
        return
    self.state = GraphState.CANCELLING

    try:
        chunk_graph = self.get_chunk_graph()
    except (KeyError, GraphNotExists):
        self.state = GraphState.CANCELLED
        return

    for chunk in chunk_graph:
        if chunk.op.key not in self._operand_infos:
            continue
        if self._operand_infos[chunk.op.key]["state"] in (
            OperandState.READY,
            OperandState.RUNNING,
            OperandState.FINISHED,
        ):
            # we only need to stop on ready, running and finished operands
            op_uid = OperandActor.gen_uid(self._session_id, chunk.op.key)
            scheduler_addr = self.get_scheduler(op_uid)
            ref = self.ctx.actor_ref(op_uid, address=scheduler_addr)
            ref.stop_operand(_tell=True)


# Traceback (IndexError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 421, in prepare_graph
for n in tensor_to_tiled[tk][-1].chunks:
IndexError: list index out of range

# Fixed code
def stop_graph(self):
    """
    Stop graph execution
    """
    from .operand import OperandActor

    if self.state == GraphState.CANCELLED:
        return
    self.state = GraphState.CANCELLING

    try:
        chunk_graph = self.get_chunk_graph()
    except (KeyError, GraphNotExists):
        self.state = GraphState.CANCELLED
        return

    has_stopping = False
    for chunk in chunk_graph:
        if chunk.op.key not in self._operand_infos:
            continue
        if self._operand_infos[chunk.op.key]["state"] in (
            OperandState.READY,
            OperandState.RUNNING,
            OperandState.FINISHED,
        ):
            # we only need to stop on ready, running and finished operands
            op_uid = OperandActor.gen_uid(self._session_id, chunk.op.key)
            scheduler_addr = self.get_scheduler(op_uid)
            ref = self.ctx.actor_ref(op_uid, address=scheduler_addr)
            has_stopping = True
            ref.stop_operand(_tell=True)
    if not has_stopping:
        self.state = GraphState.CANCELLED
# Buggy code
def free_tensor_data(self, tensor_key):
    from .operand import OperandActor

    tiled_tensor = self._tensor_to_tiled[tensor_key][-1]
    for chunk in tiled_tensor.chunks:
        op_uid = OperandActor.gen_uid(self._session_id, chunk.op.key)
        scheduler_addr = self.get_scheduler(op_uid)
        op_ref = self.ctx.actor_ref(op_uid, address=scheduler_addr)
        op_ref.free_data(_tell=True)


# Traceback (IndexError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 421, in prepare_graph
for n in tensor_to_tiled[tk][-1].chunks:
IndexError: list index out of range

# Fixed code
def free_tensor_data(self, tensor_key):
    from .operand import OperandActor

    tiled_tensor = self._get_tensor_by_key(tensor_key)
    for chunk in tiled_tensor.chunks:
        op_uid = OperandActor.gen_uid(self._session_id, chunk.op.key)
        scheduler_addr = self.get_scheduler(op_uid)
        op_ref = self.ctx.actor_ref(op_uid, address=scheduler_addr)
        op_ref.free_data(_tell=True)
# Buggy code
def fetch_tensor_result(self, tensor_key):
    from ..worker.transfer import ResultSenderActor

    # TODO for test
    tiled_tensor = self._tensor_to_tiled[tensor_key][-1]
    if tensor_key not in self._terminated_tensors:
        return None

    ctx = dict()
    for chunk_key in [c.key for c in tiled_tensor.chunks]:
        if chunk_key in ctx:
            continue
        endpoints = self._chunk_meta_ref.get_workers(self._session_id, chunk_key)
        sender_ref = self.ctx.actor_ref(
            ResultSenderActor.default_name(), address=endpoints[-1]
        )
        ctx[chunk_key] = loads(sender_ref.fetch_data(self._session_id, chunk_key))
    return dumps(merge_tensor_chunks(tiled_tensor, ctx))


# Traceback (IndexError)
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/wenjun.swj/Code/mars/mars/scheduler/graph.py", line 421, in prepare_graph
for n in tensor_to_tiled[tk][-1].chunks:
IndexError: list index out of range

# Fixed code
def fetch_tensor_result(self, tensor_key):
    from ..worker.transfer import ResultSenderActor

    # TODO for test
    tiled_tensor = self._get_tensor_by_key(tensor_key)
    if tensor_key not in self._terminated_tensors:
        return None

    ctx = dict()
    for chunk_key in [c.key for c in tiled_tensor.chunks]:
        if chunk_key in ctx:
            continue
        endpoints = self._chunk_meta_ref.get_workers(self._session_id, chunk_key)
        sender_ref = self.ctx.actor_ref(
            ResultSenderActor.default_name(), address=endpoints[-1]
        )
        ctx[chunk_key] = loads(sender_ref.fetch_data(self._session_id, chunk_key))
    return dumps(merge_tensor_chunks(tiled_tensor, ctx))
# Buggy code
def decref(self, *keys):
    if hasattr(self._sess, "decref"):
        self._sess.decref(*keys)


# Traceback (mars.actors.errors.ActorAlreadyExist)
Creating operand actors for graph 93ba7372-e748-40ab-af14-6c250f845ba4
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 156, in execute_graph
self.create_operand_actors()
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 569, in create_operand_actors
[future.result() for future in itertools.chain(six.itervalues(op_refs), [write_future])]
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 569, in <listcomp>
[future.result() for future in itertools.chain(six.itervalues(op_refs), [write_future])]
File "src/gevent/event.py", line 457, in gevent._event.AsyncResult.result
File "src/gevent/event.py", line 381, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 399, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 379, in gevent._event.AsyncResult._raise_exception
File "/Users/hekaisheng/miniconda3/lib/python3.6/site-packages/gevent/_compat.py", line 47, in reraise
raise value.with_traceback(tb)
File "mars/actors/pool/gevent_pool.pyx", line 758, in mars.actors.pool.gevent_pool.Communicator._create_local_actor
File "mars/actors/pool/gevent_pool.pyx", line 237, in mars.actors.pool.gevent_pool.LocalActorPool.create_actor
mars.actors.errors.ActorAlreadyExist: Actor s:operator$2724de06-fc4a-11e8-8d24-47a7eeef77d5$c84e3ef10df7fabaf2dc028149609284 already exist, cannot create

# Fixed code
def decref(self, *keys):
    self._executed_keys = self._executed_keys.difference(keys)
    if hasattr(self._sess, "decref"):
        self._sess.decref(*keys)
# Buggy code
def __exit__(self, exc_type, exc_val, exc_tb):
    self.close()


# Traceback (mars.actors.errors.ActorAlreadyExist)
Creating operand actors for graph 93ba7372-e748-40ab-af14-6c250f845ba4
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 156, in execute_graph
self.create_operand_actors()
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 569, in create_operand_actors
[future.result() for future in itertools.chain(six.itervalues(op_refs), [write_future])]
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 569, in <listcomp>
[future.result() for future in itertools.chain(six.itervalues(op_refs), [write_future])]
File "src/gevent/event.py", line 457, in gevent._event.AsyncResult.result
File "src/gevent/event.py", line 381, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 399, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 379, in gevent._event.AsyncResult._raise_exception
File "/Users/hekaisheng/miniconda3/lib/python3.6/site-packages/gevent/_compat.py", line 47, in reraise
raise value.with_traceback(tb)
File "mars/actors/pool/gevent_pool.pyx", line 758, in mars.actors.pool.gevent_pool.Communicator._create_local_actor
File "mars/actors/pool/gevent_pool.pyx", line 237, in mars.actors.pool.gevent_pool.LocalActorPool.create_actor
mars.actors.errors.ActorAlreadyExist: Actor s:operator$2724de06-fc4a-11e8-8d24-47a7eeef77d5$c84e3ef10df7fabaf2dc028149609284 already exist, cannot create

# Fixed code
def __exit__(self, *_):
    self.close()
# Buggy code
def tile(cls, op):
    raise NotSupportTile("FetchChunk is a chunk operand which does not support tile")


# Traceback (AttributeError)
In [16]: a = mt.random.rand(20, 10, chunk_size=10)

In [19]: _, s, _ = mt.linalg.svd(a)

In [20]: s.build_graph(tiled=False)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-77797d4ed4a0> in <module>
----> 1 s.build_graph(tiled=False)

~/Workspace/mars/mars/tensor/core.py in build_graph(self, graph, cls, tiled, compose)
298             if not graph.contains(chunk):
299                 graph.add_node(chunk)
--> 300             children = chunk.inputs or []
301             for c in children:
302                 if not graph.contains(c):

AttributeError: 'NoneType' object has no attribute 'inputs'

# Fixed code
def tile(cls, op):
    raise NotSupportTile(
        "TensorFuseChunk is a chunk operand which does not support tile"
    )
# Buggy code
def tile(cls, op):
    q, r = op.outputs
    q_dtype, r_dtype = cls._get_obj_attr(q, "dtype"), cls._get_obj_attr(r, "dtype")
    q_shape, r_shape = cls._get_obj_attr(q, "shape"), cls._get_obj_attr(r, "shape")
    in_tensor = op.input
    if in_tensor.chunk_shape == (1, 1):
        in_chunk = in_tensor.chunks[0]
        chunk_op = op.copy().reset_key()
        qr_chunks = chunk_op.new_chunks(
            [in_chunk],
            (q_shape, r_shape),
            index=in_chunk.index,
            kws=[{"side": "q"}, {"side": "r"}],
        )
        q_chunk, r_chunk = qr_chunks

        new_op = op.copy()
        kws = [
            {"chunks": [q_chunk], "nsplits": ((1,), (1,)), "dtype": q_dtype},
            {"chunks": [r_chunk], "nsplits": ((1,), (1,)), "dtype": r_dtype},
        ]
        return new_op.new_tensors(op.inputs, [q_shape, r_shape], kws=kws)
    elif op.method == "tsqr":
        return super(TensorQR, cls).tile(op)
    # TODO(hks): support sfqr(short-and-fat qr)
    else:
        raise NotImplementedError("Only tsqr method supported for now")


# Traceback (AttributeError)
In [16]: a = mt.random.rand(20, 10, chunk_size=10)

In [19]: _, s, _ = mt.linalg.svd(a)

In [20]: s.build_graph(tiled=False)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-20-77797d4ed4a0> in <module>
----> 1 s.build_graph(tiled=False)

~/Workspace/mars/mars/tensor/core.py in build_graph(self, graph, cls, tiled, compose)
298             if not graph.contains(chunk):
299                 graph.add_node(chunk)
--> 300             children = chunk.inputs or []
301             for c in children:
302                 if not graph.contains(c):

AttributeError: 'NoneType' object has no attribute 'inputs'

# Fixed code
def tile(cls, op):
    q, r = op.outputs
    q_dtype, r_dtype = q.dtype, r.dtype
    q_shape, r_shape = q.shape, r.shape
    in_tensor = op.input
    if in_tensor.chunk_shape == (1, 1):
        in_chunk = in_tensor.chunks[0]
        chunk_op = op.copy().reset_key()
        qr_chunks = chunk_op.new_chunks(
            [in_chunk],
            (q_shape, r_shape),
            index=in_chunk.index,
            kws=[{"side": "q"}, {"side": "r"}],
        )
        q_chunk, r_chunk = qr_chunks

        new_op = op.copy()
        kws = [
            {"chunks": [q_chunk], "nsplits": ((1,), (1,)), "dtype": q_dtype},
            {"chunks": [r_chunk], "nsplits": ((1,), (1,)), "dtype": r_dtype},
        ]
        return new_op.new_tensors(op.inputs, [q_shape, r_shape], kws=kws)
    elif op.method == "tsqr":
        return super(TensorQR, cls).tile(op)
    # TODO(hks): support sfqr(short-and-fat qr)
    else:
        raise NotImplementedError("Only tsqr method supported for now")
# Buggy code
def _index_set_value(ctx, chunk):
    indexes = [
        ctx[index.key] if hasattr(index, "key") else index for index in chunk.op.indexes
    ]
    input = ctx[chunk.inputs[0].key]
    value = (
        ctx[chunk.op.value.key] if hasattr(chunk.op.value, "key") else chunk.op.value
    )
    if hasattr(input, "flags") and not input.flags.writeable:
        input.setflags(write=True)
    input[tuple(indexes)] = value
    ctx[chunk.key] = input


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def _index_set_value(ctx, chunk):
    indexes = [
        ctx[index.key] if hasattr(index, "key") else index for index in chunk.op.indexes
    ]
    input = ctx[chunk.inputs[0].key].copy()
    value = (
        ctx[chunk.op.value.key] if hasattr(chunk.op.value, "key") else chunk.op.value
    )
    if hasattr(input, "flags") and not input.flags.writeable:
        input.setflags(write=True)
    input[tuple(indexes)] = value
    ctx[chunk.key] = input
# Buggy code
def new_tensors(self, inputs, shape, **kw):
    tensor, indexes = inputs
    self._indexes = indexes
    inputs = self._handle_inputs(inputs)
    return super(TensorIndex, self).new_tensors(inputs, shape, **kw)


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def new_tensors(self, inputs, shape, **kw):
    indexes = kw.pop("indexes", None)
    with self._handle_params(inputs, indexes) as mix_inputs:
        return super(TensorIndex, self).new_tensors(mix_inputs, shape, **kw)
# Buggy code
def new_chunks(self, inputs, shape, **kw):
    chunk, indexes = inputs
    self._indexes = indexes
    inputs = self._handle_inputs(inputs)
    return super(TensorIndex, self).new_chunks(inputs, shape, **kw)


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def new_chunks(self, inputs, shape, **kw):
    indexes = kw.pop("indexes", None)
    with self._handle_params(inputs, indexes) as mix_inputs:
        return super(TensorIndex, self).new_chunks(mix_inputs, shape, **kw)
# Buggy code
def __call__(self, a, index, shape):
    return self.new_tensor([a, index], shape)


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def __call__(self, a, index, shape):
    return self.new_tensor([a], shape, indexes=index)
# Buggy code
def new_tensors(self, inputs, shape, **kw):
    tensor, indexes, value = inputs
    self._indexes = indexes
    self._value = value
    inputs = self._handle_inputs(inputs)
    return super(TensorIndexSetValue, self).new_tensors(inputs, shape, **kw)


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def new_tensors(self, inputs, shape, **kw):
    indexes = kw.pop("indexes", None)
    value = kw.pop("value", None)
    with self._handle_params(inputs, indexes, value) as mix_inputs:
        return super(TensorIndexSetValue, self).new_tensors(mix_inputs, shape, **kw)
# Buggy code
def new_chunks(self, inputs, shape, **kw):
    chunk, indexes, value = inputs
    self._indexes = indexes
    self._value = value
    inputs = self._handle_inputs(inputs)
    return super(TensorIndexSetValue, self).new_chunks(inputs, shape, **kw)


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def new_chunks(self, inputs, shape, **kw):
    indexes = kw.pop("indexes", None)
    value = kw.pop("value", None)
    with self._handle_params(inputs, indexes, value) as mix_inputs:
        return super(TensorIndexSetValue, self).new_chunks(mix_inputs, shape, **kw)
# Buggy code
def __call__(self, a, index, value):
    return self.new_tensor([a, index, value], a.shape)


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def __call__(self, a, index, value):
    return self.new_tensor([a], a.shape, indexes=index, value=value)
# Buggy code
def execute(self, session=None, n_parallel=None):
    from ..session import Session

    if session is None:
        session = Session.default_or_local()
    return session.run(*self, n_parallel=n_parallel)


# Traceback (TypeError)
n [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.linalg.svd(t).execute()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-7615968c966e> in <module>()
----> 1 mt.linalg.svd(t).execute()

~/Documents/mars_dev/mars/mars/tensor/core.py in execute(self, session, n_parallel)
466         if session is None:
467             session = Session.default_or_local()
--> 468         return session.run(*self, n_parallel=n_parallel)
469
470

~/Documents/mars_dev/mars/mars/session.py in run(self, *tensors, **kw)
81
82         tensors = tuple(mt.tensor(t) for t in tensors)
---> 83         result = self._sess.run(*tensors, **kw)
84         self._executed_keys.update(t.key for t in tensors)
85         for t in tensors:

~/Documents/mars_dev/mars/mars/deploy/local/session.py in run(self, *tensors, **kw)
47         timeout = kw.pop('timeout', -1)
48         if kw:
---> 49             raise TypeError('run got unexpected key arguments {0}'.format(', '.join(kw.keys())))
50
51         graph = DirectedGraph()

TypeError: run got unexpected key arguments n_parallel

# Fixed code
def execute(self, session=None, **kw):
    from ..session import Session

    if session is None:
        session = Session.default_or_local()
    return session.run(*self, **kw)