code: def read_graph(
      graph_file, dataset_name, directed=False, weighted=False
  ):
      """
      Reads the input network in networkx.
  
      :param graph_file: The directory where graph in EPGM format is stored
      :param dataset_name: The name of the graph selected out of all the graph heads in EPGM file
      :return: The graph in networkx format
      """
      try:  # assume args.input points to an EPGM graph
          G_epgm = EPGM(graph_file)
          graphs = G_epgm.G["graphs"]
          if (
              dataset_name is None
          ):  # if dataset_name is not given, use the name of the 1st graph head
              dataset_name = graphs[0]["meta"]["label"]
              print(
                  "WARNING: dataset name not specified, using dataset '{}' in the 1st graph head".format(
                      dataset_name
                  )
              )
          graph_id = None
          for g in graphs:
              if g["meta"]["label"] == dataset_name:
                  graph_id = g["id"]
  
          g = G_epgm.to_nx(graph_id, directed)
          if weighted:
              raise NotImplementedError
          else:
              # This is the correct way to set the edge weight in a MultiGraph.
              edge_weights = {e: 1 for e in g.edges(keys=True)}
              nx.set_edge_attributes(
                  g, name="weight", values=edge_weights
              )
  
      except:  # otherwise, assume arg.input points to an edgelist file
          if weighted:
              g = nx.read_edgelist(
                  graph_file,
                  nodetype=int,
                  data=(("weight", float),),
                  create_using=nx.DiGraph(),
              )
          else:
              g = nx.read_edgelist(
                  graph_file, nodetype=int, create_using=nx.DiGraph()
              )
              for edge in g.edges():
                  g[edge[0]][edge[1]]["weight"] = 1
  
          if not directed:
              g = g.to_undirected()
  
      if not nx.is_connected(g):
          print("Graph is not connected")
          # take the largest connected component as the data
          g_ccs = (
              g.subgraph(c).copy() for c in nx.connected_components(g)
          )
          g = max(g_ccs, key=len)
          print(
              "Largest subgraph statistics: {} nodes, {} edges".format(
                  g.number_of_nodes(), g.number_of_edges()
              )
          )
  
      print(
          "Graph statistics: {} nodes, {} edges".format(
              g.number_of_nodes(), g.number_of_edges()
          )
      )
      return g
  
imports: import pytest
  import os
  import numpy
  import networkx
  from stellargraph import StellarGraph
  from stellargraph.data.edge_splitter import EdgeSplitter
  from stellargraph.data.epgm import EPGM
  import random
  import datetime
  from datetime import datetime, timedelta
  from ..test_utils import flaky_xfail_mark
  from ..test_utils.graphs import example_graph_random
label_desc: Use image node_id 2 for calling a global function with example usage: read_graph(graph_file, dataset_name, directed, weighted) and returns: g