|
@@ -20,6 +20,7 @@ from pathlib import Path
|
|
|
from grass.benchmark import (
|
|
|
join_results_from_files,
|
|
|
load_results_from_file,
|
|
|
+ nprocs_plot,
|
|
|
num_cells_plot,
|
|
|
save_results_to_file,
|
|
|
)
|
|
@@ -33,7 +34,6 @@ class CliUsageError(ValueError):
|
|
|
|
|
|
# ArgumentError from argparse may work too, but it is not documented and
|
|
|
# takes a reference argument which we don't have access to after the parse step.
|
|
|
- pass
|
|
|
|
|
|
|
|
|
def join_results_cli(args):
|
|
@@ -43,13 +43,35 @@ def join_results_cli(args):
|
|
|
f"Number of prefixes ({len(args.prefixes)}) needs to be the same"
|
|
|
f" as the number of input result files ({len(args.results)})"
|
|
|
)
|
|
|
+
|
|
|
+ def select_only(result):
|
|
|
+ return result.label == args.only
|
|
|
+
|
|
|
+ if args.only:
|
|
|
+ select_function = select_only
|
|
|
+ else:
|
|
|
+ select_function = None
|
|
|
+
|
|
|
results = join_results_from_files(
|
|
|
source_filenames=args.results,
|
|
|
prefixes=args.prefixes,
|
|
|
+ select=select_function,
|
|
|
+ prefixes_as_labels=args.re_label,
|
|
|
)
|
|
|
+
|
|
|
save_results_to_file(results, args.output)
|
|
|
|
|
|
|
|
|
+def plot_nprocs_cli(args):
|
|
|
+ """Translate CLI parser result to API calls."""
|
|
|
+ results = load_results_from_file(args.input)
|
|
|
+ nprocs_plot(
|
|
|
+ results.results,
|
|
|
+ filename=args.output,
|
|
|
+ title=args.title,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def plot_cells_cli(args):
|
|
|
"""Translate CLI parser result to API calls."""
|
|
|
results = load_results_from_file(args.input)
|
|
@@ -124,9 +146,36 @@ def add_results_subcommand(parent_subparsers):
|
|
|
nargs="*",
|
|
|
metavar="text",
|
|
|
)
|
|
|
+ join.add_argument(
|
|
|
+ "--only",
|
|
|
+ help="Select only results with matching label",
|
|
|
+ metavar="label",
|
|
|
+ )
|
|
|
+ join.add_argument(
|
|
|
+ "--re-label",
|
|
|
+ help="Use prefixes as the new labels",
|
|
|
+ action="store_true",
|
|
|
+ )
|
|
|
join.set_defaults(handler=join_results_cli)
|
|
|
|
|
|
|
|
|
+def add_plot_io_arguments(parser):
|
|
|
+ """Add input and output arguments to *parser*."""
|
|
|
+ parser.add_argument("input", help="file with results (JSON)", metavar="input_file")
|
|
|
+ parser.add_argument(
|
|
|
+ "output", help="output file (e.g., PNG)", nargs="?", metavar="output_file"
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def add_plot_title_argument(parser):
|
|
|
+ """Add title argument to *parser*."""
|
|
|
+ parser.add_argument(
|
|
|
+ "--title",
|
|
|
+ help="Title for the plot",
|
|
|
+ metavar="text",
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def add_plot_subcommand(parent_subparsers):
|
|
|
"""Add plot subcommand."""
|
|
|
main_parser = add_subcommand_parser(
|
|
@@ -135,15 +184,8 @@ def add_plot_subcommand(parent_subparsers):
|
|
|
main_subparsers = add_subparsers(main_parser, dest="subcommand")
|
|
|
|
|
|
join = main_subparsers.add_parser("cells", help="Plot for variable number of cells")
|
|
|
- join.add_argument("input", help="file with results (JSON)", metavar="input_file")
|
|
|
- join.add_argument(
|
|
|
- "output", help="output file (e.g., PNG)", nargs="?", metavar="output_file"
|
|
|
- )
|
|
|
- join.add_argument(
|
|
|
- "--title",
|
|
|
- help="Title for the plot",
|
|
|
- metavar="text",
|
|
|
- )
|
|
|
+ add_plot_io_arguments(join)
|
|
|
+ add_plot_title_argument(join)
|
|
|
join.add_argument(
|
|
|
"--resolutions",
|
|
|
help="Use resolutions for x axis instead of cell count",
|
|
@@ -151,6 +193,13 @@ def add_plot_subcommand(parent_subparsers):
|
|
|
)
|
|
|
join.set_defaults(handler=plot_cells_cli)
|
|
|
|
|
|
+ nprocs = main_subparsers.add_parser(
|
|
|
+ "nprocs", help="Plot for variable number of processing elements"
|
|
|
+ )
|
|
|
+ add_plot_io_arguments(nprocs)
|
|
|
+ add_plot_title_argument(nprocs)
|
|
|
+ nprocs.set_defaults(handler=plot_nprocs_cli)
|
|
|
+
|
|
|
|
|
|
def define_arguments():
|
|
|
"""Define top level parser and create subparsers."""
|