Пример #1
0
def split_in_balancing_learners(
    learners: List[adaptive.BaseLearner],
    fnames: List[str],
    n_parts: int,
    strategy: str = "npoints",
) -> Tuple[List[adaptive.BaseLearner], List[str]]:
    r"""Split a list of learners and fnames into `adaptive.BalancingLearner`\s.

    Parameters
    ----------
    learners : list
        List of learners.
    fnames : list
        List of filenames.
    n_parts : int
        Total number of `~adaptive.BalancingLearner`\s.
    strategy : str
        Learning strategy of the `~adaptive.BalancingLearner`.

    Returns
    -------
    new_learners, new_fnames
    """
    new_learners = []
    new_fnames = []
    for x in split(zip(learners, fnames), n_parts):
        learners_part, fnames_part = zip(*x)
        learner = adaptive.BalancingLearner(learners_part, strategy=strategy)
        new_learners.append(learner)
        new_fnames.append(fnames_part)
    return new_learners, new_fnames
Пример #2
0
def runners_in_executor(learners,
                        client,
                        nrunners,
                        goal=None,
                        interval=3600,
                        save_kwargs=default_save_kwargs,
                        client_kwargs=default_client_kwargs):
    if goal is None and interval == 0:
        raise Exception('Turn on periodic saving if there is no goal.')

    futs = []
    split_leaners = split(learners, nrunners)
    split_targets = split(range(nrunners, len(client)), nrunners)
    for i, (_learners, targets) in enumerate(zip(split_leaners,
                                                 split_targets)):
        learner = adaptive.BalancingLearner(_learners)
        fut = client[i].executor.submit(run_learner_in_ipyparallel_client,
                                        learner, goal, interval, save_kwargs,
                                        client_kwargs, targets)
        futs.append(fut)
    return futs