Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest v2 #297

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
28 changes: 28 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,31 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# flake8 options are defined in setup.cfg
flake8 . --count --statistics

testing:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
working-directory: ${{ github.workspace }}/source/python/gui
run: |
sudo apt-get update
sudo apt-get install -y chromium-browser
sudo apt-get upgrade -y
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install pytest selenium selenium-wire webdriver-manager
- name: Test
working-directory: ${{ github.workspace }}/source/python/gui
run: |
pip install -e .
export PATH=${HOME}/.local/bin:${PATH}
pytest -s -vv
1 change: 1 addition & 0 deletions source/python/gui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/build*
/*.egg-info
/source/VERSION
/geckodriver.log
5 changes: 5 additions & 0 deletions source/python/gui/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

[pytest]
addopts = --durations=20 -ras -vv
testpaths = .
filterwarnings = ignore:`np.bool8` is a deprecated alias for `np.bool_`:DeprecationWarning
90 changes: 50 additions & 40 deletions source/python/gui/source/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
from .parser import parse_files, find_causal_files, set_num_stddev
from . import __version__

default_settings = {}
default_settings["path"] = ""
default_settings["cli"] = False
default_settings["light"] = False
default_settings["ip_address"] = "0.0.0.0"
default_settings["ip_port"] = 8051
default_settings["experiments"] = ".*"
default_settings["progress_points"] = ".*"
default_settings["min_points"] = 5
default_settings["recursive"] = False
default_settings["verbose"] = 0
default_settings["stddev"] = 1.0


def causal(args):
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.CYBORG])
Expand Down Expand Up @@ -75,20 +88,25 @@ def causal(args):
sortOptions = ["Alphabetical", "Max Speedup", "Min Speedup", "Impact"]
input_filters = [
{
"Name": "Sort by",
"name": "Sort by",
"values": list(map(str, sortOptions)),
"default": "Impact",
"type": "Name",
"type": "name",
"multi": False,
},
{
"Name": "Select Workload",
"name": "Select Workload",
"values": file_names,
"default": file_names,
"type": "Name",
"type": "name",
"multi": True,
},
{"Name": "points", "filter": [], "values": max_points, "type": "int"},
{
"name": "points",
"num_points": args.min_points,
"values": max_points,
"type": "int",
},
]

gui.build_causal_layout(
Expand All @@ -107,41 +125,7 @@ def causal(args):
)


def main():
settings = {}

this_dir = Path(__file__).resolve().parent
if os.path.basename(this_dir) == "source":
settings_path = os.path.join(f"{this_dir.parent}", "settings.json")
else:
settings_path = os.path.join(f"{this_dir}", "settings.json")

for itr in [
settings_path,
os.path.join(os.environ.get("HOME"), ".omnitrace-causal-plot.json"),
]:
if os.path.exists(itr):
with open(itr, "r") as f:
settings = json.load(f)
break

default_settings = {}
default_settings["path"] = ""
default_settings["cli"] = False
default_settings["light"] = False
default_settings["ip_address"] = "0.0.0.0"
default_settings["ip_port"] = 8051
default_settings["experiments"] = ".*"
default_settings["progress_points"] = ".*"
default_settings["min_points"] = 5
default_settings["recursive"] = False
default_settings["verbose"] = 0
default_settings["stddev"] = 1.0

for key, value in default_settings.items():
if key not in settings:
settings[key] = value

def create_parser(settings):
my_parser = argparse.ArgumentParser(
description="AMD's OmniTrace Causal Profiling GUI",
prog="tool",
Expand Down Expand Up @@ -285,6 +269,32 @@ def main():
help="Validate speedup: {experiment regex} {progress-point regex} {virtual-speedup} {expected-speedup} {tolerance}",
default=[],
)
return my_parser


def main():
settings = {}

this_dir = Path(__file__).resolve().parent
if os.path.basename(this_dir) == "source":
settings_path = os.path.join(f"{this_dir.parent}", "settings.json")
else:
settings_path = os.path.join(f"{this_dir}", "settings.json")

for itr in [
settings_path,
os.path.join(os.environ.get("HOME"), ".omnitrace-causal-plot.json"),
]:
if os.path.exists(itr):
with open(itr, "r") as f:
settings = json.load(f)
break

for key, value in default_settings.items():
if key not in settings:
settings[key] = value

my_parser = create_parser(settings)

args = my_parser.parse_args()

Expand Down
45 changes: 23 additions & 22 deletions source/python/gui/source/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
__maintainer__ = "AMD Research"
__status__ = "Development"

import glob
import re
import base64
import os
Expand Down Expand Up @@ -81,13 +80,13 @@ def build_line_graph():
layout1 = html.Div(
id="graph_all",
className="graph",
children=[html.H4("All Causal Profiles", style={"color": text_color})],
# children=[html.H4("All Causal Profiles", style={"color": text_color})],
)

layout2 = html.Div(
id="graph_select",
className="graph",
children=[html.H4("Call Stack Sample Histogram", style={"color": text_color})],
# children=[html.H4("Call Stack Sample Histogram", style={"color": text_color})],
)

return layout1, layout2
Expand All @@ -109,7 +108,7 @@ def update_line_graph(
data = data.sort_values(by=["min speedup", "idx"])

if num_points > 0:
data = data[data["point count"] > num_points]
data = data[data["point count"] >= num_points]

mask = data[data.point.isin(experiment_list)]
mask = mask[mask["progress points"].isin(progpt_list)]
Expand Down Expand Up @@ -165,6 +164,7 @@ def update_line_graph(
line_shape="spline",
name=prog,
mode="lines+markers",
showlegend=True,
),
).update_xaxes(dtick=5).update_yaxes(range=y_ranges, dtick=10).update_layout(
xaxis={"title": x_label},
Expand Down Expand Up @@ -196,20 +196,20 @@ def reset_input_filters(workloads, max_points, verbosity):

input_filters = [
{
"Name": "Sort by",
"name": "Sort by",
"values": list(map(str, sortOptions)),
"default": "Impact",
"type": "Name",
"type": "name",
"multi": False,
},
{
"Name": "Select Workload",
"name": "Select Workload",
"values": workloads,
"default": workloads,
"type": "Name",
"type": "name",
"multi": True,
},
{"Name": "points", "filter": [], "values": max_points, "type": "int"},
{"Name": "points", "num_points": 1, "values": max_points, "type": "int"},
]
return input_filters

Expand Down Expand Up @@ -317,26 +317,27 @@ def generate_from_filter(

if _workload_path is not None and os.path.exists(_workload_path):
files = []
if os.path.isfile(_workload_path):
files.append(_workload_path)
workload_path = [_workload_path]
elif os.path.isdir(_workload_path):
_files = glob.glob(os.path.join(_workload_path, "*.json"))
# subfiles = glob.glob(os.path.join(workload_path, "*/*.coz")) +
subfiles = glob.glob(os.path.join(_workload_path, "*/*.json"))
# metadata = glob.glob(os.path.join(_workload_path, "*/metadata*.json"))
files = _files + subfiles
workload_path = files
files = find_causal_files([_workload_path], verbosity, True)
# if os.path.isfile(_workload_path):
# files.append(_workload_path)
# workload_path = [_workload_path]
# elif os.path.isdir(_workload_path):
# _files = glob.glob(os.path.join(_workload_path, "*.json"))
# # subfiles = glob.glob(os.path.join(workload_path, "*/*.coz")) +
# subfiles = glob.glob(os.path.join(_workload_path, "*/*.json"))
# # metadata = glob.glob(os.path.join(_workload_path, "*/metadata*.json"))
# files = _files + subfiles
# workload_path = files
global_data, global_samples, global_filenames = parse_files(
workload_path, verbose=verbose
files, verbose=verbose
)
experiment_list = sorted(list(global_data.point.unique()))
progpt_list = sorted(list(global_data["progress points"].unique()))

max_points = global_data.point.value_counts().max().max()

# reset input_filters
workloads = [os.path.basename(file) for file in files]
workloads = sorted(list(global_data.workload.unique()))
global_input_filters = reset_input_filters(workloads, max_points, verbose)

screen_data, fig1, fig2 = update_line_graph(
Expand Down Expand Up @@ -377,7 +378,7 @@ def generate_from_filter(
new_data,
num_points,
global_samples,
workload_filter,
[filename],
)
header = get_header(dropDownMenuItems, global_input_filters)

Expand Down
10 changes: 5 additions & 5 deletions source/python/gui/source/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def upload_file():
)


def minPoints(name, values):
def minPoints(num_points, values):
return html.Div(
className="filter",
id="min-points",
Expand All @@ -82,7 +82,7 @@ def minPoints(name, values):
min=0,
max=values,
step=1,
value=1,
value=num_points,
id="points-filt",
handleLabel={"showCurrentValue": True, "label": " "},
size=120,
Expand Down Expand Up @@ -162,11 +162,11 @@ def get_header(dropDownMenuItems, input_filters):
header_nav = children_[0].children[0].children

if filter["type"] == "int":
filter_children.append(minPoints(filter["Name"], filter["values"]))
elif filter["type"] == "Name":
filter_children.append(minPoints(filter["num_points"], filter["values"]))
elif filter["type"] == "name":
filter_children.append(
sortBy(
filter["Name"],
filter["name"],
filter["values"],
filter["default"],
filter["multi"],
Expand Down
Loading
Loading