commonpower.extensions.factories.Factory
- class Factory[source]
Bases:
objectFactories allow generating a large number of busses with several sub-components. So-called meta configurations can be defined which specify how to sample bounds and parameters of each bus/component. Components are described by templates which contain their class, meta config, and the probability that a bus “owns” an instance. To attach multiple components of the same type to the same bus, multiple templates must be defined.
Methods
The meta-config defines how to sample the config values for component instances. The entries must have one of the following forms: - Sampler for scalar constants and ranges with appropriate Sampler configuration - [ParamInitializer class, {"attr": Sampler}] for param initializers. Everything in the dict will be sampled and passed as **kwargs to the created ParamInitializer instance.
Attaches a fully configured node to the given parent entity.
Takes a system instance as argument and attaches components to all top-level nodes.
Generates a number of "households" (busses) and attaches sub-components based on the available meta configurations.
The meta-config defines how to sample the config values for all node instances. The entries must have one of the following forms: - Sampler for scalar constants and ranges with appropriate Sampler configuration - [ParamInitializer class, {"attr": Sampler}] for param initializers. Everything in the dict will be sampled and passed as **kwargs to the created ParamInitializer instance.
- _sample_config(meta_config: dict) dict[source]
This method samples a config from a given meta config
- Parameters:
meta_config (dict) – Meta config to use.
- Returns:
dict – Sampled config.
- add_component_template(component_type: Component, probability: float, multiple_allowed=False, meta_config: None | dict[str, Sampler | list[ParamInitializer, dict[str, Sampler | str]]] = None, data_providers: None | list[Sampler] = None) None[source]
The meta-config defines how to sample the config values for component instances. The entries must have one of the following forms: - Sampler for scalar constants and ranges with appropriate Sampler configuration - [ParamInitializer class, {“attr”: Sampler}] for param initializers.
Everything in the dict will be sampled and passed as **kwargs to the created ParamInitializer instance.
- Parameters:
component_type (Component) – Class of the component.
probability (float) – Probability that an instance of this component is attached to a household.
multiple_allowed (bool, optional) – If True, multiple components can be added to a node. This means we do the random sampling repeatedly based on the given probability threshold.
(Union[None (meta_config) – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the component. For examples, please refer to the Tutorials. Defaults to None.
dict[str – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the component. For examples, please refer to the Tutorials. Defaults to None.
Union[Sampler – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the component. For examples, please refer to the Tutorials. Defaults to None.
list[ParamInitializer – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the component. For examples, please refer to the Tutorials. Defaults to None.
- :paramdict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the component.
For examples, please refer to the Tutorials. Defaults to None.
- Parameters:
data_providers (Union[None, list[Sampler]], optional) – List of Samplers each sampling from a selection of data sources. The sampled data sources are attached to the component. Defaults to None.
- attach_node(parent: System | Bus, node_constructor_kwargs: dict, node_config: dict) None[source]
Attaches a fully configured node to the given parent entity.
- fill_topology(sys: System) None[source]
Takes a system instance as argument and attaches components to all top-level nodes.
- Parameters:
sys (System) – System instance.
- generate_households(parent: System | Bus, n_households: int)[source]
Generates a number of “households” (busses) and attaches sub-components based on the available meta configurations. At the moment all the generated nodes are directly connected to a given parent without power lines being generated.
- set_bus_template(bus_type: Bus, meta_config: None | dict[str, Sampler | list[ParamInitializer, dict[str, Sampler | str]]] = None, data_providers: None | list[Sampler] = None) None[source]
The meta-config defines how to sample the config values for all node instances. The entries must have one of the following forms: - Sampler for scalar constants and ranges with appropriate Sampler configuration - [ParamInitializer class, {“attr”: Sampler}] for param initializers.
Everything in the dict will be sampled and passed as **kwargs to the created ParamInitializer instance.
- Parameters:
bus_type (Bus) – Class of the bus.
(Union[None (meta_config) – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the node. For examples, please refer to the Tutorials. Defaults to None.
dict[str – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the node. For examples, please refer to the Tutorials. Defaults to None.
Union[Sampler – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the node. For examples, please refer to the Tutorials. Defaults to None.
list[ParamInitializer – dict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the node. For examples, please refer to the Tutorials. Defaults to None.
- :paramdict[str, Union[Sampler, str]]]]]], optional): Meta configuration for the node.
For examples, please refer to the Tutorials. Defaults to None.
- Parameters:
data_providers (Union[None, list[Sampler]], optional) – List of Samplers each sampling from a selection of data sources. The sampled data sources are attached to the node. Defaults to None.