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
3 changes: 3 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ jobs:
cd ../../
cd stgraph/graph
ruff check .
cd ../../
cd stgraph/benchmark_tools
ruff check .
cd ../../
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Explore the STGraph documentation and tutorials to get started with writing and
package_reference/stgraph.dataset
package_reference/stgraph.compiler
package_reference/stgraph.graph
package_reference/stgraph.benchmark_tools

.. toctree::
:maxdepth: 1
Expand Down
4 changes: 3 additions & 1 deletion docs/source/package_reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ Package Reference
:maxdepth: 2

stgraph.dataset
stgraph.compiler
stgraph.compiler
stgraph.graph
stgraph.benchmark_tools
12 changes: 12 additions & 0 deletions docs/source/package_reference/stgraph.benchmark_tools.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
stgraph.benchmark_tools
#######################

.. currentmodule:: stgraph.benchmark_tools
.. automodule:: stgraph.benchmark_tools

.. autosummary::
:toctree: ../generated/
:nosignatures:
:template: class.rst

BenchmarkTable
3 changes: 3 additions & 0 deletions stgraph/benchmark_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Benchmarking Tools provided by STGraph."""

from stgraph.benchmark_tools.table import BenchmarkTable
73 changes: 65 additions & 8 deletions stgraph/benchmark_tools/table.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
"""Table that can display benchmarking data and other info."""

from __future__ import annotations

from typing import IO

from rich.console import Console
from rich.table import Table


class BenchmarkTable:
def __init__(self, title: str, col_name_list: list[str]):
r"""Table that can display benchmarking data and other info.

This class provides functionality to create and display tables for
benchmarking data along with other relevant information.

Example
-------

.. code-block:: python

from stgraph.benchmark_tools import BenchmarkTable

table = BenchmarkTable(
title = "GCN Benchmark Data",
col_name_list = ["Model", "Time", "MSE"]
)

table.add_row("GCN", 12.56, 45.89)
table.add_row("GCN", 23.34, 44.32)

table.display()

Parameters
----------
title : str
The title of the table
col_name_list : list[str]
A list of the table column names

Attributes
----------
title : str
The title of the table
col_name_list : list[str]
A list of the table column names

"""

def __init__(self: BenchmarkTable, title: str, col_name_list: list[str]) -> None:
r"""Table that can display benchmarking data and other info."""
self.title = "\n" + title + "\n"
self.col_name_list = col_name_list
self._table = Table(title=self.title, show_edge=False, style="black bold")
Expand All @@ -14,17 +57,31 @@ def __init__(self, title: str, col_name_list: list[str]):

self._table_add_columns()

def _table_add_columns(self):
def _table_add_columns(self: BenchmarkTable) -> None:
r"""Prepare the table by adding all the columns."""
for col_name in self.col_name_list:
self._table.add_column(col_name, justify="left")

def add_row(self, values: list):
def add_row(self: BenchmarkTable, values: list) -> None:
r"""Add a row of data to the table.

Parameters
----------
values : list
A list of values for each column in the row.

"""
values_str = tuple([str(val) for val in values])
self._table.add_row(*values_str)

def display(self, output_file=None):
if not output_file:
console = Console()
else:
console = Console(file=output_file)
def display(self: BenchmarkTable, output_file: IO[str] | None = None) -> None:
r"""Display entire table with data.

Parameters
----------
output_file : Optional[IO[str]], optional
File object to write the table to.

"""
console = Console() if not output_file else Console(file=output_file)
console.print(self._table)