code: def compare_graphs(nx_graph, cu_graph):
      edgelist_df = cu_graph.view_edge_list().reset_index(drop=True)
  
      df = cudf.DataFrame()
      df["source"] = edgelist_df["source"]
      df["target"] = edgelist_df["target"]
      if len(edgelist_df.columns) > 2:
          df["weight"] = edgelist_df["weights"]
          cu_to_nx_graph = nx.from_pandas_edgelist(
              df.to_pandas(),
              source="source",
              target="target",
              edge_attr=["weight"],
              create_using=nx.DiGraph(),
          )
      else:
          cu_to_nx_graph = nx.from_pandas_edgelist(
              df.to_pandas(), create_using=nx.DiGraph()
          )
  
      # first compare nodes
      ds0 = pd.Series(list(nx_graph.nodes)).sort_values(
          ignore_index=True
      )
      ds1 = pd.Series(list(cu_to_nx_graph.nodes)).sort_values(
          ignore_index=True
      )
  
      if not ds0.equals(ds1):
          print("ds0 != ds1")
          return False
  
      # second compare edges
      diff = nx.difference(nx_graph, cu_to_nx_graph)
  
      if diff.number_of_edges() > 0:
          print("diff.number_of_edges = ", diff.number_of_edges())
          return False
  
      diff = nx.difference(cu_to_nx_graph, nx_graph)
      if diff.number_of_edges() > 0:
          print("2: diff.number_of_edges = ", diff.number_of_edges())
          return False
  
      if len(edgelist_df.columns) > 2:
          df0 = cudf.from_pandas(nx.to_pandas_edgelist(nx_graph))
          merge = df.merge(
              df0, on=["source", "target"], suffixes=("_cugraph", "_nx")
          )
          print("merge = \n", merge)
          print(merge[merge.weight_cugraph != merge.weight_nx])
          if not merge["weight_cugraph"].equals(merge["weight_nx"]):
              print("weights different")
              print(merge[merge.weight_cugraph != merge.weight_nx])
              return False
  
      return True
  
imports: import gc
  import time
  import pytest
  import pandas
  import scipy
  import networkx
  import cupy
  import cudf
  import cugraph
  from cugraph.testing import utils
  from cudf.testing import assert_series_equal
  from cudf.testing.testing import assert_frame_equal
  import dask_cudf
  import cugraph.dask
  from dask.distributed import Client
  from dask_cuda import LocalCUDACluster
  from pylibcugraph import ResourceHandle
  from pylibcugraph import bfs
  from cugraph.dask.traversal.bfs import convert_to_cudf
  from cugraph.dask.common.mg_utils import is_single_gpu
label_desc: Use image node_id 3 for calling a global function with example usage: compare_graphs(nx_graph, cu_graph) and returns: True, False, False, False, False