pydistsim.benchmark.AlgorithmBenchmark

class AlgorithmBenchmark(algorithm: tuple[type[BaseAlgorithm] | tuple[type[BaseAlgorithm], dict]], max_time: float = inf, network_sizes: ~collections.abc.Iterable[int] = range(1, 20), directed_network: bool = False, check_algorithm_termination: bool = True, network_behavior: NetworkBehaviorModel = NetworkBehaviorModel(message_ordering=True, message_loss_indicator=None, clock_increment=None, node_processing_frequency=None, message_delay_indicator=None, bounded_communication_delays=True), metric_collector_factory: ~collections.abc.Callable[[], ~pydistsim.metrics.MetricCollector] = <class 'pydistsim.metrics.MetricCollector'>, network_generators: dict[~typing.Literal['DETERMINISTIC', 'RANDOM'], dict[str, ~collections.abc.Callable[[int], NetworkType]]] = {'DETERMINISTIC': {'complete': <function <lambda>>, 'hypercube': <function <lambda>>, 'ring': <function <lambda>>, 'square mesh': <function <lambda>>, 'square torus': <function <lambda>>, 'star': <function <lambda>>}, 'RANDOM': {'homogeneous': <function <lambda>>, 'rectangular mesh': <function <lambda>>, 'rectangular torus': <function <lambda>>}}, network_repeat_count: dict[~typing.Literal['DETERMINISTIC', 'RANDOM'], int] = {'DETERMINISTIC': 1, 'RANDOM': 5})[source]

Bases: object

This class is used to benchmark the performance of a given algorithm.

### Usage

from pydistsim.benchmark import AlgorithmBenchmark
from pydistsim.network.behavior import NetworkBehaviorModel

benchmark = AlgorithmBenchmark(
    ((Flood, {"initial_information": "Hello Wold!"}), ),
    network_sizes=range(1, 40),
    network_behavior=NetworkBehaviorModel.UnorderedRandomDelayCommunication,
)

benchmark.run()

plot = benchmark.plot_analysis() # In IPython, this will create a plot with the results

df = benchmark.get_results_dataframe() # Get the results as a pandas DataFrame

### Params

Parameters:
  • algorithm (AlgorithmsParam = tuple[type[BaseAlgorithm] | tuple[type[BaseAlgorithm], dict]]) – The algorithm to benchmark. It can be a single algorithm or a tuple of algorithms.

  • max_time (float, optional) – The maximum time in seconds to run the benchmark.

  • network_sizes (Iterable[int], optional) – The sizes of the networks to generate and run the algorithm on.

  • directed_network (bool, False by default) – If the generated networks must be directed.

  • check_algorithm_termination (bool, optional) – Whether to check if the algorithm terminated correctly. Only for NodeAlgorithms.

  • network_behavior (NetworkBehaviorModel, optional) – The network behavior model to use.

  • metric_collector_factory (Callable[[], MetricCollector], optional) – A factory function to create a MetricCollector instance.

  • network_generators (dict[Literal["DETERMINISTIC", "RANDOM"], dict[str, Callable[[int, bool], "NetworkType"]]]) – A dict of dicts containing network generators.

  • network_repeat_count (dict[Literal["DETERMINISTIC", "RANDOM"], int]) – A dict mapping generation type with the amount of repeats.

Methods

__init__

get_results_dataframe

Get the results of the benchmark as a pandas DataFrame.

get_test_params

plot_analysis

Plot the results of the benchmark using seaborn pairplot.

run

Run the benchmark

get_results_dataframe(grouped: bool = False)[source]

Get the results of the benchmark as a pandas DataFrame.

Parameters:
  • grouped – Group results by size and generation type.

  • grouped – bool, optional

Returns:

Results of the benchmark as a table.

Return type:

DataFrame

plot_analysis(x_vars: Iterable[str] = None, y_vars: Iterable[str] = None, result_filter: Callable[[dict[str, Any]], bool] = None, grouped=True, pairplot_kwargs: dict[str, Any] = {})[source]

Plot the results of the benchmark using seaborn pairplot.

### Example call:

benchmark.plot_analysis(
    x_vars=["Net. node count"],
    y_vars=["Qty. of messages sent", "Qty. of steps"],
    result_filter=lambda df: df["Network type"] in ('complete', 'ring'),
)

### Params

Parameters:
  • x_vars (Iterable[str], optional) – The variables to plot on the x-axis. By default, it is node count and edge count.

  • y_vars (Iterable[str], optional) – The variables on the y-axis. By default, it is all variables except node count and edge count.

  • result_filter (Callable[[dict[str, Any]], bool]) – Filter the results row by row. Optional.

  • grouped (bool, optional) – Whether to group the results by network size and generation type.

Returns:

The seaborn pairplot object.

run()[source]

Run the benchmark