File tree 1 file changed +22
-1
lines changed
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
import random
2
+ import time
2
3
3
4
import flaky
4
5
import numpy as np
5
6
6
7
from adaptive .learner import Learner1D
7
8
from adaptive .learner .learner1D import curvature_loss_function
8
- from adaptive .runner import simple
9
+ from adaptive .runner import BlockingRunner , simple
9
10
10
11
11
12
def test_pending_loss_intervals ():
@@ -389,3 +390,23 @@ def f(x):
389
390
390
391
learner = Learner1D (f , bounds = (- 1 , 1 ))
391
392
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
You can’t perform that action at this time.
0 commit comments