class_docstr: Tests that the template defines the correct decomposition.
docstr: Test the correctness of the ParticleConservingU2 template including the gate count
  and order, the wires each operation acts on and the correct use of parameters
  in the circuit.
docstr_tok: ["Test","the","correctness","of","the","ParticleConservingU2","template","including","the","gate","count","and","order",",","the","wires","each","operation","acts","on","and","the","correct","use","of","parameters","in","the","circuit","."]
code: def test_operations(self, layers, qubits, init_state):
      """Test the correctness of the ParticleConservingU2 template including the gate count
      and order, the wires each operation acts on and the correct use of parameters
      in the circuit."""
      weights = np.random.normal(0, 2 * np.pi, (layers, 2 * qubits - 1))
  
      n_gates = 1 + (qubits + (qubits - 1) * 3) * layers
  
      exp_gates = (
          [qml.RZ] * qubits
          + ([qml.CNOT] + [qml.CRX] + [qml.CNOT]) * (qubits - 1)
      ) * layers
  
      op = qml.ParticleConservingU2(
          weights, wires=range(qubits), 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_gates):
          assert isinstance(op1, op2)
  
      # gate parameter
      params = np.array(
          [
              queue[i].parameters
              for i in range(1, n_gates)
              if queue[i].parameters != []
          ]
      )
      weights[:, qubits:] = weights[:, qubits:] * 2
      assert np.allclose(params.flatten(), weights.flatten())
  
      # gate wires
      wires = range(qubits)
      nm_wires = [wires[l : l + 2] for l in range(0, qubits - 1, 2)]
      nm_wires += [wires[l : l + 2] for l in range(1, qubits - 1, 2)]
  
      exp_wires = []
      for _ in range(layers):
          for i in range(qubits):
              exp_wires.append([wires[i]])
          for j in nm_wires:
              exp_wires.append(list(j))
              exp_wires.append(list(j[::-1]))
              exp_wires.append(list(j))
  
      res_wires = [queue[i].wires.tolist() for i in range(1, n_gates)]
  
      assert res_wires == exp_wires
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 1 for calling the TestDecomposition obj's underlying member method code with example usage: obj.test_operations(layers, qubits, init_state) without return types