def check_connections(gd):
    """
    Given a graph, checks that all
     - inputs/outputs are symmetric
     - control_inputs/control_outputs are symmetric
     - The graph does not reference vertices outside of the graph

    Takes a graph in "dict{str, ParsedNode}" form. Does not return,
    asserts false on failure.
    """
    # check that inputs and outputs line up
    for k, v in gd.items():
        for i in v.inputs:
            if isinstance(i, str):
                assert k in gd[i].outputs
            else:
                assert k in gd[i.name].outputs
        for i in v.outputs:
            inputs = [
                inp if isinstance(inp, str) else inp.name
                for inp in gd[i].inputs
            ]
            assert k in inputs
        for i in v.control_inputs:
            if isinstance(i, str):
                assert k in gd[i].control_outputs
            else:
                assert k in gd[i.name].control_outputs
        for i in v.control_outputs:
            control_inputs = [
                inp if isinstance(inp, str) else inp.name
                for inp in gd[i].control_inputs
            ]
            assert k in control_inputs

    Given a graph, checks that all
     - inputs/outputs are symmetric
     - control_inputs/control_outputs are symmetric
     - The graph does not reference vertices outside of the graph

    Takes a graph in "dict{str, ParsedNode}" form. Does not return,
    asserts false on failure.
    
coremltools/converters/mil/frontend/tensorflow/basic_graph_ops.py