human
Solve the following python programming problem given the following code:
@not_implemented_for('directed', 'multigraph')
def generate_graph6(G, nodes=None, header=True):
assistant
#Here is the Python program you requested.

    """Generate graph6 format string from a simple undirected graph.
    Parameters
    G : Graph (undirected)
    nodes: list or iterable
    Nodes are labeled 0...n-1 in the order provided.  If None the ordering
    given by G.nodes() is used.
    header: bool
    If True add \>>graph6<<\ string to head of data
    Returns
    s : string
    String in graph6 format
    Raises
    NetworkXError
    If the graph is directed or has parallel edges
    Examples
    >>> G = nx.Graph([(0, 1)])
    >>> nx.generate_graph6(G)
    \>>graph6<<A_\
    See Also
    read_graph6, parse_graph6, write_graph6
    Notes
    The format does not support edge or node labels, parallel edges or
    self loops.  If self loops are present they are silently ignored.
    References
    .. [1] Graph6 specification
    <http://users.cecs.anu.edu.au/~bdm/data/formats.html>
    """
    if (nodes is not None):
        G = G.subgraph(nodes)
    H = nx.convert_node_labels_to_integers(G)
    ns = sorted(H.nodes())
    def bits():
        for (i, j) in [(i, j) for j in range(1, n) for i in range(j)]:
            (yield G.has_edge(ns[i], ns[j]))
    n = G.order()
    data = n_to_data(n)
    d = 0
    flush = False
    for (i, b) in zip(range((n * n)), bits()):
        d |= (b << (5 - (i % 6)))
        flush = True
        if ((i % 6) == 5):
            data.append(d)
            d = 0
            flush = False
    if flush:
        data.append(d)
    string_data = data_to_graph6(data)
    if header:
        string_data = ('>>graph6<<' + string_data)
    return string_data