Exemple #1
0
    def use_MP_Y(self, tar_bit_pos, controls, rad_angles):
        """
        This is an override of a function in the parent class
        EchoingSEO_reader. This is the only use_ function of this class that
        doesn't simply echo its input line. This function does most of its
        work inside the Multiplexor_SEO_writer.write() function that it calls.

        Parameters
        ----------
        tar_bit_pos : int
        controls : Controls
        rad_angles : list[float]

        Returns
        -------
        None

        """
        # the flag eval_all_vars = False so should check this
        assert utg.all_floats(rad_angles)

        emb, nt, nf = self.emb_for_plexor(tar_bit_pos, controls)
        self.wr.emb = emb
        self.wr.rad_angles = rad_angles
        self.wr.num_T_trols = nt
        self.wr.num_F_trols = nf
        # style and num_gbits for wr are set by constructor

        self.wr.write()
        # revert to default embedder
        self.wr.emb = CktEmbedder(self.num_qbits, self.num_qbits)
    def use_ROTN(self, angle_x_rads, angle_y_rads, angle_z_rads, tar_bit_pos,
                 controls):
        """
        Writes line in IBM qasm file corresponding to an English file line
        of type: ROTN with no controls.

        Parameters
        ----------
        angle_x_rads : float
        angle_y_rads : float
        angle_z_rads : float
        tar_bit_pos : int
        controls : Controls

        Returns
        -------
        None

        """
        assert len(controls.bit_pos) == 0

        rad_ang_list = [angle_x_rads, angle_y_rads, angle_z_rads]
        assert utg.all_floats(rad_ang_list), \
            'At present, IBM qasm does not support variable angles'
        arr = OneBitGates.rot(*rad_ang_list)
        line_str = Qubiter_to_IBMqasm.qasm_line_for_rot(arr, tar_bit_pos)
        self.aqasm_out.write(line_str)

        if self.write_qubiter_files:
            self.qbtr_wr.write_controlled_one_bit_gate(tar_bit_pos, controls,
                                                       OneBitGates.rot,
                                                       rad_ang_list)
Exemple #3
0
    def use_ROTN(self, angle_x_rads, angle_y_rads, angle_z_rads, tar_bit_pos,
                 controls):
        """
        Writes line in Cirq file corresponding to an English file line
        of type: ROTN with no controls.

        Parameters
        ----------
        angle_x_rads : float
        angle_y_rads : float
        angle_z_rads : float
        tar_bit_pos : int
        controls : Controls

        Returns
        -------
        None

        """
        assert len(controls.bit_pos) == 0

        rad_ang_list = [angle_x_rads, angle_y_rads, angle_z_rads]
        assert utg.all_floats(rad_ang_list), \
            "With Cirq, ROTN with any of its 3 angles variable is " +\
            "not allowed. Workaround: can use 3 rotations of type " +\
            "Rx, Ry or Rz with variable angles."
        arr = OneBitGates.rot(*rad_ang_list)
        delta, left_rads, center_rads, right_rads = \
            UnitaryMat.u2_zyz_decomp(arr)

        end_str = ').on(' + self.bit2str(tar_bit_pos) + '))\n'

        line_str = 'ckt.append(Rz(rads=' + str(-2 * right_rads) + end_str
        self.aqasm_out.write(line_str)

        line_str = 'ckt.append(Ry(rads=' + str(-2 * center_rads) + end_str
        self.aqasm_out.write(line_str)

        line_str = 'ckt.append(Rz(rads=' + str(-2 * left_rads) + end_str
        self.aqasm_out.write(line_str)

        if self.write_qubiter_files:
            self.qbtr_wr.write_controlled_one_bit_gate(tar_bit_pos, controls,
                                                       OneBitGates.rot_ax,
                                                       [right_rads, 3])
            self.qbtr_wr.write_controlled_one_bit_gate(tar_bit_pos, controls,
                                                       OneBitGates.rot_ax,
                                                       [center_rads, 2])
            self.qbtr_wr.write_controlled_one_bit_gate(tar_bit_pos, controls,
                                                       OneBitGates.rot_ax,
                                                       [left_rads, 3])