diff --git a/README.md b/README.md index 5775383d..04c00ab5 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,13 @@ use: ```bash python -m report.console_tables --storage results/0001_bench.json ``` +To see the results in a web browser you can use: +```bash +python reports/interactive_viewer.py +``` +where "path" is a JSON results file or a directory containing the JSON results +files. If using a directory, it is assummed all the data in the directory have +the same result format. ## Warning This code is still under development. There are many razer sharp edges. diff --git a/report/interactive_viewer.py b/report/interactive_viewer.py new file mode 100644 index 00000000..d4547655 --- /dev/null +++ b/report/interactive_viewer.py @@ -0,0 +1,48 @@ +"""Interactive visualizer for results data""" + +import argparse +import os +import json +import glob +import pandas as pd + + +def main(path, framework="dtale"): + """ + Start visualizer. + + Args: + path (str): File or directory containing JSON formatted results + framework (str): visualization framework. Currently only 'dtale'. + """ + eda = __import__(framework) + if isinstance(path, list): + path_list = path + elif os.path.isdir(path): + path_list = glob.glob(path.rstrip("/ ") + "/*.json") + else: + path_list = [path] + df = pd.DataFrame() + result_data_list = [] + for data_path in path_list: + with open(data_path, "r", encoding="utf8") as dfile: + result_data = json.load(dfile) + result_data_list.append({"benchmarks": result_data["benchmarks"], "file": data_path}) + df = pd.json_normalize(result_data_list, record_path=["benchmarks"], meta=["file"]) + + session = eda.show(df, host="localhost", subprocess=False) + session.open_browser() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--eda-framework", + default="dtale", + dest="framework", + choices=["dtale"], + help=("Exploratory data analysis framework. " "Currently only dtale is available."), + ) + parser.add_argument("path", help="Path to directory or file for results.") + args = parser.parse_args() + main(args.path, args.framework) diff --git a/requirements.txt b/requirements.txt index 0c331b06..6a3bc352 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,5 @@ qiskit-terra pytket>1.0,<2.0 setproctitle rich +pandas +dtale