Interfaces#
Abstract base classes and data structures that define the NPAP strategy pattern.
Data Classes#
- class npap.interfaces.AggregationProfile[source]
Bases:
objectConfigure aggregation separating physical from statistical operations.
This profile distinguishes between:
Topology: How the graph structure is reduced
Physical: Electrical laws that must be preserved (coupled properties)
Statistical: Simple operations on independent properties
- topology_strategy
Strategy for graph structure reduction (“simple”, “electrical”).
- Type:
- physical_strategy
Physical aggregation strategy (“kron_reduction”, “equivalent_impedance”).
- physical_properties
Properties handled by physical strategy (e.g., [“reactance”, “resistance”]).
- Type:
list[str]
- physical_parameters
Additional parameters for physical strategies.
- Type:
dict[str,Any]
- node_properties
Mapping of node property names to aggregation strategies.
- Type:
dict[str,str]
- edge_properties
Mapping of edge property names to aggregation strategies.
- Type:
dict[str,str]
- edge_type_properties
Per-edge-type strategy overrides. Maps edge type values (from the
edge_type_attributeattribute on edges) to per-type property strategy dicts. When populated, edges are aggregated separately per type and the result graph is a MultiDiGraph with one edge per type per cluster pair. Falls back toedge_propertiesfor edges whose type is not listed here.- Type:
dict[str,dict[str,str]]
- edge_type_attribute
Name of the edge attribute that stores the type label. Only used when
edge_type_propertiesis populated. Defaults to"type".- Type:
- default_node_strategy
Default strategy for unspecified node properties.
- Type:
- default_edge_strategy
Default strategy for unspecified edge properties.
- Type:
- warn_on_defaults
Whether to warn when using default strategies.
- Type:
- mode
Indicator of which pre-defined mode is being used.
- Type:
- Attributes:
- physical_strategy
See
npap.AggregationProfilefor full member documentation.-
topology_strategy:
str= 'simple'
-
edge_type_attribute:
str= 'type'
-
default_node_strategy:
str= 'average'
-
default_edge_strategy:
str= 'sum'
-
warn_on_defaults:
bool= True
-
mode:
AggregationMode= 'custom'
- __init__(topology_strategy='simple', physical_strategy=None, physical_properties=<factory>, physical_parameters=<factory>, node_properties=<factory>, edge_properties=<factory>, edge_type_properties=<factory>, edge_type_attribute='type', default_node_strategy='average', default_edge_strategy='sum', warn_on_defaults=True, mode=AggregationMode.CUSTOM)
- class npap.interfaces.AggregationMode[source]
Bases:
EnumDefine pre-defined aggregation modes for common use cases.
- SIMPLE
Sum/average everything with simple topology.
- Type:
- GEOGRAPHICAL
Average coordinates, sum other properties.
- Type:
- DC_KRON
Kron reduction for DC networks.
- Type:
- CUSTOM
User-defined aggregation profile.
- Type:
See
npap.AggregationModefor full member documentation.- SIMPLE = 'simple'
- GEOGRAPHICAL = 'geographical'
- DC_KRON = 'dc_kron'
- CUSTOM = 'custom'
- class npap.interfaces.PartitionResult[source]
Bases:
objectStore partition result with metadata for validation and tracking.
- mapping
Dictionary mapping cluster_id to list of node_ids.
- Type:
dict[int,list[Any]]
- original_graph_hash
Hash of the original graph for compatibility validation.
- Type:
- strategy_name
Name of the partitioning strategy used.
- Type:
- strategy_metadata
Strategy-specific metadata and parameters.
- Type:
dict[str,Any]
- n_clusters
Number of clusters created.
- Type:
See
npap.PartitionResultfor full member documentation.-
original_graph_hash:
str
-
strategy_name:
str
-
n_clusters:
int
Strategy Interfaces#
- class npap.interfaces.DataLoadingStrategy[source]#
Bases:
ABCDefine interface for data loading strategies.
Methods
load(**kwargs)Load data and return a NetworkX directed graph.
validate_inputs(**kwargs)Validate input parameters before loading.
- abstractmethod load(**kwargs)[source]#
Load data and return a NetworkX directed graph.
- Returns:
Loaded network graph.
- Return type:
nx.DiGraphornx.MultiDiGraph
- abstractmethod validate_inputs(**kwargs)[source]#
Validate input parameters before loading.
- Returns:
True if validation passes.
- Return type:
- Raises:
DataLoadingError – If validation fails.
- class npap.interfaces.PartitioningStrategy[source]#
Bases:
ABCDefine interface for all partitioning algorithms.
- Attributes:
required_attributesReturn required node/edge attributes.
Methods
partition(graph, **kwargs)Partition nodes into clusters.
- class npap.interfaces.TopologyStrategy[source]#
Bases:
ABCDefine interface for topology strategies.
Topology strategies create the skeleton of the aggregated graph:
Which nodes exist in the aggregated graph
Which edges connect them
NO property aggregation at this stage
- Attributes:
can_create_new_edgesCheck whether this strategy can create edges not in original graph.
Methods
create_topology(graph, partition_map)Create aggregated graph structure without properties.
- abstractmethod create_topology(graph, partition_map)[source]#
Create aggregated graph structure without properties.
- Parameters:
graph (
nx.DiGraph) – Original directed graph.partition_map (
dict[int,list[Any]]) – Mapping of cluster_id to list of original node ids.
- Returns:
DiGraph with aggregated topology (nodes and edges, no attributes).
- Return type:
nx.DiGraph
- class npap.interfaces.NodePropertyStrategy[source]#
Bases:
ABCDefine interface for node property aggregation strategies.
Methods
aggregate_property(graph, nodes, property_name)Aggregate a specific property across nodes.
- abstractmethod aggregate_property(graph, nodes, property_name)[source]#
Aggregate a specific property across nodes.
- Parameters:
graph (
nx.DiGraph) – The graph containing node properties.nodes (
list[Any]) – List of node identifiers to aggregate.property_name (
str) – Name of the property to aggregate.
- Returns:
Aggregated property value.
- Return type:
Any
- class npap.interfaces.EdgePropertyStrategy[source]#
Bases:
ABCDefine interface for edge property aggregation strategies.
- Attributes:
required_attributesReturn required attributes for this property strategy.
Methods
aggregate_property(original_edges, property_name)Aggregate a specific property across edges.
- abstractmethod aggregate_property(original_edges, property_name)[source]#
Aggregate a specific property across edges.
- Parameters:
original_edges (
list[dict[str,Any]]) – List of edge attribute dictionaries.property_name (
str) – Name of the property to aggregate.
- Returns:
Aggregated property value.
- Return type:
Any
- class npap.interfaces.PhysicalAggregationStrategy[source]#
Bases:
ABCDefine interface for physics-aware aggregation strategies.
These strategies operate on the entire graph and respect physical laws. They work on coupled properties (e.g., reactance and resistance together). They may create new edges based on electrical coupling.
- Attributes:
can_create_edgesCheck whether this strategy can create new edges.
modifies_propertiesReturn properties modified by this physical strategy.
required_propertiesReturn properties this strategy requires.
required_topologyReturn required topology strategy for this physical aggregation.
Methods
aggregate(original_graph, partition_map, ...)Apply physical aggregation to the topology graph.
- abstractmethod aggregate(original_graph, partition_map, topology_graph, properties, parameters=None)[source]#
Apply physical aggregation to the topology graph.
- Parameters:
original_graph (
nx.DiGraph) – Full resolution directed graph with all properties.partition_map (
dict[int,list[Any]]) – Mapping of cluster_id to list of node_ids.topology_graph (
nx.DiGraph) – DiGraph with aggregated structure but no properties yet.properties (
list[str]) – Physical properties to aggregate (coupled).parameters (
dict[str,Any], optional) – Additional parameters for the strategy.
- Returns:
DiGraph with physical properties correctly aggregated.
- Return type:
nx.DiGraph
- abstract property required_properties: list[str]#
Return properties this strategy requires.
- Returns:
List of required property names (e.g., [‘reactance’, ‘resistance’]).
- Return type:
list[str]
- abstract property modifies_properties: list[str]#
Return properties modified by this physical strategy.
These properties should NOT be aggregated statistically afterward, as they are already handled by the physical strategy.
- Returns:
List of property names modified by this strategy.
- Return type:
list[str]