class_docstr: An abstract representation class utilizing PyTorch Geometric message passing layers.
  
  It comprises:
      * base (entity) representations, which can also be passed as hints
      * a sequence of message passing layers. They are utilized in an abstract
        :meth:`MessagePassingRepresentation._message_passing` to enrich the base representations
        by neighborhood information.
      * a sequence of activation layers in between the message passing layers.
      * an `edge_index` buffer, which stores the edge index and is moved to the device alongside
        the module.
docstr: Initialize the representation.
  
  :param triples_factory:
      the factory comprising the training triples used for message passing
  
  :param layers:
      the message passing layer(s) or hints thereof
  :param layers_kwargs:
      additional keyword-based parameters passed to the layers upon instantiation
  
  :param base:
      the base representations for entities, or a hint thereof
  :param base_kwargs:
      additional keyword-based parameters passed to the base representations upon instantiation
  
  :param shape:
      the output shape. Defaults to the base representation shape. Has to match to output shape of the last
      message passing layer.
  :param max_id:
      the number of representations. If provided, has to match the base representation's max_id
  
  :param activations:
      the activation(s), or hints thereof
  :param activations_kwargs:
      additional keyword-based parameters passed to the activations upon instantiation
  :param restrict_k_hop:
      whether to restrict the message passing only to the k-hop neighborhood, when only some indices
      are requested. This utilizes :func:`torch_geometric.utils.k_hop_subgraph`.
  
  :param kwargs:
      additional keyword-based parameters passed to :meth:`Representation.__init__`
  
  :raises ImportError:
      if PyTorch Geometric is not installed
  :raises ValueError:
      if the number of activations and message passing layers do not match (after input normalization)
docstr_tok: ["Initialize","the","representation",".",":","param","triples_factory",":","the","factory","comprising","the","training","triples","used","for","message","passing",":","param","layers",":","the","message","passing","layer","(","s",")","or","hints","thereof",":","param","layers_kwargs",":","additional","keyword-based","parameters","passed","to","the","layers","upon","instantiation",":","param","base",":","the","base","representations","for","entities",",","or","a","hint","thereof",":","param","base_kwargs",":","additional","keyword-based","parameters","passed","to","the","base","representations","upon","instantiation",":","param","shape",":","the","output","shape",".","Defaults","to","the","base","representation","shape",".","Has","to","match","to","output","shape","of","the","last","message","passing","layer",".",":","param","max_id",":","the","number","of","representations",".","If","provided",",","has","to","match","the","base","representation","'s","max_id",":","param","activations",":","the","activation","(","s",")",",","or","hints","thereof",":","param","activations_kwargs",":","additional","keyword-based","parameters","passed","to","the","activations","upon","instantiation",":","param","restrict_k_hop",":","whether","to","restrict","the","message","passing","only","to","the","k-hop","neighborhood",",","when","only","some","indices","are","requested",".","This","utilizes",":","func",":","`","torch_geometric.utils.k_hop_subgraph","`",".",":","param","kwargs",":","additional","keyword-based","parameters","passed","to",":","meth",":","`","Representation.__init__","`",":","raises","ImportError",":","if","PyTorch","Geometric","is","not","installed",":","raises","ValueError",":","if","the","number","of","activations","and","message","passing","layers","do","not","match","(","after","input","normalization",")"]
code: def __init__(
      self,
      triples_factory: CoreTriplesFactory,
      layers: OneOrManyHintOrType[MessagePassing],
      layers_kwargs: OneOrManyOptionalKwargs = None,
      base: HintOrType[Representation] = None,
      base_kwargs: OptionalKwargs = None,
      max_id: Optional[int] = None,
      shape: Optional[OneOrSequence[int]] = None,
      activations: OneOrManyHintOrType[nn.Module] = None,
      activations_kwargs: OneOrManyOptionalKwargs = None,
      restrict_k_hop: bool = False,
      **kwargs,
  ):
      """
      Initialize the representation.
  
      :param triples_factory:
          the factory comprising the training triples used for message passing
  
      :param layers:
          the message passing layer(s) or hints thereof
      :param layers_kwargs:
          additional keyword-based parameters passed to the layers upon instantiation
  
      :param base:
          the base representations for entities, or a hint thereof
      :param base_kwargs:
          additional keyword-based parameters passed to the base representations upon instantiation
  
      :param shape:
          the output shape. Defaults to the base representation shape. Has to match to output shape of the last
          message passing layer.
      :param max_id:
          the number of representations. If provided, has to match the base representation's max_id
  
      :param activations:
          the activation(s), or hints thereof
      :param activations_kwargs:
          additional keyword-based parameters passed to the activations upon instantiation
      :param restrict_k_hop:
          whether to restrict the message passing only to the k-hop neighborhood, when only some indices
          are requested. This utilizes :func:`torch_geometric.utils.k_hop_subgraph`.
  
      :param kwargs:
          additional keyword-based parameters passed to :meth:`Representation.__init__`
  
      :raises ImportError:
          if PyTorch Geometric is not installed
      :raises ValueError:
          if the number of activations and message passing layers do not match (after input normalization)
      """
      # fail if dependencies are missing
      if (
          MessagePassing is None
          or layer_resolver is None
          or k_hop_subgraph is None
      ):
          raise ImportError(_PYG_INSTALLATION_TEXT)
  
      # avoid cyclic import
      from . import representation_resolver
  
      # the base representations, e.g., entity embeddings or features
      base = representation_resolver.make(
          base,
          pos_kwargs=base_kwargs,
          max_id=triples_factory.num_entities,
      )
  
      # verify max_id
      max_id = max_id or base.max_id
      if max_id != base.max_id:
          raise ValueError(
              f"Inconsistent max_id={max_id} vs. base.max_id={base.max_id}"
          )
  
      # verify shape
      shape = ShapeError.verify(
          shape=shape or base.shape, reference=shape
      )
      super().__init__(max_id=max_id, shape=shape, **kwargs)
  
      # assign sub-module *after* super call
      self.base = base
  
      # initialize layers
      self.layers = nn.ModuleList(
          layer_resolver.make_many(layers, layers_kwargs)
      )
      self.flow = _extract_flow(self.layers)
  
      # normalize activation
      activations = list(upgrade_to_sequence(activations))
      if len(activations) == 1:
          activations = activations * len(self.layers)
      self.activations = nn.ModuleList(
          activation_resolver.make_many(activations, activations_kwargs)
      )
  
      # check consistency
      if len(self.layers) != len(self.activations):
          raise ValueError(
              f"The lengths of the list of message passing layers ({len(self.layers)}) "
              f"and activation layers ({len(self.activation)}) differs! To disable activations "
              f"on certain layers, e.g., the last, use torch.nn.Identity."
          )
  
      # buffer edge index for message passing
      self.register_buffer(
          name="edge_index",
          tensor=get_edge_index(triples_factory=triples_factory),
      )
  
      self.restrict_k_hop = restrict_k_hop
  
imports: from abc import ABC, abstractmethod
  from typing import Collection, Literal, Optional, Sequence
  import torch
  from class_resolver import ClassResolver, HintOrType, OneOrManyHintOrType, OneOrManyOptionalKwargs, OptionalKwargs
  from class_resolver.contrib.torch import activation_resolver
  from docdata import parse_docdata
  from torch import nn
  from .representation import Representation
  from .utils import ShapeError
  from ..triples.triples_factory import CoreTriplesFactory
  from ..typing import OneOrSequence
  from ..utils import get_edge_index, upgrade_to_sequence
label_desc: Use image node_id 1 to create a new MessagePassingRepresentation object from inherited base classes: Representation, ABC with example: obj = MessagePassingRepresentation(triples_factory, layers, layers_kwargs, base, base_kwargs, max_id, shape, activations, activations_kwargs, restrict_k_hop)