code: def get_reversed_unification_program(angles, control_indices,
                                       target, controls, mode):
      
      if mode == 'phase':
          gate = RZ
      elif mode == 'magnitude':
          gate = RY
      else:
          raise ValueError("mode must be \'phase\' or \'magnitude\'")
  
      reversed_gates = []
  
      for j in range(len(angles)):
          if angles[j] != 0:
              # angle is negated in conjugated/reversed circuit
              reversed_gates.append(gate(-angles[j], target))
          if len(controls) > 0:
              reversed_gates.append(CNOT(controls[control_indices[j] - 1],
                                         target))
  
      return Program().inst(reversed_gates[::-1])
docs: Gets the Program representing the reversed circuit
      for the decomposition of the uniformly controlled
      rotations in a unification step.
  
      If :math:`n` is the number of controls, the indices within control indices
      must range from 1 to :math:`n`, inclusive. The length of control_indices
      and the length of angles must both be :math:`2^n`.
  
      :param list angles: The angles of rotation in the the decomposition,
                          in order from left to right
      :param list control_indices: a list of positions for the controls of the
                                   CNOTs used when decomposing uniformly
                                   controlled rotations; see
                                   get_cnot_control_positions for labelling
                                   conventions.
      :param int target: Index of the target of all rotations
      :param list controls: Index of the controls, in order from bottom to top.
      :param str mode: The unification mode. Is either 'phase', corresponding
                       to controlled RZ rotations, or 'magnitude', corresponding
                       to controlled RY rotations.
      :return: The reversed circuit of this unification step.
      :rtype: Program