code: def _to_undirected_graph(
      G,
      edge_attr: AttrKey | None = None,
      edge_default: EdgeValue | None = 1,
      edge_dtype: Dtype | None = None,
  ) -> nxcg.Graph:
      """Ensure that input type is a nx_cugraph Graph, and convert if necessary.
  
      Only undirected graphs are allowed. Directed graphs will raise ValueError.
      This is an internal utility function and may change or be removed.
      """
      if isinstance(G, nxcg.Graph):
          if G.is_directed():
              raise ValueError(
                  "Only undirected graphs supported; got a directed graph"
              )
          return G
      if isinstance(G, nx.Graph):
          return from_networkx(
              G,
              {edge_attr: edge_default}
              if edge_attr is not None
              else None,
              edge_dtype,
          )
      # TODO: handle cugraph.Graph
      raise TypeError
  
file_path: cugraph/python/nx-cugraph/nx_cugraph/convert.py
imports: from __future__ import annotations
  import itertools
  import operator
  from collections import Counter
  from collections.abc import Mapping
  from typing import TYPE_CHECKING
  import cupy
  import networkx
  import numpy
  import nx_cugraph
  from .utils import index_dtype
label_desc: Use image node_id 7 for calling a global function with example usage: _to_undirected_graph(G, edge_attr, edge_default, edge_dtype) and returns: G, from_networkx