class_docstr: Test that the template defines the correct decomposition.
class_docstr_tok: ["Test","that","the","template","defines","the","correct","decomposition","."]
docstr: Test the correctness of the k-UpCCGSD template including the gate count
  and order, the wires the operation acts on and the correct use of parameters
  in the circuit.
docstr_tok: ["Test","the","correctness","of","the","k-UpCCGSD","template","including","the","gate","count","and","order",",","the","wires","the","operation","acts","on","and","the","correct","use","of","parameters","in","the","circuit","."]
code: def test_kupccgsd_operations(self, k, delta_sz, init_state, wires):
      """Test the correctness of the k-UpCCGSD template including the gate count
      and order, the wires the operation acts on and the correct use of parameters
      in the circuit."""
  
      # wires for generalized single excitation terms
      sz = np.array(
          [0.5 if (i % 2 == 0) else -0.5 for i in range(len(wires))]
      )
      gen_single_terms_wires = [
          wires[r : p + 1] if r < p else wires[p : r + 1][::-1]
          for r in range(len(wires))
          for p in range(len(wires))
          if sz[p] - sz[r] == delta_sz and p != r
      ]
  
      # wires for generalized pair coupled cluser double exictation terms
      pair_double_terms_wires = [
          [wires[r : r + 2], wires[p : p + 2]]
          for r in range(0, len(wires) - 1, 2)
          for p in range(0, len(wires) - 1, 2)
          if p != r
      ]
  
      n_excit_terms = len(gen_single_terms_wires) + len(
          pair_double_terms_wires
      )
      weights = np.random.normal(0, 2 * np.pi, (k, n_excit_terms))
  
      n_gates = 1 + n_excit_terms * k
      exp_unitary = [qml.FermionicDoubleExcitation] * len(
          pair_double_terms_wires
      )
      exp_unitary += [qml.FermionicSingleExcitation] * len(
          gen_single_terms_wires
      )
  
      op = qml.kUpCCGSD(
          weights,
          wires=wires,
          k=k,
          delta_sz=delta_sz,
          init_state=init_state,
      )
      queue = op.expand().operations
  
      # number of gates
      assert len(queue) == n_gates
  
      # initialization
      assert isinstance(queue[0], qml.BasisEmbedding)
  
      # order of gates
      for op1, op2 in zip(queue[1:], exp_unitary):
          assert isinstance(op1, op2)
  
      # gate parameter
      params = np.zeros((k, n_excit_terms))
      for i in range(1, n_gates):
          gate_index = (i - 1) % n_excit_terms
          if gate_index < len(pair_double_terms_wires):
              gate_index += len(gen_single_terms_wires)
          else:
              gate_index -= len(pair_double_terms_wires)
          params[(i - 1) // n_excit_terms][gate_index] = queue[
              i
          ].parameters[0]
  
      assert qml.math.allclose(params.flatten(), weights.flatten())
  
      # gate wires
      exp_wires = (
          [np.concatenate(w) for w in pair_double_terms_wires]
          + gen_single_terms_wires
      ) * k
      res_wires = [queue[i].wires.tolist() for i in range(1, n_gates)]
      for wires1, wires2 in zip(exp_wires, res_wires):
          assert np.all(wires1 == wires2)
  
imports: import pytest
  import numpy
  import pennylane
label_desc: Use image node_id 1 for calling the TestDecomposition obj's underlying member method code with example usage: obj.test_kupccgsd_operations(k, delta_sz, init_state, wires) without return types