Skip to content

Commit 6e29e2c

Browse files
committed
1 parent b0c1bf8 commit 6e29e2c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

adaptive/learner/sequence_learner.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from copy import copy
21
import sys
2+
import warnings
3+
from copy import copy
34

45
from adaptive.learner.base_learner import BaseLearner
56

@@ -11,7 +12,13 @@ def ensure_hashable(x):
1112
hash(x)
1213
return x
1314
except TypeError:
14-
return tuple(x)
15+
msg = "The items in `sequence` need to be hashable, {}. Make sure you reflect this in your function."
16+
if isinstance(x, dict):
17+
warnings.warn(msg.format("we converted `dict` to `tuple(dict.items())`"))
18+
return tuple(x.items())
19+
else:
20+
warnings.warn(msg.format("we tried to cast the items to a tuple"))
21+
return tuple(x)
1522

1623

1724
class SequenceLearner(BaseLearner):
@@ -26,13 +33,11 @@ def __init__(self, function, sequence):
2633
def ask(self, n, tell_pending=True):
2734
points = []
2835
loss_improvements = []
29-
i = 0
3036
for point in self._to_do_seq:
31-
if i > n:
37+
if len(points) >= n:
3238
break
3339
points.append(point)
3440
loss_improvements.append(inf / self._npoints)
35-
i += 1
3641

3742
if tell_pending:
3843
for p in points:

0 commit comments

Comments
 (0)