class_docstr: Tests that the template defines the correct decomposition.
docstr: Test the correctness of the ParticleConservingU1 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","ParticleConservingU1","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):
      """Test the correctness of the ParticleConservingU1 template including the gate count
      and order, the wires each operation acts on and the correct use of parameters
      in the circuit."""
  
      qubits = 4
      layers = 2
      weights = np.random.random(size=(layers, qubits - 1, 2))
  
      gates_per_u1 = 16
      gates_per_layer = gates_per_u1 * (qubits - 1)
      gate_count = layers * gates_per_layer + 1
  
      gates_u1 = [
          qml.CZ,
          qml.CRot,
          qml.PhaseShift,
          qml.CNOT,
          qml.PhaseShift,
          qml.CNOT,
          qml.PhaseShift,
      ]
      gates_ent = gates_u1 + [qml.CZ, qml.CRot] + gates_u1
  
      wires = list(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)]
  
      op = qml.ParticleConservingU1(
          weights, wires, init_state=np.array([1, 1, 0, 0])
      )
      queue = op.expand().operations
  
      assert gate_count == len(queue)
  
      # check initialization of the qubit register
      assert isinstance(queue[0], qml.BasisEmbedding)
  
      # check all quantum operations
      idx_CRot = 8
      for l in range(layers):
          for i in range(qubits - 1):
              exp_wires = self._wires_gates_u1(nm_wires[i])
  
              phi = weights[l, i, 0]
              theta = weights[l, i, 1]
  
              for j, exp_gate in enumerate(gates_ent):
                  idx = gates_per_layer * l + gates_per_u1 * i + j + 1
  
                  # check that the gates are applied in the right order
                  assert isinstance(queue[idx], exp_gate)
  
                  # check the wires the gates act on
                  assert queue[idx].wires.tolist() == exp_wires[j]
  
                  # check that parametrized gates take the parameters \phi and \theta properly
                  if exp_gate is qml.CRot:
                      if j < idx_CRot:
                          exp_params = [-phi, np.pi, phi]
                      if j > idx_CRot:
                          exp_params = [phi, np.pi, -phi]
                      if j == idx_CRot:
                          exp_params = [0, 2 * theta, 0]
  
                      assert queue[idx].parameters == exp_params
  
                  elif exp_gate is qml.PhaseShift:
                      if j < idx_CRot:
                          exp_params = (
                              phi if j == idx_CRot / 2 else -phi
                          )
                      if j > idx_CRot:
                          exp_params = (
                              -phi
                              if j == (3 * idx_CRot + 2) / 2
                              else phi
                          )
  
                      assert queue[idx].parameters == exp_params
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestDecomposition obj's underlying member method code with example usage: obj.test_operations() without return types