Skip to content

minrecord

minrecord

Root package.

minrecord.BaseComparator

Bases: Generic[T], ABC

Define the base comparator class to implement a comparator.

Example usage:

>>> from minrecord import MinScalarComparator
>>> comparator = MinScalarComparator()
>>> comparator.is_better(old_value=0.4, new_value=0.6)
False
>>> comparator.get_initial_best_value()
inf

minrecord.BaseComparator.equal abstractmethod

equal(other: Any) -> bool

Indicate if two comparators are equal or not.

Parameters:

Name Type Description Default
other Any

The other object to compare with.

required

Returns:

Type Description
bool

True if the comparators are equal, False otherwise.

Example usage:

>>> from minrecord import MinScalarComparator, MaxScalarComparator
>>> comparator = MinScalarComparator()
>>> comparator.equal(MinScalarComparator())
True
>>> comparator.equal(MaxScalarComparator())
False

minrecord.BaseComparator.get_initial_best_value abstractmethod

get_initial_best_value() -> T

Get the initial best value.

Returns:

Type Description
T

The initial best value.

Example usage:

>>> from minrecord import MinScalarComparator
>>> comparator = MinScalarComparator()
>>> comparator.get_initial_best_value()
inf

minrecord.BaseComparator.is_better abstractmethod

is_better(old_value: T, new_value: T) -> bool

Indicate if the new value is better than the old value.

Parameters:

Name Type Description Default
old_value T

The old value to compare.

required
new_value T

The new value to compare.

required

Returns:

Type Description
bool

True if the new value is better than the old value, otherwise False.

Example usage:

>>> from minrecord import MinScalarComparator
>>> comparator = MinScalarComparator()
>>> comparator.is_better(old_value=0.4, new_value=0.6)
False

minrecord.BaseRecord

Bases: Generic[T], ABC

Define the base class to implement a record.

The record tracks the value added as well as the step when the value is added. The goal of this class is to track the recent record because the loggers (e.g. MLFlow or Tensorboard) do not allow to get the last value or the best value. The record keeps in memory a recent record of pairs (step, value) where step is the index of the step when the value was added. The length of the recent record depends on the concrete implementation.

To implement your own record, you will need to define the following methods:

- ``add_value``
- ``get_last_value``
- ``get_most_recent``
- ``is_comparable``
- ``is_empty``
- ``update``
- ``load_state_dict``
- ``state_dict``

If it is a comparable record, you will need to implement the following methods too:

- ``_get_best_value``
- ``_has_improved``

You may also need to extend the config_dict method.

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.add_value(value=2, step=0)
>>> record.add_value(value=1.2, step=1)
>>> record.get_last_value()
1.2

minrecord.BaseRecord.name abstractmethod property

name: str

The name of the record.

minrecord.BaseRecord._get_best_value

_get_best_value() -> T

Get the best value of this record.

You need to implement this method for a comparable record.

Returns:

Type Description
T

The best value of this record.

Raises:

Type Description
NotImplementedError

if this method is not implemented.

minrecord.BaseRecord._has_improved

_has_improved() -> bool

Indicate if the last value is the best value.

You need to implement this method for a comparable record.

Returns:

Type Description
bool

True if the last value is the best value, otherwise False.

Raises:

Type Description
NotImplementedError

if this method is not implemented

minrecord.BaseRecord.add_value abstractmethod

add_value(value: T, step: float | None = None) -> None

Add a new value to the record.

Parameters:

Name Type Description Default
value T

The value to add to the record.

required
step float | None

The step value to record. None means there is no step to track.

None

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.add_value(value=2)
>>> record.add_value(value=42, step=1)
>>> record
Record(name=loss, max_size=10, size=2)

minrecord.BaseRecord.clone abstractmethod

clone() -> BaseRecord

Clone the current record.

Returns:

Type Description
BaseRecord

A copy of the current record.

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record_cloned = record.clone()
>>> record_cloned
Record(name=loss, max_size=10, size=0)

minrecord.BaseRecord.config_dict

config_dict() -> dict[str, Any]

Get the config of the record.

The config dictionary should contain all the values necessary to instantiate a record with the same parameters with the factory method. It is expected to contain values like the full name of the class and the arguments of the constructor. This dictionary should not contain the state values. It is possible to get the state values with the state_dict method.

Returns:

Type Description
dict[str, Any]

The config of the record.

Example usage:

>>> from minrecord import BaseRecord, Record
>>> config = Record("loss").config_dict()
>>> record = BaseRecord.factory(**config)  # Note that the state is not copied.
>>> record
Record(name=loss, max_size=10, size=0)

minrecord.BaseRecord.equal abstractmethod

equal(other: Any) -> bool

Indicate if two records are equal or not.

Parameters:

Name Type Description Default
other Any

The object to compare.

required

Returns:

Type Description
bool

True if the records are equal, False otherwise.

Example usage:

>>> from minrecord import Record
>>> record1 = Record("loss")
>>> record2 = Record("accuracy")
>>> record3 = Record("loss")
>>> record1.equal(record2)
False
>>> record1.equal(record1)
True

minrecord.BaseRecord.from_dict classmethod

from_dict(data: dict) -> BaseRecord

Instantiate a record from a dictionary.

Parameters:

Name Type Description Default
data dict

The dictionary that is used to instantiate the record. The dictionary is expected to contain the parameters to create instantiate the record and the state of the record.

required

Returns:

Type Description
BaseRecord

The instantiated record.

Example usage:

>>> from minrecord import BaseRecord
>>> from objectory import OBJECT_TARGET
>>> record = BaseRecord.from_dict(
...     {
...         "config": {
...             OBJECT_TARGET: "minrecord.Record",
...             "name": "loss",
...             "max_size": 7,
...         },
...         "state": {"record": ((0, 1), (1, 5))},
...     }
... )
>>> record
Record(name=loss, max_size=7, size=2)

minrecord.BaseRecord.get_best_value

get_best_value() -> T

Get the best value of this record.

It is possible to get the best value only if it is a comparable record i.e. it is possible to compare the values in the record.

Returns:

Type Description
T

The best value of this record.

Raises:

Type Description
NotAComparableRecord

if it is not a comparable record.

EmptyRecordError

if the record is empty

Example usage:

>>> from minrecord import MaxScalarRecord
>>> record = MaxScalarRecord("accuracy")
>>> record.add_value(value=2, step=0)
>>> record.add_value(value=4, step=1)
>>> record.get_best_value()
4

minrecord.BaseRecord.get_last_value abstractmethod

get_last_value() -> T

Get the last value.

Returns:

Type Description
T

The last value added in the record.

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.add_value(value=2, step=0)
>>> record.add_value(value=1.2, step=1)
>>> record.get_last_value()
1.2
>>> record.add_value(value=0.8, step=1)
>>> record.get_last_value()
0.8

minrecord.BaseRecord.get_most_recent abstractmethod

get_most_recent() -> tuple[tuple[float | None, T], ...]

Get the tuple of recent values and their associated steps.

The last value in the tuple is the last value added to the record. The length of the recent record depends on the concrete implementation.

Returns:

Type Description
tuple[tuple[float | None, T], ...]

A tuple of the recent values in the record.

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.add_value(value=2)
>>> record.add_value(value=1.2, step=1)
>>> record.add_value(value=0.8, step=2)
>>> record.get_most_recent()
((None, 2), (1, 1.2), (2, 0.8))

minrecord.BaseRecord.has_improved

has_improved() -> bool

Indicate if the last value is the best value.

It is possible to use this method only if it is a comparable record i.e. it is possible to compare the values in the record.

Returns:

Type Description
bool

True if the last value is the best value, otherwise False.

Raises:

Type Description
NotAComparableRecord

if it is not a comparable record.

EmptyRecordError

if the record is empty

>>> from minrecord import MaxScalarRecord
>>> record = MaxScalarRecord("accuracy")
>>> record.add_value(value=2, step=0)
>>> record.add_value(value=4, step=1)
>>> record.has_improved()
True

minrecord.BaseRecord.is_comparable abstractmethod

is_comparable() -> bool

Indicate if it is possible to compare the values in the record.

Note that it is possible to compute the best value only for records that are comparable.

Returns:

Type Description
bool

True if it is possible to compare the values in the record, otherwise False.

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.is_comparable()
False

minrecord.BaseRecord.is_empty abstractmethod

is_empty() -> bool

Indicate if the record is empty or not.

Returns:

Type Description
bool

True if the record is empty, otherwise False.

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.is_empty()
True

minrecord.BaseRecord.load_state_dict abstractmethod

load_state_dict(state_dict: dict[str, Any]) -> None

Set up the record from a dictionary containing the state values.

Parameters:

Name Type Description Default
state_dict dict[str, Any]

A dictionary containing state keys with values.

required

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.load_state_dict({"record": ((0, 42.0),)})
>>> record.get_last_value()
42.0

minrecord.BaseRecord.state_dict abstractmethod

state_dict() -> dict[str, Any]

Get a dictionary containing the state values of the record.

Returns:

Type Description
dict[str, Any]

The state values in a dict.

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.add_value(42.0, step=0)
>>> state = record.state_dict()
>>> state
{'record': ((0, 42.0),)}

minrecord.BaseRecord.to_dict

to_dict() -> dict[str, Any]

Export the current record to a dictionary.

This method exports all the information to re-create the record with the same state. The returned dictionary can be used as input of the from_dict method to resume the record.

Returns:

Type Description
dict[str, Any]

A dictionary with the config and the state of the record.

Example usage:

>>> from minrecord import BaseRecord, Record
>>> record_dict = Record("loss").to_dict()
>>> record = BaseRecord.from_dict(record_dict)
>>> record
Record(name=loss, max_size=10, size=0)

minrecord.BaseRecord.update abstractmethod

update(elements: Iterable[tuple[float | None, T]]) -> None

Update the record by adding the elements.

Parameters:

Name Type Description Default
elements Iterable[tuple[float | None, T]]

The elements to add to the record. Each tuple has the following structure (step, value). The step can be None if there is no step.

required

Example usage:

>>> from minrecord import Record
>>> record = Record("loss")
>>> record.update([(0, 42), (1, 45)])
>>> record
Record(name=loss, max_size=10, size=2)

minrecord.ComparableRecord

Bases: Record[T]

Implement a record of comparable values.

Parameters:

Name Type Description Default
name str

The name of the record.

required
comparator BaseComparator[T]

The comparator to use to find the best value.

required
elements Iterable[tuple[int | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum number of elements to store inthe record.

10
best_value T | None

The initial best value. If None, the initial best value of the comparator is used.

None
improved bool

Indicate if the last value is the best value or not.

False

Example usage:

>>> from minrecord import ComparableRecord
>>> from minrecord.comparator import MaxScalarComparator
>>> record = ComparableRecord("value", MaxScalarComparator())
>>> record.add_value(64.0)
>>> record.add_value(42.0)
>>> record.get_last_value()
42.0
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_best_value()
64.0

minrecord.ComparableRecord.is_better

is_better(old_value: T, new_value: T) -> bool

Indicate if the new value is better than the old value.

Parameters:

Name Type Description Default
old_value T

The old value to compare.

required
new_value T

The new value to compare.

required

Returns:

Type Description
bool

True if the new value is better than the old value, otherwise False.

Example usage:

>>> from minrecord import ComparableRecord
>>> from minrecord.comparator import MaxScalarComparator
>>> record = ComparableRecord("accuracy", MaxScalarComparator())
>>> record.is_better(new_value=1, old_value=0)
True
>>> record.is_better(new_value=0, old_value=1)
False

minrecord.EmptyRecordError

Bases: Exception

Raise an error if the record is empty.

minrecord.MaxScalarComparator

Bases: BaseComparator[float]

Implement a max comparator for scalar value.

This comparator can be used to find the maximum value between two scalar values.

Example usage:

>>> from minrecord import MaxScalarComparator
>>> comparator = MaxScalarComparator()
>>> comparator.is_better(old_value=0.4, new_value=0.6)
True
>>> comparator.get_initial_best_value()
-inf

minrecord.MaxScalarRecord

Bases: ComparableRecord[Number]

A specific implementation to track the max value of a scalar record.

This record uses the MaxScalarComparator to find the best value of the record.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[int | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum number of elements to store inthe record.

10
best_value T | None

The initial best value. If None, the initial best value of the comparator is used.

None
improved bool

Indicate if the last value is the best value or not.

False

Example usage:

>>> from minrecord import MaxScalarRecord
>>> record = MaxScalarRecord("value")
>>> record.add_value(64.0)
>>> record.add_value(42.0)
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
64.0

minrecord.MaxScalarRecord.from_elements classmethod

from_elements(
    name: str, elements: Iterable[tuple[float | None, T]]
) -> Self

Instantiate a MaxScalarRecord object from the elements.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[float | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

required

Returns:

Type Description
Self

The instantiated record.

Example usage:

>>> from minrecord import MaxScalarRecord
>>> record = MaxScalarRecord.from_elements("value", ((None, 64.0), (None, 42.0)))
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
64.0

minrecord.MinScalarComparator

Bases: BaseComparator[float]

Implementation of a min comparator for scalar value.

This comparator can be used to find the minimum value between two scalar values.

Example usage:

>>> from minrecord import MinScalarComparator
>>> comparator = MinScalarComparator()
>>> comparator.is_better(old_value=0.4, new_value=0.6)
False
>>> comparator.get_initial_best_value()
inf

minrecord.MinScalarRecord

Bases: ComparableRecord[Number]

A specific implementation to track the min value of a scalar record.

This record uses the MinScalarComparator to find the best value of the record.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[int | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum number of elements to store inthe record.

10
best_value T | None

The initial best value. If None, the initial best value of the comparator is used.

None
improved bool

Indicate if the last value is the best value or not.

False

Example usage:

>>> from minrecord import MinScalarRecord
>>> record = MinScalarRecord("value")
>>> record.add_value(64.0)
>>> record.add_value(42.0)
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
42.0

minrecord.MinScalarRecord.from_elements classmethod

from_elements(
    name: str, elements: Iterable[tuple[float | None, T]]
) -> Self

Instantiate a MaxScalarRecord object from the elements.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[float | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

required

Returns:

Type Description
Self

The instantiated record.

Example usage:

>>> from minrecord import MinScalarRecord
>>> record = MinScalarRecord.from_elements("value", ((None, 64.0), (None, 42.0)))
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
42.0

minrecord.NotAComparableRecordError

Bases: Exception

Raise an error if it is not possible to compare the values in the record.

minrecord.Record

Bases: BaseRecord[T]

Implement a generic record to store the recent values.

Internally, this class uses a deque to keep the most recent values added in the record. Note that this class does not allow to get the best value because it is not possible to define a generic rule to know the best object. Please see ScalarRecord that can compute the best value for scalars.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[int | None, T]]

The initial elements in the record. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum size of the record.

get_max_size()

Example usage:

>>> from minrecord import Record
>>> record = Record(name="value", elements=((None, 64.0), (None, 42.0)))
>>> record
Record(name=value, max_size=10, size=2)
>>> record.get_last_value()
42.0
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))

minrecord.Record.max_size property

max_size: int

The maximum size of the record.

minrecord.RecordManager

Implement a simple record manager.

This class proposes an approach to manage a group of records, but it is possible to use other approaches. If this class does not fit your needs, feel free to use another approach.

Parameters:

Name Type Description Default
records dict[str, BaseRecord] | None

The initial records to add to the manager.

None

Example usage:

>>> from minrecord import RecordManager, MinScalarRecord
>>> manager = RecordManager()
>>> manager.add_record(MinScalarRecord("loss"))
>>> manager.get_record("loss")
MinScalarRecord(name=loss, max_size=10, size=0)
>>> manager.get_record("new_record")
Record(name=new_record, max_size=10, size=0)

minrecord.RecordManager.add_record

add_record(
    record: BaseRecord,
    key: str | None = None,
    exist_ok: bool = False,
) -> None

Add a record to the manager.

Parameters:

Name Type Description Default
record BaseRecord

The record to add to the manager.

required
key str | None

The key to store the record. If None, the name of the record is used.

None
exist_ok bool

If False, RuntimeError is raised if the key already exists. This parameter should be set to True to overwrite the record for this key.

False

Raises:

Type Description
RuntimeError

if a record is already registered for the key and exist_ok=False.

Example usage:

>>> from minrecord import RecordManager, MinScalarRecord
>>> manager = RecordManager()
>>> manager.add_record(MinScalarRecord("loss"))
>>> manager
RecordManager(
  (loss): MinScalarRecord(name=loss, max_size=10, size=0)
)
>>> manager.add_record(MinScalarRecord("loss"), "my key")
>>> manager
RecordManager(
  (loss): MinScalarRecord(name=loss, max_size=10, size=0)
  (my key): MinScalarRecord(name=loss, max_size=10, size=0)
)

minrecord.RecordManager.get_best_values

get_best_values(
    prefix: str = "", suffix: str = ""
) -> dict[str, Any]

Get the best value of each metric.

This method ignores the metrics with empty record and the non-comparable record.

Parameters:

Name Type Description Default
prefix str

The prefix used to create the dict of best values. The goal of this prefix is to generate a name which is different from the metric name to avoid confusion. By default, the returned dict uses the same name as the metric.

''
suffix str

The suffix used to create the dict of best values. The goal of this suffix is to generate a name which is different from the metric name to avoid confusion. By default, the returned dict uses the same name as the metric.

''

Returns:

Type Description
dict[str, Any]

The dict with the best value of each metric.

Example usage:

>>> from minrecord import RecordManager, MaxScalarRecord
>>> manager = RecordManager()
>>> manager.add_record(MaxScalarRecord("accuracy"))
>>> manager.get_record("accuracy").add_value(42.0)
>>> manager.get_best_values()
{'accuracy': 42.0}
>>> manager.get_best_values(prefix="best/")
{'best/accuracy': 42.0}
>>> manager.get_best_values(suffix="/best")
{'accuracy/best': 42.0}

minrecord.RecordManager.get_record

get_record(key: str) -> BaseRecord

Get the record associated to a key.

Parameters:

Name Type Description Default
key str

The key of the record to retrieve.

required

Returns:

Type Description
BaseRecord

The record if it exists, otherwise it returns an empty record. The created empty record is a Record object.

Example usage:

>>> from minrecord import RecordManager, MinScalarRecord
>>> manager = RecordManager()
>>> manager.add_record(MinScalarRecord("loss"))
>>> manager.get_record("loss")
MinScalarRecord(name=loss, max_size=10, size=0)
>>> manager.get_record("new_record")
Record(name=new_record, max_size=10, size=0)

minrecord.RecordManager.get_records

get_records() -> dict[str, BaseRecord]

Get all the records.

Returns:

Type Description
dict[str, BaseRecord]

The records with their associated keys.

Example usage:

>>> from minrecord import RecordManager, MinScalarRecord
>>> manager = RecordManager()
>>> manager.add_record(MinScalarRecord("loss"))
>>> manager.get_records()
{'loss': MinScalarRecord(name=loss, max_size=10, size=0)}

minrecord.RecordManager.has_record

has_record(key: str) -> bool

Indicate if the engine has a record for the given key.

Parameters:

Name Type Description Default
key str

The key of the record to check.

required

Returns:

Type Description
bool

True if the record exists, False otherwise

Example usage:

>>> from minrecord import RecordManager, MinScalarRecord
>>> manager = RecordManager()
>>> manager.add_record(MinScalarRecord("loss"))
>>> manager.has_record("loss")
True
>>> manager.has_record("missing")
False

minrecord.RecordManager.load_state_dict

load_state_dict(state_dict: dict) -> None

Load the state values from a dict.

Parameters:

Name Type Description Default
state_dict dict

A dict with the new state values.

required

Example usage:

>>> from minrecord import RecordManager, Record
>>> manager = RecordManager()
>>> manager.add_record(Record("value"))
>>> manager.load_state_dict({"value": {"state": {"record": ((0, 1), (1, 0.5), (2, 0.25))}}})
>>> manager.get_record("value").get_last_value()
0.25

minrecord.RecordManager.state_dict

state_dict() -> dict

Return a dictionary containing state values of all the records.

Returns:

Type Description
dict

The dictionary containing state values of all the records.

Example usage:

>>> from minrecord import RecordManager
>>> manager = RecordManager()
>>> manager.state_dict()
{}

minrecord.get_best_values

get_best_values(
    records: Mapping[str, BaseRecord],
    prefix: str = "",
    suffix: str = "",
) -> dict[str, Any]

Get the best value of each record.

This function ignores the empty and non-comparable records.

Parameters:

Name Type Description Default
records Mapping[str, BaseRecord]

The records and their associated keys.

required
prefix str

The prefix used to create the dict of best values. The goal of this prefix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''
suffix str

The suffix used to create the dict of best values. The goal of this suffix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''

Returns:

Type Description
dict[str, Any]

The dict with the best value of each record.

Example usage:

>>> from minrecord import (
...     MinScalarRecord,
...     MaxScalarRecord,
...     get_best_values,
... )
>>> record1 = MinScalarRecord.from_elements("loss", elements=[(None, 1.9), (None, 1.2)])
>>> record2 = MaxScalarRecord.from_elements("accuracy", elements=[(None, 42), (None, 35)])
>>> get_best_values({"loss": record1, "accuracy": record2})
{'loss': 1.2, 'accuracy': 42}
>>> get_best_values({"loss": record1, "accuracy": record2}, prefix="best/")
{'best/loss': 1.2, 'best/accuracy': 42}
>>> get_best_values({"loss": record1, "accuracy": record2}, suffix="/best")
{'loss/best': 1.2, 'accuracy/best': 42}

minrecord.get_last_values

get_last_values(
    records: Mapping[str, BaseRecord],
    prefix: str = "",
    suffix: str = "",
) -> dict[str, Any]

Get the last value of each record.

This function ignores the empty records.

Parameters:

Name Type Description Default
records Mapping[str, BaseRecord]

The records and their associated keys.

required
prefix str

The prefix used to create the dict of best values. The goal of this prefix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''
suffix str

The suffix used to create the dict of best values. The goal of this suffix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''

Returns:

Type Description
dict[str, Any]

The dict with the best value of each record.

Example usage:

>>> from minrecord import (
...     MinScalarRecord,
...     MaxScalarRecord,
...     get_best_values,
... )
>>> record1 = MinScalarRecord.from_elements("loss", elements=[(None, 1.9), (None, 1.2)])
>>> record2 = MaxScalarRecord.from_elements("accuracy", elements=[(None, 42), (None, 35)])
>>> get_best_values({"loss": record1, "accuracy": record2})
{'loss': 1.2, 'accuracy': 42}
>>> get_best_values({"loss": record1, "accuracy": record2}, prefix="best/")
{'best/loss': 1.2, 'best/accuracy': 42}
>>> get_best_values({"loss": record1, "accuracy": record2}, suffix="/best")
{'loss/best': 1.2, 'accuracy/best': 42}

minrecord.get_max_size

get_max_size() -> int

Get the current default maximum size of values to track in each record.

Returns:

Type Description
int

The current default maximum size of values to track in each record.

This value can be changed by using set_max_size.

Example usage:

>>> from minrecord import get_max_size
>>> get_max_size()
10

minrecord.set_max_size

set_max_size(max_size: int) -> None

Set the default maximum size of values to track in each record.

This function does not change the maximum size of records that are already created. It only changes the maximum size of records that will be created after the call of this function.

Parameters:

Name Type Description Default
max_size int

The new default maximum size of values to track in each record.

required

Example usage:

>>> from minrecord import get_max_size, set_max_size
>>> get_max_size()
10
>>> set_max_size(5)
>>> get_max_size()
5