ray.tune.ResultGrid#

class ray.tune.ResultGrid(experiment_analysis: ray.tune.analysis.experiment_analysis.ExperimentAnalysis)[source]#

Bases: object

A set of Result objects for interacting with Ray Tune results.

You can use it to inspect the trials and obtain the best result.

The constructor is a private API. This object can only be created as a result of Tuner.fit().

Example

>>> import random
>>> from ray import air, tune
>>> def random_error_trainable(config):
...     if random.random() < 0.5:
...         return {"loss": 0.0}
...     else:
...         raise ValueError("This is an error")
>>> tuner = tune.Tuner(
...     random_error_trainable,
...     run_config=air.RunConfig(name="example-experiment"),
...     tune_config=tune.TuneConfig(num_samples=10),
... )
>>> result_grid = tuner.fit()  
>>> for i in range(len(result_grid)): 
...     result = result_grid[i]
...     if not result.error:
...             print(f"Trial finishes successfully with metrics"
...                f"{result.metrics}.")
...     else:
...             print(f"Trial failed with error {result.error}.")

You can also use result_grid for more advanced analysis.

>>> # Get the best result based on a particular metric.
>>> best_result = result_grid.get_best_result( 
...     metric="loss", mode="min")
>>> # Get the best checkpoint corresponding to the best result.
>>> best_checkpoint = best_result.checkpoint 
>>> # Get a dataframe for the last reported results of all of the trials
>>> df = result_grid.get_dataframe() 
>>> # Get a dataframe for the minimum loss seen for each trial
>>> df = result_grid.get_dataframe(metric="loss", mode="min") 

Note that trials of all statuses are included in the final result grid. If a trial is not in terminated state, its latest result and checkpoint as seen by Tune will be provided.

See Analyzing Tune Experiment Results for more usage examples.

PublicAPI (beta): This API is in beta and may change before becoming stable.

Methods

get_best_result([metric, mode, scope, ...])

Get the best result from all the trials run.

get_dataframe([filter_metric, filter_mode])

Return dataframe of all trials with their configs and reported results.

Attributes

errors

Returns the exceptions of errored trials.

num_errors

Returns the number of errored trials.

num_terminated

Returns the number of terminated (but not errored) trials.