code: def test_flatten_unflatten():
      """Test the flatten and unflatten methods."""
  
      def acquaintances(index, *_, use_CNOT=True, **__):
          return qml.CNOT(index) if use_CNOT else qml.CZ(index)
  
      weights = np.array([0.5, 0.6, 0.7])
      wires = qml.wires.Wires((0, 1, 2))
  
      op = qml.templates.TwoLocalSwapNetwork(
          wires,
          acquaintances,
          weights,
          fermionic=True,
          shift=False,
          use_CNOT=False,
      )
      data, metadata = op._flatten()
      assert qml.math.allclose(data[0], weights)
      assert metadata[0] == wires
      assert metadata[1] == (
          ("acquaintances", acquaintances),
          ("fermionic", True),
          ("shift", False),
          ("use_CNOT", False),
      )
  
      # make sure metadata is hashable
      assert hash(metadata)
  
      new_op = type(op)._unflatten(*op._flatten())
      assert qml.equal(new_op, op)
      assert new_op is not op
  
imports: import pytest
  from pennylane import numpy
  import pennylane
label_desc: Use image node_id 1 for calling a global function with example usage: test_flatten_unflatten() and returns: unknown