@@ -0,0 +1,2443 @@
+%22%22%22Plot results from ray-based simulations%0A%0AThis method accepts as input the progress file generated by ray%0A(usually stored at ~/ray_results/.../progress.csv)%0Aas well as the column(s) to be plotted.%0A%0AIf no column is specified, all existing columns will be printed.%0A%0AExample usage%0A-----%0A::%0A    python ray_plot_progress.py %3C/path/to/file%3E.csv mean_reward max_reward%0A%22%22%22%0A%0Aimport csv%0Aimport argparse%0Aimport matplotlib.pyplot as plt%0Afrom collections import defaultdict%0A%0A%0AEXAMPLE_USAGE = 'ray_plot_progress.py ' + %5C%0A    '~/ray_results/experiment-tag/experiment-name/seed-id/progress.csv ' + %5C%0A    'evaluation/return-average training/return-average'%0A%0A%0Adef plot_progress(filepath, columns):%0A    %22%22%22%0A    Plot the values contained in the csv file at %3Cfilepath%3E for each column%0A    in the list of string columns.%0A    %22%22%22%0A    data = defaultdict(list)%0A%0A    with open(filepath) as f:%0A        # if columns list is empty, print a list of all columns and return%0A        if not columns:%0A            reader = csv.reader(f)%0A            print('Columns are: ' + ', '.join(next(reader)))%0A            return%0A%0A        try:%0A            reader = csv.DictReader(f)%0A            for row in reader:%0A                for col in columns:%0A                    data%5Bcol%5D.append(float(row%5Bcol%5D))%0A        except KeyError:%0A            print(f'Error: %7B__file__%7D was called with an unknown column name '%0A                  f'%22%7Bcol%7D%22. Run %60python %7B__file__%7D %7Bfilepath%7D%60 to get a list '%0A                  f'of all the existing columns.')%0A            raise%0A        except ValueError:%0A            print(f'Error: %7B__file__%7D was called with an invalid column name '%0A                  f'%22%7Bcol%7D%22. This column contains values that are not '%0A                  f'convertible to floats.')%0A            raise%0A%0A    for col_name, values in data.items():%0A        plt.plot(values, label=col_name)%0A    plt.legend()%0A    plt.show()%0A%0A%0Adef create_parser():%0A%0A    parser = argparse.ArgumentParser(%0A        formatter_class=argparse.RawDescriptionHelpFormatter,%0A        description='%5BFlow%5D Plots progress.csv file generated by ray.',%0A        epilog='Example usage:%5Cn%5Ct' + EXAMPLE_USAGE)%0A%0A    parser.add_argument('file', type=str, help='Path to the csv file.')%0A    parser.add_argument(%0A        'columns', type=str, nargs='*', help='Names of the columns to plot.')%0A%0A    return parser%0A%0A%0Aif __name__ == '__main__':%0A    parser = create_parser()%0A    args = parser.parse_args()%0A    plot_progress(args.file, args.columns)

add ray_results plotter