class_docstr: EPGM class with converter methods to edgelist, adjacency matrix, etc.
class_docstr_tok: ["EPGM","class","with","converter","methods","to","edgelist",",","adjacency","matrix",",","etc","."]
docstr: Convert the graph specified by its graph_id to networkx graph
docstr_tok: ["Convert","the","graph","specified","by","its","graph_id","to","networkx","graph"]
code: def to_nx_OLD(
      self,
      graph_id,
      directed=False,
      parallel_processing=True,
      n_jobs=multiprocessing.cpu_count(),
      progress=True,
      chunksize=100,
  ):
      """Convert the graph specified by its graph_id to networkx graph"""
  
      if (
          graph_id in self.G_nx.keys()
      ):  # if self.G_nx[graph_id] already exists, just return it, otherwise evaluate it
          return self.G_nx[graph_id]
      else:
          print(
              "Converting the EPGM graph {} to NetworkX graph...".format(
                  graph_id
              )
          )
          if not any([graph_id in g["id"] for g in self.G["graphs"]]):
              raise Exception(
                  "Graph with id {} does not exist".format(graph_id)
              )
  
          # List relevant nodes and edges:
          print("...extracting relevant nodes...", end="")
          nodes = [
              v["id"]
              for v in self.G["vertices"]
              if graph_id in v["meta"]["graphs"]
          ]
          print(" ...{} nodes extracted...".format(len(nodes)))
          print("...extracting relevant edges...", end="")
          edges = [
              (e["source"], e["target"])
              for e in self.G["edges"]
              if graph_id in e["meta"]["graphs"]
          ]
          print(" ...{} edges extracted...".format(len(edges)))
          # TODO: implement the case of weighted edges
  
          # create a graph as dict of lists in the format (node_id: [neighbour nodes])
          print("...building the graph as dict of lists...")
          print(
              "...[parallel_processing: {}, n_jobs: {}, progress_bar: {}]".format(
                  parallel_processing, n_jobs, progress
              )
          )
  
          if parallel_processing:  # parallel execution
              pool = Pool(processes=n_jobs)
              if progress:
                  n = len(nodes)
                  self.G_nx[graph_id] = []
  
                  # pbar = ProgressBar(
                  #     widgets=[
                  #         SimpleProgress(
                  #             format="%(value_s)s of %(max_value_s)s nodes processed (%(percentage)3d%%)"
                  #         )
                  #     ],
                  #     maxval=n,
                  # ).start()
                  # _ = [pool.apply_async(partial(node_neighbours, edges=edges), args=(v,),
                  #                       callback=self.G_nx[graph_id].append) for v in nodes]
                  # it seems that appending results using callback works much slower than either pool.map_async or pool.map
                  # while len(self.G_nx[graph_id]) != n:
                  #     pbar.update(len(self.G_nx[graph_id]))
                  #     sleep(1)
  
                  graph = pool.imap(
                      partial(node_neighbours, edges=edges),
                      nodes,
                      chunksize,
                  )  # lazy map
                  # evaluate batches of imap, as the progress bar is being updated:
                  while len(self.G_nx[graph_id]) != n:
                      self.G_nx[graph_id].append(next(graph))
                      # pbar.update(len(self.G_nx[graph_id]))
  
                  # pbar.finish()
  
                  self.G_nx[graph_id] = dict(self.G_nx[graph_id])
  
              else:
                  self.G_nx[graph_id] = dict(
                      pool.map(
                          partial(node_neighbours, edges=edges), nodes
                      )
                  )
  
              pool.close()
              pool.join()
  
          else:  # sequential execution
              self.G_nx[graph_id] = {
                  v: [e[1] for e in edges if e[0] == v] for v in nodes
              }  # this works ~2.5x faster (for cora dataset) than the above for loop
  
          print("...converting the graph to nx format...")
          self.G_nx[graph_id] = nx.from_dict_of_lists(
              self.G_nx[graph_id]
          )
  
          if directed:
              self.G_nx[graph_id] = self.G_nx[graph_id].to_directed()
          else:
              self.G_nx[graph_id] = self.G_nx[graph_id].to_undirected()
  
          return self.G_nx[graph_id]
  
imports: from collections import OrderedDict
  import networkx
  from networkx.readwrite import json_graph
  import os
  import json
  import uuid
  import numpy
  import scipy.sparse
  import multiprocessing
  from multiprocessing import Pool
  from functools import partial
  from time import sleep
label_desc: Use image node_id 12 for calling the EPGM obj's underlying member method code with example usage: obj.to_nx_OLD(graph_id, directed, parallel_processing, n_jobs, progress, chunksize) and returns: self, self