class_docstr: Unit tests for the cluster_wrapper module.
docstr: Verify weights of cluster_wrapper are the same after serialisation.
docstr_tok: ["Verify","weights","of","cluster_wrapper","are","the","same","after","serialisation","."]
code: def testSameWeightsAreReturnedBeforeAndAfterSerialisation(self):
      """Verify weights of cluster_wrapper are the same after serialisation."""
      # Create a dummy layer for this test
      input_shape = (
          1,
          2,
      )
      original_layer = cluster_wrapper.ClusterWeights(
          keras.layers.Dense(8, input_shape=input_shape),
          number_of_clusters=2,
      )
      # Build a layer with the given shape
      original_layer.build(input_shape)
      model = keras.Sequential([original_layer])
      # Update cluster association at least once
      original_layer.update_clustered_weights_associations()
  
      # Save and load the layer in a temp directory
      with tempfile.TemporaryDirectory() as tmp_dir_name:
          keras_file = os.path.join(tmp_dir_name, "keras_model")
          keras.models.save_model(model, keras_file)
          with cluster.cluster_scope():
              loaded_layer = keras.models.load_model(keras_file).layers[
                  0
              ]
  
      def assert_list_of_variables_all_equal(l1, l2):
          self.assertLen(
              l1,
              len(l2),
              "lists l1 and l2 are not equal: \n l1={l1} \n l2={l2}".format(
                  l1=[v.name for v in l1], l2=[v.name for v in l2]
              ),
          )
  
          name_to_var_from_l1 = {var.name: var for var in l1}
          for var2 in l2:
              self.assertIn(var2.name, name_to_var_from_l1)
              arr1 = name_to_var_from_l1[var2.name].numpy()
              arr2 = var2.numpy()
              self.assertAllEqual(arr1, arr2)
  
      # Check that trainable_weights and non_trainable_weights are the same
      # in the original layer and loaded layer
      assert_list_of_variables_all_equal(
          original_layer.trainable_weights,
          loaded_layer.trainable_weights,
      )
      assert_list_of_variables_all_equal(
          original_layer.non_trainable_weights,
          loaded_layer.non_trainable_weights,
      )
  
imports: import itertools
  import os
  import tempfile
  from absl.testing import parameterized
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras import cluster
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_config
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_wrapper
  from tensorflow_model_optimization.python.core.clustering.keras import clusterable_layer
label_desc: Use image node_id 12 for calling the ClusterWeightsTest obj's underlying member method code with example usage: obj.testSameWeightsAreReturnedBeforeAndAfterSerialisation() without return types