flixopt.topology_accessor ¶
Topology accessor for FlowSystem.
This module provides the TopologyAccessor class that enables the flow_system.topology pattern for network structure inspection and visualization.
Attributes¶
Classes¶
TopologyAccessor ¶
Accessor for network topology inspection and visualization on FlowSystem.
This class provides the topology API for FlowSystem, accessible via flow_system.topology. It offers methods to inspect the network structure and visualize it.
Examples:
Visualize the network:
Interactive visualization:
>>> flow_system.topology.start_app()
>>> # ... interact with the visualization ...
>>> flow_system.topology.stop_app()
Get network structure info:
Initialize the accessor with a reference to the FlowSystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_system | FlowSystem | The FlowSystem to inspect. | required |
Attributes¶
carrier_colors property ¶
component_colors property ¶
bus_colors property ¶
carrier_units property ¶
effect_units property ¶
Functions¶
infos ¶
Get network topology information as dictionaries.
Returns node and edge information suitable for visualization or analysis.
Returns:
| Type | Description |
|---|---|
tuple[dict[str, dict[str, str]], dict[str, dict[str, str]]] | Tuple of (nodes_dict, edges_dict) where: - nodes_dict maps node labels to their properties (label, class, infos) - edges_dict maps edge labels to their properties (label, start, end, infos) |
Examples:
plot ¶
Visualize the network structure as a Sankey diagram using Plotly.
Creates a Sankey diagram showing the topology of the flow system, with buses and components as nodes, and flows as links between them. All links have equal width since no solution data is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors | ColorType | None | Color specification for nodes (buses). - | None |
show | bool | None | Whether to display the figure in the browser. - | None |
**plotly_kwargs | Any | Additional arguments passed to Plotly layout. | {} |
Returns:
| Type | Description |
|---|---|
PlotResult | PlotResult containing the Sankey diagram figure and topology data |
PlotResult | (source, target, value for each link). |
Examples:
>>> flow_system.topology.plot()
>>> flow_system.topology.plot(show=True)
>>> flow_system.topology.plot(colors='Viridis')
>>> flow_system.topology.plot(colors={'ElectricityBus': 'gold', 'HeatBus': 'red'})
Notes
This visualization shows the network structure without optimization results. For visualizations that include flow values, use flow_system.statistics.plot.sankey.flows() after running an optimization.
Hover over nodes and links to see detailed element information.
See Also
plot_legacy(): Previous PyVis-based network visualization.statistics.plot.sankey.flows(): Sankey with actual flow values from optimization.
plot_legacy ¶
plot_legacy(path: bool | str | Path = 'flow_system.html', controls: bool | list[Literal['nodes', 'edges', 'layout', 'interaction', 'manipulation', 'physics', 'selection', 'renderer']] = True, show: bool | None = None) -> pyvis.network.Network | None
Visualize the network structure using PyVis, saving it as an interactive HTML file.
.. deprecated:: Use plot() instead for the new Plotly-based Sankey visualization. This method is kept for backwards compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | bool | str | Path | Path to save the HTML visualization. - | 'flow_system.html' |
controls | bool | list[Literal['nodes', 'edges', 'layout', 'interaction', 'manipulation', 'physics', 'selection', 'renderer']] | UI controls to add to the visualization. - | True |
show | bool | None | Whether to open the visualization in the web browser. | None |
Returns:
| Type | Description |
|---|---|
Network | None | The |
Network | None | or |
Examples:
>>> flow_system.topology.plot_legacy()
>>> flow_system.topology.plot_legacy(show=False)
>>> flow_system.topology.plot_legacy(path='output/network.html', controls=['nodes', 'layout'])
Notes
This function requires pyvis. If not installed, the function prints a warning and returns None. Nodes are styled based on type (circles for buses, boxes for components) and annotated with node information.
start_app ¶
Start an interactive network visualization using Dash and Cytoscape.
Launches a web-based interactive visualization server that allows exploring the network structure dynamically.
Raises:
| Type | Description |
|---|---|
ImportError | If required dependencies are not installed. |
Examples:
>>> flow_system.topology.start_app()
>>> # ... interact with the visualization in browser ...
>>> flow_system.topology.stop_app()
Notes
Requires optional dependencies: dash, dash-cytoscape, dash-daq, networkx, flask, werkzeug. Install with: pip install flixopt[network_viz] or pip install flixopt[full]