openmdao/devtools/problem_viewer/problem_viewer.py
def _get_viewer_data(data_source):
    """
    Get the data needed by the N2 viewer as a dictionary.

    Parameters
    ----------
    data_source : <Problem> or <Group> or str
        A Problem or Group or case recorder file name containing the model or model data.

    Returns
    -------
    dict
        A dictionary containing information about the model for use by the viewer.
    """
    if isinstance(data_source, Problem):
        root_group = data_source.model
        if not isinstance(root_group, Group):
            simple_warning("The model is not a Group, viewer data is unavailable.")
            return {}

    elif isinstance(data_source, Group):
        if not data_source.pathname:  # root group
            root_group = data_source
        else:
            # this function only makes sense when it is at the root
            return {}

    elif isinstance(data_source, str):
        check_valid_sqlite3_db(data_source)
        import sqlite3
        con = sqlite3.connect(data_source, detect_types=sqlite3.PARSE_DECLTYPES)
        cur = con.cursor()
        cur.execute("SELECT format_version FROM metadata")
        row = cur.fetchone()
        format_version = row[0]

        cur.execute("SELECT model_viewer_data FROM driver_metadata;")
        model_text = cur.fetchone()

        from six import PY2, PY3
        if row is not None:
            if format_version >= 3:
                return json.loads(model_text[0])
            elif format_version in (1, 2):
                if PY2:
                    import cPickle
                    return cPickle.loads(str(model_text[0]))
                if PY3:
                    import pickle
                    return pickle.loads(model_text[0])

    else:
        raise TypeError('_get_viewer_data only accepts Problems, Groups or filenames')

    data_dict = {}
    comp_exec_idx = [0]  # list so pass by ref
    comp_exec_orders = {}
    data_dict['tree'] = _get_tree_dict(root_group, comp_exec_orders, comp_exec_idx)

    connections_list = []

    # sort to make deterministic for testing
    sorted_abs_input2src = OrderedDict(sorted(root_group._conn_global_abs_in2out.items()))
    root_group._conn_global_abs_in2out = sorted_abs_input2src
    G = root_group.compute_sys_graph(comps_only=True)
    scc = nx.strongly_connected_components(G)
    scc_list = [s for s in scc if len(s) > 1]
    for in_abs, out_abs in iteritems(sorted_abs_input2src):
        if out_abs is None:
            continue
        src_subsystem = out_abs.rsplit('.', 1)[0]
        tgt_subsystem = in_abs.rsplit('.', 1)[0]
        src_to_tgt_str = src_subsystem + ' ' + tgt_subsystem

        count = 0
        edges_list = []
        for li in scc_list:
            if src_subsystem in li and tgt_subsystem in li:
                count += 1
                if(count > 1):
                    raise ValueError('Count greater than 1')

                exe_tgt = comp_exec_orders[tgt_subsystem]
                exe_src = comp_exec_orders[src_subsystem]
                exe_low = min(exe_tgt, exe_src)
                exe_high = max(exe_tgt, exe_src)

                subg = G.subgraph(n for n in li if exe_low <= comp_exec_orders[n] <= exe_high)
                for edge in subg.edges():
                    edge_str = ' '.join(edge)
                    if edge_str != src_to_tgt_str:
                        edges_list.append(edge_str)

        if(edges_list):
            edges_list.sort()  # make deterministic so same .html file will be produced each run
            connections_list.append(OrderedDict([('src', out_abs), ('tgt', in_abs),
                                                 ('cycle_arrows', edges_list)]))
        else:
            connections_list.append(OrderedDict([('src', out_abs), ('tgt', in_abs)]))

    data_dict['connections_list'] = connections_list

    data_dict['abs2prom'] = root_group._var_abs2prom

    return data_dict

    Get the data needed by the N2 viewer as a dictionary.

    Parameters
    ----------
    data_source : <Problem> or <Group> or str
        A Problem or Group or case recorder file name containing the model or model data.

    Returns
    -------
    dict
        A dictionary containing information about the model for use by the viewer.
    
Get the data needed by the N2 viewer as a dictionary.
Parameters

data_source :  or  or str
A Problem or Group or case recorder file name containing the model or model data.

Returns

dict
A dictionary containing information about the model for use by the viewer.
Get the data needed by the N2 viewer as a dictionary . Parameters data_source : or or str A Problem or Group or case recorder file name containing the model or model data . Returns dict A dictionary containing information about the model for use by the viewer .
def _get_viewer_data(data_source):
    if isinstance(data_source, Problem):
        root_group = data_source.model
        if not isinstance(root_group, Group):
            simple_warning("The model is not a Group, viewer data is unavailable.")
            return {}
    elif isinstance(data_source, Group):
        if not data_source.pathname:  
            root_group = data_source
        else:
            return {}
    elif isinstance(data_source, str):
        check_valid_sqlite3_db(data_source)
        import sqlite3
        con = sqlite3.connect(data_source, detect_types=sqlite3.PARSE_DECLTYPES)
        cur = con.cursor()
        cur.execute("SELECT format_version FROM metadata")
        row = cur.fetchone()
        format_version = row[0]
        cur.execute("SELECT model_viewer_data FROM driver_metadata;")
        model_text = cur.fetchone()
        from six import PY2, PY3
        if row is not None:
            if format_version >= 3:
                return json.loads(model_text[0])
            elif format_version in (1, 2):
                if PY2:
                    import cPickle
                    return cPickle.loads(str(model_text[0]))
                if PY3:
                    import pickle
                    return pickle.loads(model_text[0])
    else:
        raise TypeError('_get_viewer_data only accepts Problems, Groups or filenames')
    data_dict = {}
    comp_exec_idx = [0]  
    comp_exec_orders = {}
    data_dict['tree'] = _get_tree_dict(root_group, comp_exec_orders, comp_exec_idx)
    connections_list = []
    sorted_abs_input2src = OrderedDict(sorted(root_group._conn_global_abs_in2out.items()))
    root_group._conn_global_abs_in2out = sorted_abs_input2src
    G = root_group.compute_sys_graph(comps_only=True)
    scc = nx.strongly_connected_components(G)
    scc_list = [s for s in scc if len(s) > 1]
    for in_abs, out_abs in iteritems(sorted_abs_input2src):
        if out_abs is None:
            continue
        src_subsystem = out_abs.rsplit('.', 1)[0]
        tgt_subsystem = in_abs.rsplit('.', 1)[0]
        src_to_tgt_str = src_subsystem + ' ' + tgt_subsystem
        count = 0
        edges_list = []
        for li in scc_list:
            if src_subsystem in li and tgt_subsystem in li:
                count += 1
                if(count > 1):
                    raise ValueError('Count greater than 1')
                exe_tgt = comp_exec_orders[tgt_subsystem]
                exe_src = comp_exec_orders[src_subsystem]
                exe_low = min(exe_tgt, exe_src)
                exe_high = max(exe_tgt, exe_src)
                subg = G.subgraph(n for n in li if exe_low <= comp_exec_orders[n] <= exe_high)
                for edge in subg.edges():
                    edge_str = ' '.join(edge)
                    if edge_str != src_to_tgt_str:
                        edges_list.append(edge_str)
        if(edges_list):
            edges_list.sort()  
            connections_list.append(OrderedDict([('src', out_abs), ('tgt', in_abs),
                                                 ('cycle_arrows', edges_list)]))
        else:
            connections_list.append(OrderedDict([('src', out_abs), ('tgt', in_abs)]))
    data_dict['connections_list'] = connections_list
    data_dict['abs2prom'] = root_group._var_abs2prom
    return data_dict
def _get_viewer_data ( data_source ) : if isinstance ( data_source , Problem ) : root_group = data_source . model if not isinstance ( root_group , Group ) : simple_warning ( "The model is not a Group, viewer data is unavailable." ) return { } elif isinstance ( data_source , Group ) : if not data_source . pathname : root_group = data_source else : return { } elif isinstance ( data_source , str ) : check_valid_sqlite3_db ( data_source ) import sqlite3 con = sqlite3 . connect ( data_source , detect_types = sqlite3 . PARSE_DECLTYPES ) cur = con . cursor ( ) cur . execute ( "SELECT format_version FROM metadata" ) row = cur . fetchone ( ) format_version = row [ 0 ] cur . execute ( "SELECT model_viewer_data FROM driver_metadata;" ) model_text = cur . fetchone ( ) from six import PY2 , PY3 if row is not None : if format_version >= 3 : return json . loads ( model_text [ 0 ] ) elif format_version in ( 1 , 2 ) : if PY2 : import cPickle return cPickle . loads ( str ( model_text [ 0 ] ) ) if PY3 : import pickle return pickle . loads ( model_text [ 0 ] ) else : raise TypeError ( '_get_viewer_data only accepts Problems, Groups or filenames' ) data_dict = { } comp_exec_idx = [ 0 ] comp_exec_orders = { } data_dict [ 'tree' ] = _get_tree_dict ( root_group , comp_exec_orders , comp_exec_idx ) connections_list = [ ] sorted_abs_input2src = OrderedDict ( sorted ( root_group . _conn_global_abs_in2out . items ( ) ) ) root_group . _conn_global_abs_in2out = sorted_abs_input2src G = root_group . compute_sys_graph ( comps_only = True ) scc = nx . strongly_connected_components ( G ) scc_list = [ s for s in scc if len ( s ) > 1 ] for in_abs , out_abs in iteritems ( sorted_abs_input2src ) : if out_abs is None : continue src_subsystem = out_abs . rsplit ( '.' , 1 ) [ 0 ] tgt_subsystem = in_abs . rsplit ( '.' , 1 ) [ 0 ] src_to_tgt_str = src_subsystem + ' ' + tgt_subsystem count = 0 edges_list = [ ] for li in scc_list : if src_subsystem in li and tgt_subsystem in li : count += 1 if ( count > 1 ) : raise ValueError ( 'Count greater than 1' ) exe_tgt = comp_exec_orders [ tgt_subsystem ] exe_src = comp_exec_orders [ src_subsystem ] exe_low = min ( exe_tgt , exe_src ) exe_high = max ( exe_tgt , exe_src ) subg = G . subgraph ( n for n in li if exe_low <= comp_exec_orders [ n ] <= exe_high ) for edge in subg . edges ( ) : edge_str = ' ' . join ( edge ) if edge_str != src_to_tgt_str : edges_list . append ( edge_str ) if ( edges_list ) : edges_list . sort ( ) connections_list . append ( OrderedDict ( [ ( 'src' , out_abs ) , ( 'tgt' , in_abs ) , ( 'cycle_arrows' , edges_list ) ] ) ) else : connections_list . append ( OrderedDict ( [ ( 'src' , out_abs ) , ( 'tgt' , in_abs ) ] ) ) data_dict [ 'connections_list' ] = connections_list data_dict [ 'abs2prom' ] = root_group . _var_abs2prom return data_dict
Get the data needed by the N2 viewer as a dictionary.
Get the data needed by the N2 viewer as a dictionary .
"""
    Get the data needed by the N2 viewer as a dictionary.

    Parameters
    ----------
    data_source : <Problem> or <Group> or str
        A Problem or Group or case recorder file name containing the model or model data.

    Returns
    -------
    dict
        A dictionary containing information about the model for use by the viewer.
    """ # root group # this function only makes sense when it is at the root # list so pass by ref # sort to make deterministic for testing # make deterministic so same .html file will be produced each run
data_source