Skip to content

SequenceLearner with unhashable entries in sequence break Runner #265

Open
@basnijholt

Description

@basnijholt

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

adaptive/adaptive/runner.py

Lines 204 to 210 in 0f85d3a

except Exception as e:
self.tracebacks[x] = traceback.format_exc()
self.to_retry[x] = self.to_retry.get(x, 0) + 1
if self.to_retry[x] > self.retries:
self.to_retry.pop(x)
if self.raise_if_retries_exceeded:
self._do_raise(e, x)

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions