desmod.dot

Generate graphical representation of component hierarchy.

Component hierarchy, connections, and processes can be represented graphically using the Graphviz DOT language.

The component_to_dot() function produces a DOT language string that can be rendered into a variety of formats using Graphviz tools. Because the component hierarchy, connections, and processes are determined dynamically, component_to_dot() must be called with an instantiated component. A good way to integrate this capabililty into a model is to call component_to_dot() from a component’s desmod.component.Component.elab_hook() method.

The dot program from Graphviz may be used to render the generated DOT language description of the component hierarchy:

dot -Tpng -o foo.png foo.dot

For large component hierarchies, the osage program (also part of Graphviz) can produce a more compact layout:

osage -Tpng -o foo.png foo.dot
desmod.dot.component_to_dot(top: desmod.component.Component, show_hierarchy: bool = True, show_connections: bool = True, show_processes: bool = True, colorscheme: str = '') → str[source]

Produce a dot stream from a component hierarchy.

The DOT language representation of the component instance hierarchy can show the component hierarchy, the inter-component connections, components’ processes, or any combination thereof.

Note

The top component hierarchy must be initialized and all connections must be made in order for component_to_dot() to inspect these graphs. The desmod.component.Component.elab_hook() method is a good place to call component_to_dot() since the model is fully elaborated at that point and simulation has not yet started.

Parameters:
  • top (Component) – Top-level component (instance).
  • show_hierarchy (bool) – Should the component hierarchy be shown in the graph.
  • show_connections (bool) – Should the inter-component connections be shown in the graph.
  • show_processes (bool) – Should each component’s processes be shown in the graph.
  • colorscheme (str) – One of the Brewer color schemes supported by graphviz, e.g. “blues8” or “set27”. Each level of the component hierarchy will use a different color from the color scheme. N.B. Brewer color schemes have between 3 and 12 colors; one should be chosen that has at least as many colors as the depth of the component hierarchy.
Returns str:

DOT language representation of the component/connection graph(s).