class_docstr: A plain python object modeling a heterogeneous graph with various
  attributes (Node types in :class:`HeteroGraph` require string type).
  
  Args:
      G (:class:`networkx.classes.graph`): A NetworkX graph object which
          contains features and labels for each node type and edge type.
      **kwargs: Keyworded argument list with keys such
          as :obj:`"node_feature"`, :obj:`"node_label"` and
          corresponding attributes.
class_docstr_tok: ["A","plain","python","object","modeling","a","heterogeneous","graph","with","various","attributes","(","Node","types","in",":","class",":","`","HeteroGraph","`","require","string","type",")",".","Args",":","G","(",":","class",":","`","networkx.classes.graph","`",")",":","A","NetworkX","graph","object","which","contains","features","and","labels","for","each","node","type","and","edge","type",".","*","*","kwargs",":","Keyworded","argument","list","with","keys","such","as",":","obj",":","`","``","node_feature","''","`",",",":","obj",":","`","``","node_label","''","`","and","corresponding","attributes","."]
docstr: Check validity.
docstr_tok: ["Check","validity","."]
code: def _is_valid(self):
      r"""
      Check validity.
      """
      for key in self.keys:
          if self._is_node_attribute(key):
              num_nodes = 0
              if key != "node_to_tensor_mapping":
                  for node_type in self[key]:
                      num_nodes += self[key][node_type].size(0)
              else:
                  num_nodes = self[key].size(0)
              assert (
                  sum(self.num_nodes().values()) == num_nodes
              ), f"key {key} is not valid"
          if self._is_edge_attribute(key):
              num_edges = 0
              if key != "edge_to_tensor_mapping":
                  for edge_type in self[key]:
                      num_edges += self[key][edge_type].size(0)
              else:
                  num_edges = self[key].size(0)
              assert (
                  sum(self.num_edges().values()) == num_edges
                  or self.num_edges * 2 == num_edges
              ), f"key {key} is not valid"
  
imports: import math
  import copy
  import random
  import torch
  import networkx
  import numpy
  from deepsnap.graph import Graph
  from typing import Dict, List, Union
  import warnings
label_desc: Use image node_id 22 for calling the HeteroGraph obj's underlying member method code with example usage: obj._is_valid() without return types