python/ray/tune/tune.py
def run_experiments(
    experiments: Union[Experiment, Mapping, Sequence[Union[Experiment, Mapping]]],
    scheduler: Optional[TrialScheduler] = None,
    server_port: Optional[int] = None,
    verbose: Union[int, Verbosity] = Verbosity.V3_TRIAL_DETAILS,
    progress_reporter: Optional[ProgressReporter] = None,
    resume: Union[bool, str] = False,
    reuse_actors: Optional[bool] = None,
    trial_executor: Optional[RayTrialExecutor] = None,
    raise_on_failed_trial: bool = True,
    concurrent: bool = True,
    # Deprecated args.
    queue_trials: Optional[bool] = None,
    callbacks: Optional[Sequence[Callback]] = None,
    _remote: Optional[bool] = None,
):
    """Runs and blocks until all trials finish.

    Example:
        >>> from ray.tune.experiment import Experiment
        >>> from ray.tune.tune import run_experiments
        >>> def my_func(config): return {"score": 0}
        >>> experiment_spec = Experiment("experiment", my_func) # doctest: +SKIP
        >>> run_experiments(experiments=experiment_spec) # doctest: +SKIP
        >>> experiment_spec = {"experiment": {"run": my_func}} # doctest: +SKIP
        >>> run_experiments(experiments=experiment_spec) # doctest: +SKIP

    Returns:
        List of Trial objects, holding data for each executed trial.

    """
    # To be removed in 1.9.
    if queue_trials is not None:
        raise DeprecationWarning(
            "`queue_trials` has been deprecated and is replaced by "
            "the `TUNE_MAX_PENDING_TRIALS_PG` environment variable. "
            "Per default at least one Trial is queued at all times, "
            "so you likely don't need to change anything other than "
            "removing this argument from your call to `tune.run()`"
        )

    if _remote is None:
        _remote = ray.util.client.ray.is_connected()

    if _remote is True and trial_executor:
        raise ValueError("cannot use custom trial executor")

    if not trial_executor or isinstance(trial_executor, RayTrialExecutor):
        _ray_auto_init()

    if _remote:
        remote_run = ray.remote(num_cpus=0)(run_experiments)

        # Make sure tune.run_experiments is run on the server node.
        remote_run = force_on_current_node(remote_run)

        return ray.get(
            remote_run.remote(
                experiments,
                scheduler,
                server_port,
                verbose,
                progress_reporter,
                resume,
                reuse_actors,
                trial_executor,
                raise_on_failed_trial,
                concurrent,
                callbacks,
                _remote=False,
            )
        )

    # This is important to do this here
    # because it schematize the experiments
    # and it conducts the implicit registration.
    experiments = convert_to_experiment_list(experiments)

    if concurrent:
        return run(
            experiments,
            server_port=server_port,
            verbose=verbose,
            progress_reporter=progress_reporter,
            resume=resume,
            reuse_actors=reuse_actors,
            trial_executor=trial_executor,
            raise_on_failed_trial=raise_on_failed_trial,
            scheduler=scheduler,
            callbacks=callbacks,
        ).trials
    else:
        trials = []
        for exp in experiments:
            trials += run(
                exp,
                server_port=server_port,
                verbose=verbose,
                progress_reporter=progress_reporter,
                resume=resume,
                reuse_actors=reuse_actors,
                trial_executor=trial_executor,
                raise_on_failed_trial=raise_on_failed_trial,
                scheduler=scheduler,
                callbacks=callbacks,
            ).trials
        return trials
Runs and blocks until all trials finish.

    Example:
        >>> from ray.tune.experiment import Experiment
        >>> from ray.tune.tune import run_experiments
        >>> def my_func(config): return {"score": 0}
        >>> experiment_spec = Experiment("experiment", my_func) # doctest: +SKIP
        >>> run_experiments(experiments=experiment_spec) # doctest: +SKIP
        >>> experiment_spec = {"experiment": {"run": my_func}} # doctest: +SKIP
        >>> run_experiments(experiments=experiment_spec) # doctest: +SKIP

    Returns:
        List of Trial objects, holding data for each executed trial.

    
Runs and blocks until all trials finish.
Runs and blocks until all trials finish .
def run_experiments(
    experiments: Union[Experiment, Mapping, Sequence[Union[Experiment, Mapping]]],
    scheduler: Optional[TrialScheduler] = None,
    server_port: Optional[int] = None,
    verbose: Union[int, Verbosity] = Verbosity.V3_TRIAL_DETAILS,
    progress_reporter: Optional[ProgressReporter] = None,
    resume: Union[bool, str] = False,
    reuse_actors: Optional[bool] = None,
    trial_executor: Optional[RayTrialExecutor] = None,
    raise_on_failed_trial: bool = True,
    concurrent: bool = True,
    queue_trials: Optional[bool] = None,
    callbacks: Optional[Sequence[Callback]] = None,
    _remote: Optional[bool] = None,
):
    if queue_trials is not None:
        raise DeprecationWarning(
            "`queue_trials` has been deprecated and is replaced by "
            "the `TUNE_MAX_PENDING_TRIALS_PG` environment variable. "
            "Per default at least one Trial is queued at all times, "
            "so you likely don't need to change anything other than "
            "removing this argument from your call to `tune.run()`"
        )
    if _remote is None:
        _remote = ray.util.client.ray.is_connected()
    if _remote is True and trial_executor:
        raise ValueError("cannot use custom trial executor")
    if not trial_executor or isinstance(trial_executor, RayTrialExecutor):
        _ray_auto_init()
    if _remote:
        remote_run = ray.remote(num_cpus=0)(run_experiments)
        remote_run = force_on_current_node(remote_run)
        return ray.get(
            remote_run.remote(
                experiments,
                scheduler,
                server_port,
                verbose,
                progress_reporter,
                resume,
                reuse_actors,
                trial_executor,
                raise_on_failed_trial,
                concurrent,
                callbacks,
                _remote=False,
            )
        )
    experiments = convert_to_experiment_list(experiments)
    if concurrent:
        return run(
            experiments,
            server_port=server_port,
            verbose=verbose,
            progress_reporter=progress_reporter,
            resume=resume,
            reuse_actors=reuse_actors,
            trial_executor=trial_executor,
            raise_on_failed_trial=raise_on_failed_trial,
            scheduler=scheduler,
            callbacks=callbacks,
        ).trials
    else:
        trials = []
        for exp in experiments:
            trials += run(
                exp,
                server_port=server_port,
                verbose=verbose,
                progress_reporter=progress_reporter,
                resume=resume,
                reuse_actors=reuse_actors,
                trial_executor=trial_executor,
                raise_on_failed_trial=raise_on_failed_trial,
                scheduler=scheduler,
                callbacks=callbacks,
            ).trials
        return trials
def run_experiments ( experiments : Union [ Experiment , Mapping , Sequence [ Union [ Experiment , Mapping ] ] ] , scheduler : Optional [ TrialScheduler ] = None , server_port : Optional [ int ] = None , verbose : Union [ int , Verbosity ] = Verbosity . V3_TRIAL_DETAILS , progress_reporter : Optional [ ProgressReporter ] = None , resume : Union [ bool , str ] = False , reuse_actors : Optional [ bool ] = None , trial_executor : Optional [ RayTrialExecutor ] = None , raise_on_failed_trial : bool = True , concurrent : bool = True , queue_trials : Optional [ bool ] = None , callbacks : Optional [ Sequence [ Callback ] ] = None , _remote : Optional [ bool ] = None , ) : if queue_trials is not None : raise DeprecationWarning ( "`queue_trials` has been deprecated and is replaced by " "the `TUNE_MAX_PENDING_TRIALS_PG` environment variable. " "Per default at least one Trial is queued at all times, " "so you likely don't need to change anything other than " "removing this argument from your call to `tune.run()`" ) if _remote is None : _remote = ray . util . client . ray . is_connected ( ) if _remote is True and trial_executor : raise ValueError ( "cannot use custom trial executor" ) if not trial_executor or isinstance ( trial_executor , RayTrialExecutor ) : _ray_auto_init ( ) if _remote : remote_run = ray . remote ( num_cpus = 0 ) ( run_experiments ) remote_run = force_on_current_node ( remote_run ) return ray . get ( remote_run . remote ( experiments , scheduler , server_port , verbose , progress_reporter , resume , reuse_actors , trial_executor , raise_on_failed_trial , concurrent , callbacks , _remote = False , ) ) experiments = convert_to_experiment_list ( experiments ) if concurrent : return run ( experiments , server_port = server_port , verbose = verbose , progress_reporter = progress_reporter , resume = resume , reuse_actors = reuse_actors , trial_executor = trial_executor , raise_on_failed_trial = raise_on_failed_trial , scheduler = scheduler , callbacks = callbacks , ) . trials else : trials = [ ] for exp in experiments : trials += run ( exp , server_port = server_port , verbose = verbose , progress_reporter = progress_reporter , resume = resume , reuse_actors = reuse_actors , trial_executor = trial_executor , raise_on_failed_trial = raise_on_failed_trial , scheduler = scheduler , callbacks = callbacks , ) . trials return trials
Runs and blocks until all trials finish.
Runs and blocks until all trials finish .
# Deprecated args. """Runs and blocks until all trials finish.

    Example:
        >>> from ray.tune.experiment import Experiment
        >>> from ray.tune.tune import run_experiments
        >>> def my_func(config): return {"score": 0}
        >>> experiment_spec = Experiment("experiment", my_func) # doctest: +SKIP
        >>> run_experiments(experiments=experiment_spec) # doctest: +SKIP
        >>> experiment_spec = {"experiment": {"run": my_func}} # doctest: +SKIP
        >>> run_experiments(experiments=experiment_spec) # doctest: +SKIP

    Returns:
        List of Trial objects, holding data for each executed trial.

    """ # To be removed in 1.9. # Make sure tune.run_experiments is run on the server node. # This is important to do this here # because it schematize the experiments # and it conducts the implicit registration.
List of Trial objects, holding data for each executed trial.
List of Trial objects holding data for each executed trial .
experiments
Union[Experiment, Mapping, Sequence[Union[Experiment, Mapping]]]
scheduler
Optional[TrialScheduler]
server_port
Optional[int]
verbose
Union[int, Verbosity]
progress_reporter
Optional[ProgressReporter]
resume
Union[bool, str]
reuse_actors
Optional[bool]
trial_executor
Optional[RayTrialExecutor]
raise_on_failed_trial
bool
concurrent
bool
queue_trials
Optional[bool]
callbacks
Optional[Sequence[Callback]]
_remote
Optional[bool]
examples
>>> from ray.tune.experiment import Experiment
>>> from ray.tune.tune import run_experiments
>>> def my_func(config): return {"score": 0}
>>> experiment_spec = Experiment("experiment", my_func) # doctest: +SKIP
>>> run_experiments(experiments=experiment_spec) # doctest: +SKIP
>>> experiment_spec = {"experiment": {"run": my_func}} # doctest: +SKIP
>>> run_experiments(experiments=experiment_spec) # doctest: +SKIP
>>> from ray . tune . experiment import Experiment >>> from ray . tune . tune import run_experiments >>> def my_func ( config ) : return { " score " : 0 } >>> experiment_spec = Experiment ( " experiment " my_func ) # doctest : + SKIP >>> run_experiments ( experiments = experiment_spec ) # doctest : + SKIP >>> experiment_spec = { " experiment " : { " run " : my_func }} # doctest : + SKIP >>> run_experiments ( experiments = experiment_spec ) # doctest : + SKIP