Converter¶
Converters turn domain-specific objects (e.g. a pypowsybl.network.Network) into
Graph instances.
A Converter is composed of one
ElementsConverter per hyper-edge class (e.g. "bus", "line"),
each in charge of extracting a table of addresses and features from the input object.
The converter then maps string addresses to consecutive integers, casts features to bounded
floats, and assembles the tables into a graph.
Converter¶
- class Converter[source]¶
Bases:
objectAbstract base class for all converters.
A converter turns a domain-specific object (e.g. a
pypowsybl.network.Network) into anenergnn.graph.Graph. Subclasses only need to provideelements_converter_dict, which maps each hyper-edge class name (e.g."bus","line") to theElementsConverterin charge of extracting its table of addresses and features.Calling the converter runs the following pipeline:
each
ElementsConverterextracts an(address table, feature table)pair from the input object;string addresses are mapped to consecutive integers
0..n-1, in sorted order so that the mapping is reproducible across runs;features are cast to floats: categorical values are hashed to a deterministic float in
[0, 1), NaNs are replaced by 0, and values are clipped to[-1e6, 1e6];the tables are assembled into a
energnn.graph.GraphthroughHyperEdgeSet.from_dict()andGraph.from_dict().
The graph is always built on a numpy backend, because graph shapes vary from one input to the next and building directly in jax would trigger one XLA compilation per new shape. If
backendis set, the finished graph is converted to it withGraph.to_backend().- Variables:
elements_converter_dict – Mapping from hyper-edge class name to its
ElementsConverter. Must be defined by subclasses.backend – Optional target backend for the returned graph. If
None, the graph is returned on aNumpyBackend.
Convert an input object into a |
|
Return the |
ElementsConverter¶
- class ElementsConverter(port_list, feature_list)[source]¶
Bases:
ABCAbstract base class for elements converters.
An elements converter extracts, for one class of hyper-edges (e.g.
"bus","line"), a table of addresses and a table of features from a domain-specific object. Subclasses must implement_get_table(), which returns a singlepandas.DataFramecontaining at least the columns listed inport_listandfeature_list;__call__()then splits it into the(address table, feature table)pair consumed byConverter.At least one of
port_listandfeature_listmust be provided: a hyper-edge set with neither ports nor features would be empty.- Parameters:
port_list (list[str] | None) – Names of the columns of the table returned by
_get_table()that contain addresses (e.g.["from", "to"]for a line).Noneif the hyper-edges have no ports (e.g. global quantities).feature_list (list[str] | None) – Names of the columns that contain features.
Noneif the hyper-edges carry no feature (e.g. purely structural elements).
- Variables:
attributes – All columns that must be fetched from the underlying data source, i.e. the concatenation of
port_listandfeature_list.
Extract the |
|
Get the edge structure of the element, useful for building an EnerGNN model. |