paroto.viz#
Visualization module for Paroto.
This module provides tools for visualizing optimization problems, parameter hierarchies, and model connectivity in multiple formats.
Main Functions#
extract_hierarchy : Extract parameter hierarchy from OpenMDAO Problem generate_hierarchical_graph : Generate hierarchical Mermaid diagram generate_simple_graph : Generate simple all-to-all Mermaid diagram to_networkx : Convert hierarchy to NetworkX DiGraph model_graph_to_cytoscape : Convert graph to Cytoscape format for Dash
Submodules#
Classes#
Unified graph abstraction for OpenMDAO Problem visualization. |
Functions#
Get default Cytoscape layout configuration. |
|
Get default Cytoscape stylesheet for model graphs. |
|
|
Convert model graph to Cytoscape elements format. |
|
Extract parameter hierarchy from an OpenMDAO Problem. |
|
Generate hierarchical Mermaid diagram showing parameter dependencies. |
|
Generate a simple Mermaid flowchart showing system connectivity. |
|
Analyze hierarchy structure and return statistics. |
|
Export NetworkX graph to GraphML format. |
|
Export NetworkX graph to JSON format. |
|
Generate static image of hierarchy using matplotlib. |
|
Convert ProblemGraph to NetworkX DiGraph. |
Package Contents#
- paroto.viz.get_cytoscape_layout()#
Get default Cytoscape layout configuration.
- Returns:
Cytoscape layout configuration
- Return type:
- paroto.viz.get_cytoscape_stylesheet()#
Get default Cytoscape stylesheet for model graphs.
- Returns:
Cytoscape stylesheet
- Return type:
- paroto.viz.model_graph_to_cytoscape(parameters, models, constraints, connections=None)#
Convert model graph to Cytoscape elements format.
- Parameters:
- Returns:
Cytoscape elements list with nodes and edges
- Return type:
- paroto.viz.extract_hierarchy(prob, primary_params, constraint_names=None)#
Extract parameter hierarchy from an OpenMDAO Problem.
Analyzes the connection structure of an OpenMDAO problem to determine which parameters are primary (design variables), secondary (outputs of models consuming primary parameters), and so on.
- Parameters:
prob (
openmdao.api.Problem) – Configured OpenMDAO problem (should call setup() called)primary_params (
listofstr) – List of primary parameter names (design variables) These can be partial names that will be matchedconstraint_names (
listofstr, optional) – List of constraint output names. If None, attempts to detect constraints
- Returns:
Graph abstraction with nodes, edges, and hierarchy levels
- Return type:
Notes
Hierarchy levels: - Level 0: Primary parameters (user-specified design variables) - Level N: Parameters/outputs that depend only on levels 0 through N-1 - Constraints are assigned their own level based on dependencies
- paroto.viz.generate_hierarchical_graph(graph, output_path, max_level=None, orientation='LR')#
Generate hierarchical Mermaid diagram showing parameter dependencies.
Creates a layered graph where nodes are organized by hierarchy level, showing actual connections between parameters, models, and constraints.
- Parameters:
graph (
ProblemGraph) – Problem graph from extract_hierarchy()output_path (
str) – File path where the Mermaid diagram will be savedmax_level (
int, optional) – Maximum hierarchy level to display. If None, shows all levelsorientation (
str, optional) – Graph orientation: “LR” (left-right) or “TD” (top-down). Default: “LR”
- Returns:
The output file path where the diagram was saved
- Return type:
- paroto.viz.generate_simple_graph(graph, output_path)#
Generate a simple Mermaid flowchart showing system connectivity.
Creates a graph with three layers: parameters (inputs), models (processing), and constraints (outputs/checks). Automatically extracts nodes from the ProblemGraph.
- Parameters:
graph (
ProblemGraph) – Problem graph from extract_hierarchy()output_path (
str) – File path where the Mermaid diagram will be saved
- Returns:
The output file path where the diagram was saved
- Return type:
- paroto.viz.analyze_hierarchy(graph)#
Analyze hierarchy structure and return statistics.
- Parameters:
graph (
networkx.DiGraph) – Graph to analyze- Returns:
Statistics including: - ‘num_nodes’: total number of nodes - ‘num_edges’: total number of edges - ‘num_levels’: number of hierarchy levels - ‘nodes_by_level’: dict mapping level -> count - ‘nodes_by_type’: dict mapping type -> count - ‘max_in_degree’: maximum number of inputs to a node - ‘max_out_degree’: maximum number of outputs from a node
- Return type:
- paroto.viz.export_graphml(graph, output_path)#
Export NetworkX graph to GraphML format.
GraphML is supported by tools like yEd, Gephi, and Cytoscape.
- paroto.viz.export_json(graph, output_path)#
Export NetworkX graph to JSON format.
Exports in node-link format compatible with D3.js and other JavaScript libraries.
- paroto.viz.plot_hierarchy(graph, output_path, figsize=(12, 8), dpi=150)#
Generate static image of hierarchy using matplotlib.
- Parameters:
- Returns:
The output file path
- Return type:
- paroto.viz.to_networkx(graph)#
Convert ProblemGraph to NetworkX DiGraph.
- Parameters:
graph (
ProblemGraph) – Problem graph from extract_hierarchy()- Returns:
Directed graph with node attributes: - ‘level’: hierarchy level (int) - ‘type’: node type (str) - ‘units’: variable units (str) - ‘value’: variable value - ‘label’: simplified display name
- Return type:
networkx.DiGraph
- class paroto.viz.ProblemGraph(prob, primary_params=None, constraint_markers=None)#
Unified graph abstraction for OpenMDAO Problem visualization.
This class wraps an OpenMDAO Problem and provides a clean, unified interface for extracting graph structure that can be consumed by any visualization backend.
- Parameters:
prob (
openmdao.api.Problem) – OpenMDAO problem (must have setup() called)primary_params (
listofstr, optional) – List of primary parameter names (design variables). Can be partial names that will be matchedconstraint_markers (
listofstr, optional) – Keywords to identify constraint variables (e.g., [‘margin’, ‘constraint’])
- nodes#
Mapping of node_id -> node attributes (type, level, units, value, label, subsystem)
- Type:
- prob#
- model#
- get_nodes_by_level(max_level=None)#
Get nodes organized by hierarchy level.
- get_nodes_by_subsystem()#
Get nodes organized by subsystem.
- Returns:
Mapping of subsystem_name -> list of node_ids
- Return type:
- get_nodes_by_type()#
Get nodes organized by type.
- Returns:
Mapping of node_type -> list of node_ids
- Return type:
- filter_by_level(max_level)#
Get filtered view with nodes up to max_level.