class_docstr: Tests that the template defines the correct decomposition.
class_docstr_tok: ["Tests","that","the","template","defines","the","correct","decomposition","."]
docstr: Test the correctness of the UCCSD 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","UCCSD","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_uccsd_operations(self, s_wires, d_wires, weights, ref_gates):
      """Test the correctness of the UCCSD template including the gate count
      and order, the wires the operation acts on and the correct use of parameters
      in the circuit."""
  
      sqg = 10 * len(s_wires) + 72 * len(d_wires)
  
      cnots = 0
      for s_wires_ in s_wires:
          cnots += 4 * (len(s_wires_) - 1)
  
      for d_wires_ in d_wires:
          cnots += 16 * (
              len(d_wires_[0]) - 1 + len(d_wires_[1]) - 1 + 1
          )
      N = 6
      wires = range(N)
  
      ref_state = np.array([1, 1, 0, 0, 0, 0])
  
      op = qml.UCCSD(
          weights,
          wires,
          s_wires=s_wires,
          d_wires=d_wires,
          init_state=ref_state,
      )
      raw_queue = op.expand().operations
  
      # hack to avoid updating the test data:
      # expand the other templates, which now
      # queue as a single operation
      queue = []
      for op in raw_queue:
          if op.name in [
              "FermionicSingleExcitation",
              "FermionicDoubleExcitation",
          ]:
              queue.extend(op.expand().operations)
          else:
              queue.append(op)
  
      assert len(queue) == sqg + cnots + 1
  
      for gate in ref_gates:
          idx = gate[0]
  
          exp_gate = gate[1]
          res_gate = queue[idx]
          assert isinstance(res_gate, exp_gate)
  
          exp_wires = gate[2]
          res_wires = queue[idx]._wires
          assert res_wires.tolist() == exp_wires
  
          exp_weight = gate[3]
          res_weight = queue[idx].parameters
          assert np.allclose(res_weight, exp_weight)
  
file_path: pennylane/tests/templates/test_subroutines/test_uccsd.py
imports: import pytest
  import numpy
  from pennylane 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_uccsd_operations(s_wires, d_wires, weights, ref_gates) without return types