evokit.accounting package

Submodules

evokit.accounting.accountant module

Inheritance diagram of evokit.accounting.accountant

class evokit.accounting.accountant.AccountantRecord[source]

Bases: Generic[T]

A record collected by an Accountant from an Algorithm. Also records the generation count and time of collection.

event: str

Event that triggered the handler.

generation: int

Generation count when the event event occurs.

value: T

Data collected in generation after event.

time: float

Time (by time.perf_counter()) when the event event occurs.

__init__(event: str, generation: int, value: ~evokit.accounting.accountant.T, time: float = <factory>) None
class evokit.accounting.accountant.Accountant[source]

Bases: Generic[C, T], Sequence[AccountantRecord[T]]

Monitor and collect data from a running Algorithm.

The Accountant should be registered to an Algorithm. Then, when an event fires in the algorithm, if that event is in events, then handler will be called with that algorithm as argument. Results are collected as a sequence of AccountantRecord.

Call Algorithm.register() to register an Accountant to a Algorithm. Call report() to retrieve collected records.

For type checking purposes, the Accountant has two type parameter C and T. C is the type of the observed Algorithm; T is the type of .value in the reported AccountantRecord.

Tutorial: Collect Runtime Statistics with Accountant.

__init__(events: Container[str], handler: Callable[[C], T], watch_automatic_events: bool = False)[source]
Parameters:
  • events – Events that trigger the handler.

  • handler – Callable that takes the attached algorithm as input.

  • watch_automatic_events – If True, also call handler on Algorithm.automatic_events.

report(scope: str | int | None = None) list[AccountantRecord[T]][source]

Report collected records.

Parameters:

scope

Option to filter which records to report. Can be an int, a str, or None:

  • If scope is an int : report record only if record.generation==scope.

  • If scope is an str : report record only if record.event==scope.

  • Otherwise, of if (by default) scope==None, report all records.

Each time an event fires in the attached Algorithm, if that event is registered in handlers, supply the Algorithm to the handler as argument then collect the result in an AccountantRecord. This method returns a list of all collected records.

is_registered() bool[source]

Return if this accountant is attached to an Algorithm.

purge() None[source]

Remove all collected records.

Effect:

Reset collected records to an empty list.

evokit.accounting.accountants module

evokit.accounting.accountants.fitness_accountant(events: list[str], watch_automatic_events: bool = False) Accountant[HomogeneousAlgorithm[Individual[Any]], tuple[float, ...]][source]

Return an Accountant that collects the Individual.fitness of the best individual in the population in the algorithm.

Arg:

events: Events that trigger the accountant. See Accountant.events.

watch_automatic_events: If True, then automatic events also trigger the accountant. See Algorithm.step()

evokit.accounting.accountants.size_accountant(events: list[str], watch_automatic_events: bool = False) Accountant[HomogeneousAlgorithm[Any], int][source]

Return an Accountant that collects the length of the population in the algorithm.

Arg:

events: Events that trigger the accountant. See Accountant.events.

watch_automatic_events: If True, then automatic events also trigger the accountant. See Algorithm.step()

evokit.accounting.visualisers module

evokit.accounting.visualisers.plot(records: Sequence[AccountantRecord[tuple[float, ...]]], track_generation: bool = False, use_line: bool = False, *args: Any, **kwargs: Any)[source]

Plot a sequence of AccountantRecord`s. Plot :attr:`AccountantRecord.value against AccountantRecord.time. Also set the X axis label.

Parameters:
  • records – Sequence of records. Each AccountantRecord.value must only hold either float or a 1-tuple of type tuple[float].

  • track_generation – If True, then also plot values collected at "STEP_BEGIN" and "STEP_END" as bigger (s=50), special (marker="*") markers. Otherwise, plot them as any other values.

  • use_line – If True, then plot a line plot. Otherwise, plot a scatter graph.

  • args – Passed to matplotlib.plot().

  • kwargs – Passed to matplotlib.plot().

Note

The parameter use_line is provided for convenience. Since some values might be nan, plotting and connecting only available data points could produce misleading plots.

Module contents

class evokit.accounting.Accountant[source]

Bases: Generic[C, T], Sequence[AccountantRecord[T]]

Monitor and collect data from a running Algorithm.

The Accountant should be registered to an Algorithm. Then, when an event fires in the algorithm, if that event is in events, then handler will be called with that algorithm as argument. Results are collected as a sequence of AccountantRecord.

Call Algorithm.register() to register an Accountant to a Algorithm. Call report() to retrieve collected records.

For type checking purposes, the Accountant has two type parameter C and T. C is the type of the observed Algorithm; T is the type of .value in the reported AccountantRecord.

Tutorial: Collect Runtime Statistics with Accountant.

__init__(events: Container[str], handler: Callable[[C], T], watch_automatic_events: bool = False)[source]
Parameters:
  • events – Events that trigger the handler.

  • handler – Callable that takes the attached algorithm as input.

  • watch_automatic_events – If True, also call handler on Algorithm.automatic_events.

report(scope: str | int | None = None) list[AccountantRecord[T]][source]

Report collected records.

Parameters:

scope

Option to filter which records to report. Can be an int, a str, or None:

  • If scope is an int : report record only if record.generation==scope.

  • If scope is an str : report record only if record.event==scope.

  • Otherwise, of if (by default) scope==None, report all records.

Each time an event fires in the attached Algorithm, if that event is registered in handlers, supply the Algorithm to the handler as argument then collect the result in an AccountantRecord. This method returns a list of all collected records.

is_registered() bool[source]

Return if this accountant is attached to an Algorithm.

purge() None[source]

Remove all collected records.

Effect:

Reset collected records to an empty list.

class evokit.accounting.AccountantRecord[source]

Bases: Generic[T]

A record collected by an Accountant from an Algorithm. Also records the generation count and time of collection.

event: str

Event that triggered the handler.

generation: int

Generation count when the event event occurs.

value: T

Data collected in generation after event.

time: float

Time (by time.perf_counter()) when the event event occurs.

__init__(event: str, generation: int, value: ~evokit.accounting.accountant.T, time: float = <factory>) None