simplebench.reporters.reporter packageπ
Reporter base package in the reporters package.
- class simplebench.reporters.reporter.Reporter(
- config: ReporterConfig,
Bases:
ABC,_ReporterArgparseMixin,_ReporterOrchestrationMixin,_ReporterPrioritizationMixin,_ReporterTargetMixin,ReporterProtocolBase class for Reporter classes.
A
Reporteris responsible for generating reports based on benchmark results from aSessionandCase. Reporters can produce reports in various formats and output them to different targets.All
Reportersubclasses must implement the methods defined in this interface. Reporters should handle their own output, whether to console, file system, HTTP endpoint, display device, via a callback or other output.The
Reporterinterface ensures that all reporters provide a consistent set of functionalities, making it easier to manage and utilize differentreporting options within the SimpleBench framework.
Initialize the Reporter instance.
- Parameters:
config (ReporterConfig) β The configuration object for the reporter.
- Raises:
SimpleBenchTypeError β If the provided config is not a ReporterConfig instance.
- add_choice(choice: None) None[source]π
Add a
Choiceto the reporterβs choices.- Parameters:
- Raises:
SimpleBenchTypeError β If the provided choice is not a
Choiceinstance.SimpleBenchValueError β If the choiceβs sections, targets, or formats are not supported by the reporter.
- property choices: Choicesπ
The
Choicesfor the reporter.The
Choicesinstance contains one or moreChoiceinstances, each representing a specific combination of sections, targets, and formats, command line flags, and descriptions.This property allows access to the reporterβs choices for generating reports and customizing report output and available options.
- property config: ReporterConfigπ
The configuration object for the reporter.
- static find_options_by_type(
- options: Iterable[ReporterOptions] | None,
- cls: type[T],
Retrieve an instance of type
cls(if present) from a collection ofReporterOptions.This is used to extract reporter specific options from an iterable container of generic
ReporterOptionssuch as those associated with aChoiceorCase.For example, a
CSVReportermay define aCSVReporterOptionsclass that extendsReporterOptionsand use this method to extract theCSVReporterOptionsinstance from the options iterable:options = Reporter.find_options_by_type(case.options, CSVReporterOptions)
- Parameters:
options (Iterable[
ReporterOptions]) β An iterable ofReporterOptionsinstances.cls (type[T]) β The specific subclass type of
ReporterOptionsto find.
- Returns:
The instance of the class
clsif found, otherwiseNone.- Return type:
T | None
- get_all_stats_values( ) list[float][source]π
Gathers all primary statistical values for a given section across multiple results.
It collects mean, median, minimum, maximum, 5th percentile, and 95th percentile, from each
Resultsinstance for the specified section.This method is useful in determining appropriate scaling factors or units for reporting by analyzing the range of values across all results.
Adjusted standard deviation is not included in this collection because it can be
NaNfor results with insufficient data points, or orders of magnitude different from the other statistics, which can skew scaling calculations.
- get_base_unit_for_section(
- section: Section,
Return the base unit for the specified section.
- classmethod get_default_options() ReporterOptions[source]π
Get the default options for the reporter.
Returns the default options set via
set_default_options()if set, otherwise returns the built-in hardcoded default options fromget_hardcoded_default_options().- Returns:
The default options.
- Return type:
- classmethod get_hardcoded_default_options() Any[source]π
Get the built-in hardcoded default options for the reporter.
This abstract method must be implemented by all
Reportersubclasses. It defines the base class default options for a reporter and must be available in allReportersubclasses.It returns the hardcoded default
ReporterOptionssub-class instance specific to the reporter.Sub-classes must implement the following class variables:
_OPTIONS_TYPE: ClassVar[type[MyOptions]] = MyOptions _OPTIONS_KWARGS: ClassVar[dict[str, Any]] = {β¦}
or the method will raise an exception.
- Returns:
The built-in hardcoded default
ReporterOptionsinstance.- Raises:
SimpleBenchNotImplementedError β If required class variables are not implemented or are of incorrect types.
- property options_type: type[ReporterOptions]π
The specific
ReporterOptionssubclass associated with this reporter.
- abstract render(
- *,
- case: Case,
- section: Section,
- options: ReporterOptions,
Render the report for a specific case and section.
This abstract method must be implemented by all
Reportersubclasses. It is responsible for generating the actual report content for a given case and section, based on the provided options.The output can be a string, bytes, or a Rich object (
TextorTable).- Parameters:
case (
Case) β TheCaseinstance containing the benchmark results.section (
Section) β The specificSectionof the results to render.options (
ReporterOptions) β The reporter-specificReporterOptionsfor rendering.
- Returns:
The rendered report content.
- Return type:
- Raises:
NotImplementedError β If the method is not implemented in a subclass.
- report(
- *,
- log_metadata: ReportLogMetadata,
- args: Namespace,
- case: Case,
- choice: Choice,
- path: Path | None = None,
- session: Session | None = None,
- callback: ReporterCallback | None = None,
Generate a report based on the benchmark results.
This method performs validation and then calls the subclassβs
run_report()method.- Parameters:
log_metadata (
ReportLogMetadata) β The metadata for the report log.args (
Namespace) β The parsed command-line arguments.case (
Case) β TheCaseinstance containing benchmark results.choice (
Choice) β TheChoiceinstance specifying the report configuration.path (
Path| None, optional) β The path to the directory where the report can be saved if needed. Leave asNoneif not saving to the filesystem. Defaults toNone.session (
Session| None, optional) β TheSessioninstance containing benchmark results. Defaults toNone.callback (
ReporterCallback| None, optional) β A callback function for additional processing of the report. Defaults toNone.
- run_report(
- *,
- args: Namespace,
- log_metadata: ReportLogMetadata,
- case: Case,
- choice: Choice,
- path: Path | None = None,
- session: Session | None = None,
- callback: ReporterCallback | None = None,
Orchestration hook for report generation.
This method is the primary customization point for controlling how a report is generated. It is called by the public
report()method after all inputs have been validated.The default implementation calls
render_by_section(), which is suitable for most reporters. Subclasses can override this method to provide alternative orchestration, such as callingrender_by_case()for reports that are generated once per case.Note
This is also the correct place to implement custom logic for non-standard targets like
CUSTOM.- Parameters:
args (
Namespace) β The parsed command-line arguments.log_metadata (:class:`~simplebench.reporters.log.report_log_metadata.Report) β The metadata for the report log.
case (
Case) β TheCaseinstance representing the benchmarked code.choice (
Choice) β TheChoiceinstance specifying the report configuration.path (
Path| None, optional) β The path to the directory where report files will be saved. Defaults toNone.session (
Session| None, optional) β TheSessioninstance containing benchmark results. Defaults toNone.callback (
ReporterCallback| None, optional) β A callback function for additional processing. Defaults toNone.
- classmethod set_default_options(
- options: ReporterOptions | None = None,
Set the default options for the reporter.
- Parameters:
options (
ReporterOptionsor None, optional) β The options to set as the default, defaults to None
- supported_formats() frozenset[Format][source]π
The set of supported
Formatfor the reporter.This is the set of
Formatthat the reporter can output in.Defined
Choicecan only includeFormatthat are declared in this set.
- class simplebench.reporters.reporter.ReporterConfig(
- *,
- name: str,
- description: str,
- sections: frozenset[Section],
- targets: frozenset[Target],
- default_targets: frozenset[Target],
- formats: frozenset[Format],
- choices: ChoicesConf,
- file_suffix: str,
- file_unique: bool,
- file_append: bool,
- subdir: str,
Bases:
objectImmutable, attribute-based base configuration for a Reporter.
This frozen dataclass serves as the foundation for all specific reporter configuration classes (e.g.,
RichTableConfig). It defines the common data structure and centralizes the validation of all parameters required by reporters.The
sections,targets, andformatsparameters act as master lists, constraining the values that can be used within thechoicesanddefault_targetsparameters.As a frozen dataclass, instances of this class are immutable; their state cannot be changed after creation. Validation and normalization of inputs are performed automatically in the
__post_init__method.- choicesπ
Defines the reporterβs command-line interface flags.
- Type:
- choices: ChoicesConfπ
A
ChoicesConfobject defining the reporterβs command-line interface flags. These flags allow end-users to precisely control report generation by specifying which sections to include, what output format to use, and where to send the report (targets). They can also control other reporter-specific options.
- default_targets: frozenset[Target]π
The default subset of
targetsto use if not specified. Must be a subset of the maintargetsset.
- file_append: boolπ
If
True, append to the output file if it already exists. Mutually exclusive withfile_unique; exactly one must beTrue.
- file_suffix: strπ
The file extension to use for filesystem targets (e.g., βtxtβ), without the leading dot.
The suffix must consist only of alphanumeric characters and be 10 characters or less in length.
- file_unique: boolπ
If
True, generate a unique filename for each output. Mutually exclusive withfile_append; exactly one must beTrue.
- formats: frozenset[Format]π
The master set of
Formatenums this reporter can produce. This constrains the formats that can be used by anyChoiceConfin thechoiceslist.
- sections: frozenset[Section]π
The master set of
Sectionenums this reporter can handle. This constrains the sections that can be used by anyChoiceConfin thechoiceslist.
- subdir: strπ
The subdirectory within the results directory to save files to. An empty string (
'') specifies the root of the results directory (i.e., no subdirectory).A subdirectory path should only contain valid directory name elements separated by forward slashes (
'/'). Each element must consist only of alphanumeric, underscore, or dash characters, cannot be longer than 64 characters and cannot start or end with a dash or underscore.Empty elements (i.e., consecutive slashes) are not allowed. Paths cannot start or end with a slash.
The total length of the subdirectory path must not exceed 255 characters.
- targets: frozenset[Target]π
The master set of
Targetenums this reporter can output to. This constrains the targets that can be used bydefault_targetsand anyChoiceConfin thechoiceslist.
- class simplebench.reporters.reporter.ReporterOptions[source]π
Bases:
objectMarker base class for reporter related options.
This class serves as a base for all reporter-specific options classes used within the simplebench framework. It provides a common base type for all reporter options.
These options classes can be used to encapsulate configuration settings specific to different reporter implementations and are typically used in Choice() and Case() objects to customize reporter behavior.
Subpackagesπ
Submodulesπ
- simplebench.reporters.reporter.config module
ReporterConfigReporterConfig.nameReporterConfig.descriptionReporterConfig.sectionsReporterConfig.targetsReporterConfig.default_targetsReporterConfig.formatsReporterConfig.choicesReporterConfig.file_suffixReporterConfig.file_uniqueReporterConfig.file_appendReporterConfig.subdirReporterConfig.choicesReporterConfig.default_targetsReporterConfig.descriptionReporterConfig.file_appendReporterConfig.file_suffixReporterConfig.file_uniqueReporterConfig.formatsReporterConfig.nameReporterConfig.sectionsReporterConfig.subdirReporterConfig.targets
- simplebench.reporters.reporter.options module
- simplebench.reporters.reporter.prioritized module
- simplebench.reporters.reporter.protocols module
ReporterProtocolReporterProtocol.add_boolean_flags_to_argparse()ReporterProtocol.add_choice()ReporterProtocol.add_flags_to_argparse()ReporterProtocol.add_list_of_targets_flags_to_argparse()ReporterProtocol.choicesReporterProtocol.configReporterProtocol.default_targetsReporterProtocol.descriptionReporterProtocol.dispatch_to_targets()ReporterProtocol.file_appendReporterProtocol.file_suffixReporterProtocol.file_uniqueReporterProtocol.find_options_by_type()ReporterProtocol.get_all_stats_values()ReporterProtocol.get_base_unit_for_section()ReporterProtocol.get_default_options()ReporterProtocol.get_hardcoded_default_options()ReporterProtocol.get_prioritized_default_targets()ReporterProtocol.get_prioritized_file_append()ReporterProtocol.get_prioritized_file_suffix()ReporterProtocol.get_prioritized_file_unique()ReporterProtocol.get_prioritized_options()ReporterProtocol.get_prioritized_subdir()ReporterProtocol.nameReporterProtocol.render()ReporterProtocol.render_by_case()ReporterProtocol.render_by_section()ReporterProtocol.report()ReporterProtocol.rich_text_to_plain_text()ReporterProtocol.run_report()ReporterProtocol.select_targets_from_args()ReporterProtocol.set_default_options()ReporterProtocol.subdirReporterProtocol.supported_formats()ReporterProtocol.supported_sections()ReporterProtocol.supported_targets()ReporterProtocol.target_callback()ReporterProtocol.target_console()ReporterProtocol.target_filesystem()
- simplebench.reporters.reporter.reporter module
ReporterReporter.add_choice()Reporter.choicesReporter.configReporter.default_targetsReporter.descriptionReporter.file_appendReporter.file_suffixReporter.file_uniqueReporter.find_options_by_type()Reporter.get_all_stats_values()Reporter.get_base_unit_for_section()Reporter.get_default_options()Reporter.get_hardcoded_default_options()Reporter.nameReporter.options_typeReporter.render()Reporter.report()Reporter.run_report()Reporter.set_default_options()Reporter.subdirReporter.supported_formats()Reporter.supported_sections()Reporter.supported_targets()
deferred_core_imports()