def build_controlled_inverse(self, qc, q, q_control, q_ancillas=None, params=None): if params is None: params = self._params # get qubits q_compare = q[params['i_compare']] q_objective = q[params['i_objective']] # apply approximate payoff function cry(-2 * self.offset_angle_zero, q_control, q_objective, qc) ccry(-2 * self.offset_angle, q_control, q_compare, q_objective, qc) for i in self._params['i_state']: multi_cry_q(-2 * self.slope_angle * 2**i, [q_control, q_compare, q[i]], q_objective, q_ancillas, qc) # apply comparator to compare qubit self._comparator.build_controlled_inverse(qc, q, q_control, q_ancillas, params) # apply uncertainty model self._uncertainty_model.build_controlled_inverse( qc, q, q_control, q_ancillas, params)
def build(self, qc, q, q_ancillas=None, params=None): if params is None: params = self._params # get qubits q_compare = q[params['i_compare']] q_objective = q[params['i_objective']] # apply uncertainty model self._uncertainty_model.build(qc, q, q_ancillas, params) # apply comparator to compare qubit self._comparator.build(qc, q, q_ancillas, params) # apply approximate payoff function qc.ry(2 * self.offset_angle_zero, q_objective) cry(2 * self.offset_angle, q_compare, q_objective, qc) for i in self._params['i_state']: ccry(2 * self.slope_angle * 2**i, q_compare, q[i], q_objective, qc)