quantlab.core.component.Component#
- class quantlab.core.component.Component[source]#
Bases:
objectRoot of every configurable object: serialised and rebuilt by declaration.
A subclass declares
config_cls, the config dataclass it is built from, and holds its config asself.config; the component fields of that dataclass are declared withcomponent().get_configandfrom_configthen need no code of their own. A component with a shape of its own may override either.Examples
With
factorany factor built earlier:>>> saved = factor.get_config() >>> type(factor).from_config(saved) == factor True
- config#
The component’s config, an instance of
config_cls.
- config_cls#
The config dataclass the component is built from and rebuilt with.
- classmethod from_config(config, run_dir=None)[source]#
Rebuild the component from the dict
get_config()returned.The declared component fields are rebuilt first, each by the class its own
"name"names, withrun_dirpassed down; the object is then constructed fromconfig_cls. The top-level"name"is kept only when the config class has such a field.configis not modified.- Parameters:
- configMapping
The saved config of a component of this class.
- run_dirstr or os.PathLike, optional
The run directory the config was read from.
- Returns:
- Component
The rebuilt component.
- Raises:
- TypeError
If the class declares no config class.
- ValueError
If
configholds a key the config class does not have.
Examples
>>> from quantlab.label.forward import Forward >>> Forward.from_config(label.get_config()) == label True
- get_config()[source]#
Return the config as a plain dict with the class’s import path as
"name".Declared component fields hold their components’ own configs (see
config_to_dict).Examples
>>> cfg = label.get_config() >>> cfg["name"], cfg["factor"]["name"] ('quantlab.label.forward.Forward', 'quantlab.factor.predefined.momentum.Momentum')
- property import_path#
The class as a dotted import path, the
nameof its config.Examples
>>> label.import_path 'quantlab.label.forward.Forward'
- store_uses()[source]#
Return the stores this component uses itself, and how; none here.
Each entry is a
quantlab.core.store_uses.StoreUse(a store path and its relation:"reads","owns"or"source") or aBuiltFromnaming a sub-component the store is only built from. A component declares only its own direct uses: the components in its fields declare theirs, andwalk_store_usesgathers a whole tree. A dataset declares the store its panel reads, a factor its store, a factor risk model its regression and estimate stores.Examples
>>> label.store_uses() # a Forward label writes through its factor () >>> [(use.relation, use.handle is factor) for use in factor.store_uses()] [('owns', True)]