basnijholt / adaptive-scheduler

Run many functions (adaptively) on many cores (>10k-100k) using mpi4py.futures, ipyparallel, loky, or dask-mpi. :tada:
http://adaptive-scheduler.readthedocs.io
BSD 3-Clause "New" or "Revised" License
26 stars 10 forks source link

Add a SequentialExecutor based on ProcessPoolExecutor #232

Closed basnijholt closed 3 months ago

basnijholt commented 3 months ago

test with e.g.,


class SequentialExecutor(ProcessPoolExecutor):
    """A asynchronous executor that runs tasks sequentially."""

    def __init__(self) -> None:
        super().__init__(max_workers=1)

def burn():
    import numpy as np
    np.linalg.eigvals(np.random.rand(1000, 1000))

def f(x):
    with ProcessPoolExecutor() as executor:
        future = executor.submit(burn)
        future.result()
    return x**2

learner = adaptive.Learner1D(f, bounds=(-1, 1))
runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.1, executor=SequentialExecutor())
runner.live_info()