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

add tests for stats #43

Merged
merged 17 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
29 changes: 29 additions & 0 deletions thicket/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ def columnar_join_thicket(mpi_scaling_cali, rajaperf_basecuda_xl_cali):
return thicket_list, thicket_list_cp, combined_th


@pytest.fixture
def stats_columnar_join_thicket(rajaperf_basecuda_xl_cali):
"""Generator for 'columnar_join' thicket for test_stats.py.

Arguments:
mpi_scaling_cali (list): List of Caliper files for MPI scaling study.
rajaperf_basecuda_xl_cali (list): List of Caliper files for base cuda variant.

Returns:
list: List of original thickets, list of deepcopies of original thickets, and
columnar-joined thicket.
"""
th_cuda128_1 = Thicket.from_caliperreader(rajaperf_basecuda_xl_cali[0:4])
th_cuda128_2 = Thicket.from_caliperreader(rajaperf_basecuda_xl_cali[5:9])

# To check later if modifications were unexpectedly made
th_cuda128_1_deep = th_cuda128_1.deepcopy()
th_cuda128_2_deep = th_cuda128_2.deepcopy()
thicket_list = [th_cuda128_1, th_cuda128_2]
thicket_list_cp = [th_cuda128_1_deep, th_cuda128_2_deep]

combined_th = Thicket.columnar_join(
thicket_list=thicket_list,
header_list=["Cuda 1", "Cuda 2"],
)

return thicket_list, thicket_list_cp, combined_th


@pytest.fixture
def data_dir():
"""Return path to the top-level data directory for tests."""
Expand Down
148 changes: 148 additions & 0 deletions thicket/tests/test_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Copyright 2022 Lawrence Livermore National Security, LLC and other
# Thicket Project Developers. See the top-level LICENSE file for details.
#
# SPDX-License-Identifier: MIT

import matplotlib.pyplot as plt
import pandas as pd

import thicket as th


def test_histogram(example_cali):
th_ens = th.Thicket.from_caliperreader(example_cali)

assert sorted(th_ens.dataframe.index.get_level_values(0).unique()) == sorted(
th_ens.statsframe.dataframe.index.values
)
assert list(th_ens.statsframe.dataframe.columns) == ["name"]

n = pd.unique(th_ens.dataframe.reset_index()["node"])[4]

ax = th.display_histogram(th_ens, node=n, column="Min time/rank")

# check to make sure that a figure is generated
assert plt.get_fignums()[0] == 1

# check to make sure ylabel is Count
assert ax.axes.flat[0].get_ylabel() == "Count"

plt.close()


def test_histogram_columnar_join(columnar_join_thicket):
thicket_list, thicket_list_cp, combined_th = columnar_join_thicket
idx = combined_th.dataframe.columns.levels[0][0]
assert sorted(combined_th.dataframe.index.get_level_values(0).unique()) == sorted(
combined_th.statsframe.dataframe.index.values
)

assert list(combined_th.statsframe.dataframe.columns) == [("name", "")]

n = pd.unique(combined_th.dataframe.reset_index()["node"])[0]

ax = th.display_histogram(combined_th, node=n, column=(idx, "Min time/rank"))

# check to make sure that a figure is generated
assert plt.get_fignums()[0] == 1

# check to make sure ylabel is Count
assert ax.axes.flat[0].get_ylabel() == "Count"

plt.close()


def test_heatmap(example_cali):
th_ens = th.Thicket.from_caliperreader(example_cali)

assert sorted(th_ens.dataframe.index.get_level_values(0).unique()) == sorted(
th_ens.statsframe.dataframe.index.values
)
assert list(th_ens.statsframe.dataframe.columns) == ["name"]

th.variance(th_ens, columns=["Min time/rank"])

ax = th.display_heatmap(th_ens, columns=["Min time/rank_var"])

# check to make sure that a figure is generated
assert plt.get_fignums()[0] == 1

# check to make sure x and y axes have proper x and y tick labels
assert "Min time/rank_var" in ax.get_xticklabels()[0].get_text()
assert (
"{'name': 'Base_Seq', 'type': 'function'}" in ax.get_yticklabels()[0].get_text()
)

plt.close()


def test_heatmap_columnar_join(columnar_join_thicket):
thicket_list, thicket_list_cp, combined_th = columnar_join_thicket
idx = combined_th.dataframe.columns.levels[0][0]
assert sorted(combined_th.dataframe.index.get_level_values(0).unique()) == sorted(
combined_th.statsframe.dataframe.index.values
)

assert list(combined_th.statsframe.dataframe.columns) == [("name", "")]

th.variance(combined_th, columns=[(idx, "Min time/rank")])

ax = th.display_heatmap(combined_th, columns=[(idx, "Min time/rank_var")])

# check to make sure that a figure is generated
assert plt.get_fignums()[0] == 1

# check to make sure x, y and title have proper labels
# pr #75 must be merged before below checks can be used
# assert "Min time/rank_var" == ax.get_xticklabels()[0].get_text()
# assert (
# "{'name': 'Base_CUDA', 'type': 'function'}" in ax.get_yticklabels()[0].get_text()
# )
assert idx == ax.get_text()

plt.close()


def test_display_boxplot(example_cali):
th_ens = th.Thicket.from_caliperreader(example_cali)

assert sorted(th_ens.dataframe.index.get_level_values(0).unique()) == sorted(
th_ens.statsframe.dataframe.index.values
)
assert list(th_ens.statsframe.dataframe.columns) == ["name"]

n = pd.unique(th_ens.dataframe.reset_index()["node"])[0:2]

ax = th.display_boxplot(th_ens, nodes=n, columns=["Min time/rank"])

# check to make sure that a figure is generated
assert plt.get_fignums()[0] == 1

# check to make sure xlabel and xticklabels are correct
assert "Base_Seq" in ax.get_xticklabels()[0].get_text()
assert "node" in ax.get_xlabel()

plt.close()


def test_display_boxplot_columnar_join(columnar_join_thicket):
thicket_list, thicket_list_cp, combined_th = columnar_join_thicket
idx = combined_th.dataframe.columns.levels[0][0]
assert sorted(combined_th.dataframe.index.get_level_values(0).unique()) == sorted(
combined_th.statsframe.dataframe.index.values
)

assert list(combined_th.statsframe.dataframe.columns) == [("name", "")]

n = pd.unique(combined_th.dataframe.reset_index()["node"])[0:1].tolist()

ax = th.display_boxplot(combined_th, nodes=n, columns=[(idx, "Min time/rank")])

# check to make sure that a figure is generated
assert plt.get_fignums()[0] == 1

# check to make sure xlabel and xticklabels are correct
assert "Base_CUDA" in ax.get_xticklabels()[0].get_text()
assert "node" == ax.get_xlabel()

plt.close()
Loading
Loading