コード例 #1
0
ファイル: __init__.py プロジェクト: 5l1v3r1/orion-1
def workon(experiment, worker_trials=None):
    """Try to find solution to the search problem defined in `experiment`."""
    producer = Producer(experiment)
    consumer = Consumer(experiment)

    log.debug("#####  Init Experiment  #####")
    try:
        iterator = range(int(worker_trials))
    except (OverflowError, TypeError):
        # When worker_trials is inf
        iterator = itertools.count()

    for _ in iterator:
        log.debug("#### Poll for experiment termination.")
        if experiment.is_broken:
            log.info(
                "#### Experiment has reached broken trials threshold, terminating."
            )
            return

        if experiment.is_done:
            break

        log.debug("#### Try to reserve a new trial to evaluate.")
        trial = reserve_trial(experiment, producer)

        if trial is not None:
            log.debug(
                "#### Successfully reserved %s to evaluate. Consuming...",
                trial)
            consumer.consume(trial)

    stats = experiment.stats

    if not stats:
        log.info("No trials completed.")
        return

    best = get_storage().get_trial(uid=stats['best_trials_id'])

    stats_stream = io.StringIO()
    pprint.pprint(stats, stream=stats_stream)
    stats_string = stats_stream.getvalue()

    best_stream = io.StringIO()
    pprint.pprint(best.to_dict()['params'], stream=best_stream)
    best_string = best_stream.getvalue()

    log.info("#####  Search finished successfully  #####")
    log.info("\nRESULTS\n=======\n%s\n", stats_string)
    log.info("\nBEST PARAMETERS\n===============\n%s", best_string)
コード例 #2
0
ファイル: __init__.py プロジェクト: vishalbelsare/orion
def workon(experiment):
    """Try to find solution to the search problem defined in `experiment`."""
    producer = Producer(experiment)
    consumer = Consumer(experiment)

    log.debug("#####  Init Experiment  #####")
    while True:
        log.debug("#### Try to reserve a new trial to evaluate.")
        trial = experiment.reserve_trial(score_handle=producer.algorithm.score)

        if trial is None:
            log.debug("#### Failed to pull a new trial from database.")

            log.debug(
                "#### Fetch most recent completed trials and update algorithm."
            )
            producer.update()

            log.debug("#### Poll for experiment termination.")
            if experiment.is_done:
                break

            log.debug("#### Produce new trials.")
            producer.produce()

        else:
            log.debug(
                "#### Successfully reserved %s to evaluate. Consuming...",
                trial)
            consumer.consume(trial)

    stats = experiment.stats
    best = Database().read('trials', {'_id': stats['best_trials_id']})[0]

    stats_stream = io.StringIO()
    pprint.pprint(stats, stream=stats_stream)
    stats_string = stats_stream.getvalue()

    best_stream = io.StringIO()
    pprint.pprint(best['params'], stream=best_stream)
    best_string = best_stream.getvalue()

    log.info("#####  Search finished successfully  #####")
    log.info("\nRESULTS\n=======\n%s\n", stats_string)
    log.info("\nBEST PARAMETERS\n===============\n%s", best_string)
コード例 #3
0
def workon(
    experiment,
    n_workers=None,
    pool_size=None,
    max_trials=None,
    max_broken=None,
    max_idle_time=None,
    reservation_timeout=None,
    heartbeat=None,
    user_script_config=None,
    interrupt_signal_code=None,
    ignore_code_changes=None,
    executor=None,
    executor_configuration=None,
    idle_timeout=None,
):
    """Try to find solution to the search problem defined in `experiment`."""

    # NOTE: Remove in v0.3.0
    if max_idle_time is not None and reservation_timeout is None:
        reservation_timeout = max_idle_time

    producer = Producer(experiment)
    consumer = Consumer(
        experiment,
        user_script_config,
        interrupt_signal_code,
        ignore_code_changes,
    )

    client = ExperimentClient(experiment, producer, heartbeat=heartbeat)

    if executor is None:
        executor = orion.core.config.worker.executor

    if executor_configuration is None:
        executor_configuration = orion.core.config.worker.executor_configuration

    log.debug("Starting workers")
    with client.tmp_executor(executor,
                             n_workers=n_workers,
                             **executor_configuration):
        try:
            client.workon(
                consumer,
                n_workers=n_workers,
                pool_size=pool_size,
                reservation_timeout=reservation_timeout,
                max_trials_per_worker=max_trials,
                max_broken=max_broken,
                trial_arg="trial",
                on_error=on_error,
                idle_timeout=idle_timeout,
            )
        except BrokenExperiment as e:
            print(e)

    if client.is_done:
        print("Search finished successfully")

    print("\n" + format_stats(client))

    print("\n" + COMPLETION_MESSAGE.format(experiment=client))
    if not experiment.is_done:
        print(NONCOMPLETED_MESSAGE.format(experiment=client))
コード例 #4
0
def workon(
    experiment,
    max_trials=None,
    max_broken=None,
    max_idle_time=None,
    heartbeat=None,
    user_script_config=None,
    interrupt_signal_code=None,
    ignore_code_changes=None,
):
    """Try to find solution to the search problem defined in `experiment`."""
    producer = Producer(experiment, max_idle_time)
    consumer = Consumer(
        experiment,
        heartbeat,
        user_script_config,
        interrupt_signal_code,
        ignore_code_changes,
    )

    log.debug("#####  Init Experiment  #####")
    try:
        iterator = range(int(max_trials))
    except (OverflowError, TypeError):
        # When worker_trials is inf
        iterator = itertools.count()

    worker_broken_trials = 0
    for _ in iterator:
        log.debug("#### Poll for experiment termination.")
        if experiment.is_broken:
            print(
                "#### Experiment has reached broken trials threshold, terminating."
            )
            break

        if experiment.is_done:
            print("#####  Search finished successfully  #####")
            break

        log.debug("#### Try to reserve a new trial to evaluate.")
        try:
            trial = reserve_trial(experiment, producer)
        except WaitingForTrials as ex:
            print(
                "### Experiment failed to reserve new trials: {reason}, terminating. "
                .format(reason=str(ex)))
            break

        if trial is not None:
            log.info("#### Successfully reserved %s to evaluate. Consuming...",
                     trial)
            success = consumer.consume(trial)
            if not success:
                worker_broken_trials += 1

        if worker_broken_trials >= max_broken:
            print(
                "#### Worker has reached broken trials threshold, terminating."
            )
            print(worker_broken_trials, max_broken)
            break

    print("\n" + format_stats(experiment))

    print("\n" + COMPLETION_MESSAGE.format(experiment=experiment))
    if not experiment.is_done:
        print(NONCOMPLETED_MESSAGE.format(experiment=experiment))