def test_stop_after_goal(): seconds_to_wait = 0.2 # don't make this too large or the test will take ages start_time = time.time() BlockingRunner(Learner1D(linear, (-1, 1)), stop_after(seconds=seconds_to_wait)) stop_time = time.time() assert stop_time - start_time > seconds_to_wait
def test_loky_executor(loky_executor): learner = Learner1D(lambda x: x, (-1, 1)) BlockingRunner(learner, trivial_goal, executor=loky_executor, shutdown_executor=True) assert learner.npoints > 0
def test_learnerND_curvature_runs_to_10_points_Blocking(execution_number): loss = curvature_loss_function() learner = LearnerND(ring_of_fire, bounds=[(-1, 1), (-1, 1)], loss_per_simplex=loss) BlockingRunner(learner, goal=lambda l: l.npoints >= 10) assert learner.npoints >= 10
def test_concurrent_futures_executor(): from concurrent.futures import ProcessPoolExecutor BlockingRunner( Learner1D(linear, (-1, 1)), trivial_goal, executor=ProcessPoolExecutor(max_workers=1), )
def test_distributed_executor(): from distributed import Client learner = Learner1D(linear, (-1, 1)) client = Client(n_workers=1) BlockingRunner(learner, trivial_goal, executor=client) client.shutdown() assert learner.npoints > 0
def test_ipyparallel_executor(): from ipyparallel import Client if OPERATING_SYSTEM == "Windows": import wexpect as expect else: import pexpect as expect child = expect.spawn("ipcluster start -n 1") child.expect("Engines appear to have started successfully", timeout=35) ipyparallel_executor = Client() learner = Learner1D(linear, (-1, 1)) BlockingRunner(learner, trivial_goal, executor=ipyparallel_executor) assert learner.npoints > 0 if not child.terminate(force=True): raise RuntimeError("Could not stop ipcluster")
def test_ipyparallel_executor(ipyparallel_executor): learner = Learner1D(linear, (-1, 1)) BlockingRunner(learner, trivial_goal, executor=ipyparallel_executor) assert learner.npoints > 0
def blocking_runner(learner, goal): BlockingRunner(learner, goal, executor=SequentialExecutor())
def test_distributed_executor(dask_executor): learner = Learner1D(linear, (-1, 1)) BlockingRunner(learner, trivial_goal, executor=dask_executor) assert learner.npoints > 0
def test_learnerND_runs_to_10_points_Blocking(execution_number): learner = LearnerND(ring_of_fire, bounds=[(-1, 1), (-1, 1)]) BlockingRunner(learner, goal=lambda l: l.npoints >= 10) assert learner.npoints >= 10