simplebench.reporters.reporter_manager.manager moduleπ
ReporterManager for benchmark results.
This module contains the ReporterManager class, which manages the registration,
retrieval, and unregistration of Reporter
classes and instances.
This registry is global. When a Reporter is registered,
it is added to the global registry, and when it is unregistered, it is removed from the
global registry.
- class simplebench.reporters.reporter_manager.manager.ReporterManager(load_defaults: bool = True)[source]π
Bases:
objectManager for all available
Reporterclasses.This class maintains a registry of
Reporterinstances and their associated CLI arguments. It allows for the registration, retrieval, and unregistration ofReporterinstances.Initially, it registers a set of built-in
Reporterinstances:CSVReporter,ScatterPlotReporter, andRichTableReporter.New
Reporterinstances can be added using theregister()method, and existing ones can be removed using theunregister()orunregister_by_name()methods.Reporterinstances are required to have unique names and CLI arguments in theirChoicesto avoid conflicts and the manager will raise exceptions if duplicates are detected during registration.Registering a custom reporter exampleπ1reporter_manager = ReporterManager() 2my_custom_reporter = CustomReporter() 3reporter_manager.register(my_custom_reporter)
Initialize the ReporterManager.
By default, this loads a set of predefined
Reporterinstances and then any reporters registered via theregister_reporter()decorator.If one of the predefined reportersβ dependencies are not installed, that reporter will be skipped and not registered.
If desired, this can be skipped by setting
load_defaultstoFalse. In which case, the manager starts with an empty registry andReporterinstances can be added via theregister()method.- Parameters:
load_defaults (bool) β Whether to load the predefined reporters. Defaults to
True.
- add_reporters_to_argparse(
- parser: ArgumentParser,
Add all registered reporter choices to an
ArgumentParser.This method adds the CLI arguments for all registered reporters to the provided
ArgumentParserinstance using theadd_flags_to_argparse()method of eachReporter.- Parameters:
parser (
ArgumentParser) β TheArgumentParserto add the flags to.
- all_reporters() dict[str, Reporter][source]π
Return all available
Reporterinstances as a dictionary keyed by their names.
- choice_for_arg(
- arg: str,
Return the
Choiceinstance for a given CLI argument.
- register(
- reporter: Reporter,
Register a new
Reporter.This method adds a new
Reporterto the registry. Unlike the predefined reporters and theregister_reporter()decorator which both register by class, this method requires an instance of theReporter.This allows for more flexibility, such as registering
Reporterinstances with custom initialization parameters.- Parameters:
- Raises:
SimpleBenchValueError β If a
Reporterwith the same name or CLI argument is already registered.SimpleBenchTypeError β If the provided reporter is not an instance of
Reporter.
- unregister(
- reporter: Reporter,
Unregister a
Reporterby an instance exemplar.It looks up the reporter by its name and removes it from the registry.
reporter_manager.unregister(MyCustomReporter())
- Parameters:
reporter (
Reporter) βReporterinstance exemplar to unregister.- Raises:
SimpleBenchKeyError β If no reporter with the given name is registered.
SimpleBenchTypeError β If the provided reporter is not an instance of
Reporter.