File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import random
2+ import time
23
34import flaky
45import numpy as np
56
67from adaptive .learner import Learner1D
78from adaptive .learner .learner1D import curvature_loss_function
8- from adaptive .runner import simple
9+ from adaptive .runner import BlockingRunner , simple
910
1011
1112def 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
You can’t perform that action at this time.
0 commit comments