class_docstr: Unit tests for the pennylane.qnn.keras.KerasLayer class.
class_docstr_tok: ["Unit","tests","for","the","pennylane.qnn.keras.KerasLayer","class","."]
docstr: Test if the build() method correctly passes on user specified weight_specs to the
  inherited add_weight() method. This is done by monkeypatching add_weight() so that it
  simply returns its input keyword arguments. The qnode_weights dictionary should then have
  values that are the input keyword arguments, and we check that the specified weight_specs
  keywords are there.
docstr_tok: ["Test","if","the","build","(",")","method","correctly","passes","on","user","specified","weight_specs","to","the","inherited","add_weight","(",")","method",".","This","is","done","by","monkeypatching","add_weight","(",")","so","that","it","simply","returns","its","input","keyword","arguments",".","The","qnode_weights","dictionary","should","then","have","values","that","are","the","input","keyword","arguments",",","and","we","check","that","the","specified","weight_specs","keywords","are","there","."]
code: def test_qnode_weights_with_spec(
      self, get_circuit, monkeypatch, output_dim, n_qubits
  ):  # pylint: disable=no-self-use
      """Test if the build() method correctly passes on user specified weight_specs to the
      inherited add_weight() method. This is done by monkeypatching add_weight() so that it
      simply returns its input keyword arguments. The qnode_weights dictionary should then have
      values that are the input keyword arguments, and we check that the specified weight_specs
      keywords are there."""
  
      add_weight = KerasLayer.add_weight
  
      specs = {}
  
      def add_weight_dummy(self, **kwargs):
          """Dummy function for mocking out the add_weight method to store the kwargs in a dict"""
          specs[kwargs["name"]] = kwargs
          return add_weight(self, **kwargs)
  
      weight_specs = {
          "w1": {"initializer": "random_uniform", "trainable": False},
          "w2": {
              "initializer": tf.keras.initializers.RandomNormal(
                  mean=0, stddev=0.5
              )
          },
          "w3": {},
          "w4": {},
          "w5": {},
          "w6": {},
          "w7": {},
      }
  
      with monkeypatch.context() as m:
          m.setattr(
              tf.keras.layers.Layer, "add_weight", add_weight_dummy
          )
          c, w = get_circuit
          layer = KerasLayer(
              c, w, output_dim, weight_specs=weight_specs
          )
          layer.build(input_shape=(10, n_qubits))
  
          for weight in layer.weight_shapes:
              assert all(
                  item in specs[weight].items()
                  for item in weight_specs[weight].items()
              )
  
imports: from collections import defaultdict
  import numpy
  import pytest
  import pennylane
label_desc: Use image node_id 11 for calling the TestKerasLayer obj's underlying member method code with example usage: obj.test_qnode_weights_with_spec(get_circuit, monkeypatch, output_dim, n_qubits) and returns: add_weight