Skip to content

The Cosimulation Graph Engine

GraphEngine is a class that represents a graph structure based on * FMUs and/or symbolic nodes * connections (namely edges) It uses networkx library to build and manipulate the graph.

Custom dependencies: the method plot_graph uses GraphPlotter

Initialize the GraphEngine instance, set up the FMU and connection lists, and construct the graph.

PARAMETER DESCRIPTION
fmu_list

List of FMU data (each FMU represented as a dictionary).

TYPE: List[Dict]

symbolic_nodes

List of symbolic nodes (each node represented as a dictionary).

TYPE: List[Dict]

conn_list

List of connections (each connection represented as a dictionary).

TYPE: List[Dict]

edge_sep

Separator used for edge labels. Default is " -> ".

TYPE: str DEFAULT: ' -> '

Source code in cofmpy/graph_engine.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def __init__(
    self,
    fmu_list: List[Dict],
    symbolic_nodes: List[Dict],
    conn_list: List[Dict],
    edge_sep: str = " -> ",
) -> None:
    """
    Initialize the GraphEngine instance, set up the FMU and connection lists,
    and construct the graph.

    Args:
        fmu_list (List[Dict]): List of FMU data (each FMU represented as a
            dictionary).
        symbolic_nodes (List[Dict]): List of symbolic nodes (each node represented
            as a dictionary).
        conn_list (List[Dict]): List of connections (each connection represented as
            a dictionary).
        edge_sep (str, optional): Separator used for edge labels.
            Default is " -> ".
    """

    self.fmu_list = fmu_list
    self.symbolic_nodes = symbolic_nodes
    self.conn_list = conn_list
    self.edge_sep = edge_sep
    self.keys = Keys()
    self.color_map = {}

    # Build Graph
    self.graph, self.fmu_types = self._create_graph()

    # Create connections and get order
    self.connections = self._name_connections()
    self.sequence_order = self._get_order()

plot_graph

plot_graph(savefig=False)

Plot a graph representation of the co-simulation diagram.

This method generates a Plotly figure showing nodes and their connections. It uses NetworkX for node positioning and Plotly for rendering the graph.

PARAMETER DESCRIPTION
savefig

Whether to save the figure as an HTML file. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Figure

go.Figure: The Plotly figure object representing the co-simulation diagram.

Source code in cofmpy/graph_engine.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def plot_graph(self, savefig: bool = False) -> go.Figure:
    """
    Plot a graph representation of the co-simulation diagram.

    This method generates a Plotly figure showing nodes and their connections.
    It uses NetworkX for node positioning and Plotly for rendering the graph.

    Args:
        savefig (bool, optional): Whether to save the figure as an HTML file. Defaults to False.

    Returns:
        go.Figure: The Plotly figure object representing the co-simulation diagram.
    """

    plotter = GraphPlotter()

    size_map = {k: 1 if v == "fmu" else 0.2 for k, v in self.fmu_types.items()}

    fig = plotter.generate_figure(
        self.graph, self.fmu_list + self.symbolic_nodes, size_map
    )

    self.color_map = plotter.color_map

    if savefig:
        plotter.save_plotly_figure(fig, "cosim_diagram")

    return fig