adaptive icon indicating copy to clipboard operation
adaptive copied to clipboard

SequenceLearner with unhashable entries in sequence break Runner

Open basnijholt opened this issue 5 years ago • 0 comments
trafficstars

When a SequenceLearner that has unhashable entries in sequence (e.g., List[dict]) fails, the Runner breaks.

This happens because of the dict[x] in https://github.com/python-adaptive/adaptive/blob/0f85d3abd1cb0eddf195dec0deabd6d0dd97d268/adaptive/runner.py#L204-L210

Reproduce with:

import adaptive
import numpy as np

adaptive.notebook_extension()

def f(dct):
    import random

    if random.random() < 0.5:
        raise Exception()
    return dct["x"]


seq = [dict(x=x) for x in np.linspace(-1, 1, 101)]  # unhashable

learner = adaptive.SequenceLearner(f, sequence=seq)

runner = adaptive.Runner(learner, goal=adaptive.SequenceLearner.done)
runner.live_info()
runner.task.print_stack()

traceback

Traceback for <Task finished name='Task-3' coro=<AsyncRunner._run() done, defined at /Users/basnijholt/Work/adaptive/adaptive/runner.py:601> exception=TypeError("unhashable type: 'dict'")> (most recent call last):
TypeError: unhashable type: 'dict'
  File "/Users/basnijholt/Work/adaptive/adaptive/runner.py", line 555, in status
    return "failed"
  File "/Users/basnijholt/Work/adaptive/adaptive/runner.py", line 555, in status
    return "failed"
  File "/Users/basnijholt/Work/adaptive/adaptive/runner.py", line 618, in _run
    self._cleanup()
  File "/Users/basnijholt/Work/adaptive/adaptive/runner.py", line 210, in _process_futures
    self._do_raise(e, x)

basnijholt avatar Apr 14 '20 14:04 basnijholt