lenskit.pipeline.AutoConfig#

class lenskit.pipeline.AutoConfig(*args, **kwargs)#

Bases: ConfigurableComponent

Mixin class providing automatic configuration support based on constructor arguments.

This method provides implementations of get_config() and from_config() that inspect the constructor arguments and instance variables to automatically provide configuration support. By default, all constructor parameters will be considered configuration parameters, and their values will be read from instance variables of the same name. Subclasses can also define EXTRA_CONFIG_FIELDS and IGNORED_CONFIG_FIELDS class variables to modify this behavior. Missing attributes are silently ignored.

In the simple case, you can write a class like this and get config for free:

class MyComponent(AutoConfig):
    some_param: int

    def __init__(self, some_param: int = 20):
        self.some_param = some_param

For compatibility with pipeline serialization, all configuration data should be JSON-compatible.

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

from_config(cfg)

Create a class from the specified construction.

get_config()

Get the configuration by inspecting the constructor and instance variables.

Attributes

EXTRA_CONFIG_FIELDS

Names of instance variables that should be included in the configuration dictionary even though they do not correspond to named constructor arguments.

IGNORED_CONFIG_FIELDS

Names of constructor parameters that should be excluded from the configuration dictionary.

EXTRA_CONFIG_FIELDS: ClassVar[list[str]] = []#

Names of instance variables that should be included in the configuration dictionary even though they do not correspond to named constructor arguments.

Note

This is rarely needed, and usually needs to be coupled with **kwargs in the constructor to make the resulting objects constructible.

IGNORED_CONFIG_FIELDS: ClassVar[list[str]] = []#

Names of constructor parameters that should be excluded from the configuration dictionary.

get_config()#

Get the configuration by inspecting the constructor and instance variables.

Return type:

dict[str, object]

classmethod from_config(cfg)#

Create a class from the specified construction. Configuration elements are passed to the constructor as keywrod arguments.

Parameters:

cfg (dict[str, Any])

Return type:

Self