Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions lib/ramble/ramble/cmd/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import json
import os

import llnl.util.tty.color as color
from llnl.util.tty.colify import colified

import ramble.cmd
import ramble.reports
import ramble.uploader
import ramble.util.colors as rucolor
from ramble.util.logger import logger

import spack.util.spack_yaml as syaml
Expand All @@ -29,6 +33,11 @@ def setup_parser(subparser):
)
upload_parser.add_argument("filename", help="path of file to upload")

index_parser = sp.add_parser(
"index", help=results_index.__doc__, description=results_index.__doc__
)
index_parser.add_argument("-f", "--file", help="path of results file")

report_parser = sp.add_parser(
"report", help=results_report.__doc__, description=results_report.__doc__
)
Expand Down Expand Up @@ -209,12 +218,33 @@ def _load_results(args):
return results_dict


def _print_attr_dict(attr_dict: dict, n_indent=0):
for attr, values in attr_dict.items():
indentation = " " * n_indent
color.cprint(f"{indentation}{rucolor.title_color(attr, n_indent)}:")
if isinstance(values, dict):
_print_attr_dict(values, n_indent + 4)
else:
color.cprint(colified(sorted(values), tty=True, indent=n_indent + 4))


def results_index(args):
"""List attributes in results including FOMs and template variables"""
results_dict = _load_results(args)
result_index = ramble.reports.generate_result_index(results_dict)
for obj_name, obj_dict in result_index.items():
if obj_dict:
color.cprint(rucolor.title_color(f'{obj_name.replace("_", " ").title()}:'))
_print_attr_dict(obj_dict, n_indent=4)


def results_report(args):
"""Create a report with charts from Ramble experiment results."""
results_dict = _load_results(args)

ws_name = results_dict["workspace_name"]
if not ws_name:
if "workspace_name" in results_dict:
ws_name = results_dict["workspace_name"]
else:
ws_name = "unknown_workspace"

if args.workspace:
Expand All @@ -225,5 +255,9 @@ def results_report(args):


def results(parser, args):
action = {"upload": results_upload, "report": results_report}
action = {
"upload": results_upload,
"index": results_index,
"report": results_report,
}
action[args.results_command](args)
42 changes: 13 additions & 29 deletions lib/ramble/ramble/definitions/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@
import ramble.util.colors as rucolor


def _title_color(title: str, n_indent: int = 0):
"""Set the appropriate color for titles based on indentation"""
if n_indent == 0:
out_str = rucolor.section_title(f"{title}")
elif n_indent == 4:
out_str = rucolor.nested_1(f"{title}")
elif n_indent == 8:
out_str = rucolor.nested_2(f"{title}")
elif n_indent == 12:
out_str = rucolor.nested_3(f"{title}")
elif n_indent == 16:
out_str = rucolor.nested_4(f"{title}")

return out_str


class Variable:
"""Class representing a variable definition"""

Expand Down Expand Up @@ -81,7 +65,7 @@ def as_str(self, n_indent: int = 0, verbose: bool = False):
if verbose:
print_attrs = ["Description", "Default", "Values"]

out_str = _title_color(f"{indentation}{self.name}:\n", n_indent)
out_str = rucolor.title_color(f"{indentation}{self.name}:\n", n_indent)
for print_attr in print_attrs:
name = print_attr
if print_attr == "Values":
Expand All @@ -91,7 +75,7 @@ def as_str(self, n_indent: int = 0, verbose: bool = False):
attr_val = getattr(self, attr_name, None)
if attr_val:
out_str += (
f"{indentation} {_title_color(name, n_indent=n_indent + 4)}: "
f"{indentation} {rucolor.title_color(name, n_indent=n_indent + 4)}: "
f'{str(attr_val).replace("@", "@@")}\n'
)
else:
Expand Down Expand Up @@ -156,7 +140,7 @@ def as_str(self, n_indent: int = 0, verbose: bool = False):

print_attrs = ["Modification", "Method", "Separator", "When"]

out_str = _title_color(f"{indentation}{self.name}:\n", n_indent)
out_str = rucolor.title_color(f"{indentation}{self.name}:\n", n_indent)
for print_attr in print_attrs:
name = print_attr
attr_name = print_attr.lower()
Expand All @@ -166,7 +150,7 @@ def as_str(self, n_indent: int = 0, verbose: bool = False):
if print_attr == "Separator":
attr_val = f"'{attr_val}'"
out_str += (
f"{indentation} {_title_color(name, n_indent=n_indent + 4)}: "
f"{indentation} {rucolor.title_color(name, n_indent=n_indent + 4)}: "
f'{str(attr_val).replace("@", "@@")}\n'
)
return out_str
Expand Down Expand Up @@ -226,13 +210,13 @@ def as_str(self, n_indent: int = 0, verbose: bool = False):
print_attrs = ["Description", "Value", "Method"]
if self.method == "append":
print_attrs.append("Separator")
out_str = _title_color(f"{indentation}{self.name}:\n", n_indent)
out_str = rucolor.title_color(f"{indentation}{self.name}:\n", n_indent)
for name in print_attrs:
attr_name = name.lower()
attr_val = getattr(self, attr_name, None)
if attr_val:
out_str += (
f"{indentation} {_title_color(name, n_indent=n_indent + 4)}: "
f"{indentation} {rucolor.title_color(name, n_indent=n_indent + 4)}: "
f'{str(attr_val).replace("@", "@@")}\n'
)
else:
Expand Down Expand Up @@ -307,33 +291,33 @@ def as_str(self, n_indent: int = 0, verbose: bool = False):

if verbose:
n = 0
out_str = _title_color(f"{indentation}{self.name}:\n", n_indent)
out_str = rucolor.title_color(f"{indentation}{self.name}:\n", n_indent)
for method in self.all_methods:
if getattr(self, method):
if n > 0:
out_str += "\n"
out_str += (
f"{indentation} {_title_color('method', n_indent=n_indent + 4)}: "
f"{method}\n"
f"{indentation} "
f"{rucolor.title_color('method', n_indent=n_indent + 4)}: {method}\n"
)
n += 1
if method == "set":
out_str += (
f"{indentation} "
f"{_title_color('modification', n_indent=n_indent + 4)}: "
f"{rucolor.title_color('modification', n_indent=n_indent + 4)}: "
f"{self.set[self.name]}\n"
)
elif method in ["prepend", "append"]:
for method_dict in getattr(self, method):
for attr, val in method_dict.items():
out_str += (
f"{indentation} "
f"{_title_color(attr, n_indent=n_indent + 4)}: {val}\n"
f"{rucolor.title_color(attr, n_indent=n_indent + 4)}: {val}\n"
)
if self.when:
out_str += (
f"{indentation} {_title_color('when', n_indent=n_indent + 4)}: "
f"{self.when}\n"
f"{indentation} "
f"{rucolor.title_color('when', n_indent=n_indent + 4)}: {self.when}\n"
)
else:
out_str = f"{indentation}{self.name}"
Expand Down
Loading