-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
nnbench.reporter
module, first tabular console implementation
The interface is not yet stable, since there are no options defined on the class constructor, and the console does not take any arguments yet.
- Loading branch information
1 parent
e37acb0
commit 2c4138e
Showing
4 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import sys | ||
import types | ||
from typing import Any | ||
|
||
from nnbench.types import BenchmarkResult | ||
|
||
|
||
class BaseReporter: | ||
""" | ||
The base interface for a benchmark reporter class. | ||
A benchmark reporter consumes benchmark results from a run, and subsequently | ||
reports them in the way specified by the respective implementation's `report()` | ||
method. | ||
For example, to write benchmark results to a database, you could save the credentials | ||
for authentication in the class constructor, and then stream the results directly to | ||
the database in `report()`, with preprocessing if necessary. | ||
Parameters | ||
---------- | ||
**kwargs: Any | ||
Additional keyword arguments, for compatibility with subclass interfaces. | ||
""" | ||
|
||
def __init__(self, **kwargs: Any): | ||
pass | ||
|
||
def report(self, result: BenchmarkResult) -> None: | ||
raise NotImplementedError | ||
|
||
|
||
class ConsoleReporter(BaseReporter): | ||
# TODO: Implement regex filters, context values, display options, ... (__init__) | ||
def report(self, result: BenchmarkResult) -> None: | ||
try: | ||
from tabulate import tabulate | ||
except ModuleNotFoundError: | ||
raise ValueError( | ||
f"{self.__class__.__name__} requires `tabulate` to be installed. " | ||
f"To install, run `{sys.executable} -m pip install --upgrade tabulate`." | ||
) | ||
|
||
benchmarks = result["benchmarks"] | ||
print(tabulate(benchmarks, headers="keys")) | ||
|
||
|
||
# internal, mutable | ||
_reporter_registry: dict[str, type[BaseReporter]] = { | ||
"console": ConsoleReporter, | ||
} | ||
|
||
# external, immutable | ||
reporter_registry: types.MappingProxyType[str, type[BaseReporter]] = types.MappingProxyType( | ||
_reporter_registry | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters