class_docstr: Manages the partitioning related controls.
  
  Handles data generation and informs model about changes in partition.
class_docstr_tok: ["Manages","the","partitioning","related","controls",".","Handles","data","generation","and","informs","model","about","changes","in","partition","."]
docstr: Generates the metadata needed for persisting and loading partition embeddings and other parameters.
code: def _generate_partition_params(self):
      """Generates the metadata needed for persisting and loading partition embeddings and other parameters."""
  
      num_optimizer_hyperparams = (
          self._model.optimizer.get_hyperparam_count()
      )
  
      # create entity embeddings and optimizer hyperparams for all entities
      for i in range(self.partitioner_k):
          with shelve.open(
              self.ent_map_fname, writeback=True
          ) as ent_partition:
              with shelve.open(self.partitioner.files[i]) as bucket:
                  out_dict_key = str(i)
                  num_ents_bucket = bucket["indexes"].shape[0]
                  # print(num_ents_bucket)
                  # TODO change the hardcoding from 3 to actual hyperparam of
                  # optim
                  opt_param = np.zeros(
                      shape=(
                          num_ents_bucket,
                          num_optimizer_hyperparams,
                          self.internal_k,
                      ),
                      dtype=np.float32,
                  )
                  ent_emb = self._model.encoding_layer.ent_init(
                      shape=(num_ents_bucket, self.internal_k),
                      dtype=tf.float32,
                  ).numpy()
                  ent_partition.update(
                      {out_dict_key: [opt_param, ent_emb]}
                  )
  
      # create relation embeddings and optimizer hyperparams for all relations
      # relations are not partitioned
      with shelve.open(
          self.rel_map_fname, writeback=True
      ) as rel_partition:
          out_dict_key = str(0)
          # TODO change the hardcoding from 3 to actual hyperparam of optim
          opt_param = np.zeros(
              shape=(
                  self.num_rels,
                  num_optimizer_hyperparams,
                  self.internal_k,
              ),
              dtype=np.float32,
          )
          rel_emb = self._model.encoding_layer.rel_init(
              shape=(self.num_rels, self.internal_k), dtype=tf.float32
          ).numpy()
          rel_partition.update({out_dict_key: [opt_param, rel_emb]})
  
      # for every partition
      for i in range(len(self.partitioner.partitions)):
          # get the source and dest bucket
          # print(self.partitioner.partitions[i].backend.mapper.metadata['name'])
          splits = (
              self.partitioner.partitions[i]
              .backend.mapper.metadata["name"]
              .split("-")
          )
          source_bucket = splits[0][-1]
          dest_bucket = splits[1]
          all_keys_merged_buckets = []
          # get all the unique entities present in the buckets
          with shelve.open(
              self.partitioner.files[int(source_bucket)]
          ) as bucket:
              all_keys_merged_buckets.extend(bucket["indexes"])
          if source_bucket != dest_bucket:
              with shelve.open(
                  self.partitioner.files[int(dest_bucket)]
              ) as bucket:
                  all_keys_merged_buckets.extend(bucket["indexes"])
  
          # since we would be concatenating the bucket embeddings, let's find what 0, 1, 2 etc indices of
          # embedding matrix means.
          # bucket entity value to ent_emb matrix index mappings eg: 2001 ->
          # 0, 2002->1, 2003->2, ...
          merged_bucket_to_ent_mat_mappings = {}
          for key, val in zip(
              all_keys_merged_buckets,
              np.arange(0, len(all_keys_merged_buckets)),
          ):
              merged_bucket_to_ent_mat_mappings[key] = val
          emb_mat_order = []
  
          # partitions do not contain all entities of the bucket they belong to.
          # they will produce data from 0->n idx. So we need to remap the get position of the
          # entities of the partition in the concatenated emb matrix
          # data_index -> original_ent_index -> ent_emb_matrix mappings (a->b->c) 0->2002->1, 1->2003->2
          # (because 2001 may not exist in this partition)
          # a->b mapping
          num_ents_bucket = self.partitioner.partitions[
              i
          ].backend.mapper.get_entities_count()
          sorted_partition_keys = np.arange(num_ents_bucket)
          sorted_partition_values = self.partitioner.partitions[
              i
          ].backend.mapper.get_indexes(
              sorted_partition_keys, type_of="e", order="ind2raw"
          )
          for val in sorted_partition_values:
              # a->b->c mapping
              emb_mat_order.append(
                  merged_bucket_to_ent_mat_mappings[int(val)]
              )
  
          # store it
          with shelve.open(
              self.ent_meta_fname, writeback=True
          ) as metadata:
              metadata[str(i)] = emb_mat_order
  
          rel_mat_order = []
          # with
          # shelve.open(self.partitioner.partitions[i].backend.mapper.metadata['relations'])
          # as rel_sh:
          num_rels_bucket = self.partitioner.partitions[
              i
          ].backend.mapper.get_relations_count()
          sorted_partition_keys = np.arange(num_rels_bucket)
          sorted_partition_values = self.partitioner.partitions[
              i
          ].backend.mapper.get_indexes(
              sorted_partition_keys, type_of="r", order="ind2raw"
          )
          # a : 0 to n
          for val in sorted_partition_values:
              # a->b mapping
              rel_mat_order.append(int(val))
  
          with shelve.open(
              self.rel_meta_fname, writeback=True
          ) as metadata:
              metadata[str(i)] = rel_mat_order
  
imports: import abc
  import glob
  import logging
  import os
  import shelve
  import shutil
  import tempfile
  from datetime import datetime
  import numpy
  import tensorflow
  from .graph_partitioner import PARTITION_ALGO_REGISTRY, AbstractGraphPartitioner
label_desc: Use image node_id 2 for calling the BucketPartitionDataManager obj's underlying member method code with example usage: obj._generate_partition_params() without return types