Skip to content

Commit e07416d

Browse files
committed
test test_inf_loss_with_missing_bounds
1 parent 4bf9aff commit e07416d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

adaptive/tests/test_learner1d.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import random
2+
import time
23

34
import flaky
45
import numpy as np
56

67
from adaptive.learner import Learner1D
78
from adaptive.learner.learner1D import curvature_loss_function
8-
from adaptive.runner import simple
9+
from adaptive.runner import BlockingRunner, simple
910

1011

1112
def test_pending_loss_intervals():
@@ -389,3 +390,23 @@ def f(x):
389390

390391
learner = Learner1D(f, bounds=(-1, 1))
391392
simple(learner, lambda l: l.npoints > 100)
393+
394+
395+
def test_inf_loss_with_missing_bounds():
396+
def flat_middle(x):
397+
x *= 1e7
398+
xs = np.array([0.0, 0.1, 0.9, 1.0])
399+
ys = [0, 1, 1, 0]
400+
if x < xs[1] or x > xs[-2]:
401+
time.sleep(1)
402+
return np.interp(x, xs, ys)
403+
404+
learner = Learner1D(
405+
flat_middle,
406+
bounds=(0, 1e-7),
407+
loss_per_interval=curvature_loss_function(),
408+
)
409+
# must be done in parallel because otherwise the bounds will be evaluated first
410+
BlockingRunner(learner, goal=lambda learner: learner.loss() < 0.01)
411+
412+
learner.npoints > 20

0 commit comments

Comments
 (0)