From b5940c1d42c86be7a142bbf69d95e0b273e8ac5f Mon Sep 17 00:00:00 2001 From: Erick Winston Date: Tue, 28 Jun 2022 18:56:53 -0400 Subject: [PATCH 1/3] linting --- report/interactive_viewer.py | 53 ++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 report/interactive_viewer.py diff --git a/report/interactive_viewer.py b/report/interactive_viewer.py new file mode 100644 index 00000000..69a798f2 --- /dev/null +++ b/report/interactive_viewer.py @@ -0,0 +1,53 @@ +"""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) + # check whether we are in notebook + try: + get_ipython().__class__.__name__ + except NameError: + print("jupyter notebook not detected...attempting to open in browser") + 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 From 67fd5e4f06c84e48b673bbb1951a5f7708aa295b Mon Sep 17 00:00:00 2001 From: Erick Winston Date: Wed, 29 Jun 2022 14:50:25 -0400 Subject: [PATCH 2/3] add usage info --- README.md | 7 +++++++ report/interactive_viewer.py | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) 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 index 69a798f2..165b119d 100644 --- a/report/interactive_viewer.py +++ b/report/interactive_viewer.py @@ -31,12 +31,7 @@ def main(path, framework="dtale"): df = pd.json_normalize(result_data_list, record_path=["benchmarks"], meta=["file"]) session = eda.show(df) - # check whether we are in notebook - try: - get_ipython().__class__.__name__ - except NameError: - print("jupyter notebook not detected...attempting to open in browser") - session.open_browser() + session.open_browser() if __name__ == "__main__": From bb5c21e2f6da3d39e8c4cf11d44265d0c8529ce3 Mon Sep 17 00:00:00 2001 From: Erick Winston Date: Wed, 29 Jun 2022 15:02:36 -0400 Subject: [PATCH 3/3] allow running dtale from script --- report/interactive_viewer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/report/interactive_viewer.py b/report/interactive_viewer.py index 165b119d..d4547655 100644 --- a/report/interactive_viewer.py +++ b/report/interactive_viewer.py @@ -30,7 +30,7 @@ def main(path, framework="dtale"): 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) + session = eda.show(df, host="localhost", subprocess=False) session.open_browser()