Пример #1
0
    def generate_sequence(self, config):
        """Generate sequence by adding gates/pulses to waveforms."""
        # get parameters
        n_pulse = int(config['# of pulses'])
        alternate = config['Alternate pulse direction']

        if n_pulse == 0:
            self.add_gate_to_all(Gate.I)
        for n in range(n_pulse):
            pulse_type = config['Pulse']
            # check if alternate pulses
            if alternate and (n % 2) == 1:
                pulse_type = pulse_type.replace('p', 'm')
                gate = Gate.__getattr__(pulse_type)
            else:
                gate = Gate.__getattr__(pulse_type)
            self.add_gate_to_all(gate)
Пример #2
0
    def generate_sequence(self, config):
        """Generate sequence by adding gates/pulses to waveforms."""
        # get parameters
        sequence = config['Sequence']
        # Number of Cliffords to generate
        N_cliffords = int(config['Number of Cliffords'])
        randomize = config['Randomize']
        interleave = config['Interleave 1-QB Gate']
        multi_seq = config.get('Output multiple sequences', False)
        if interleave is True:
            interleaved_gate = config['Interleaved 1-QB Gate']
        else:
            interleaved_gate = -999.999
        # generate new randomized clifford gates only if configuration changes
        if (self.prev_sequence != sequence or self.prev_randomize != randomize
                or self.prev_N_cliffords != N_cliffords
                or self.prev_interleave != interleave or multi_seq
                or self.prev_interleaved_gate != interleaved_gate):

            self.prev_randomize = randomize
            self.prev_N_cliffords = N_cliffords
            self.prev_interleave = interleave
            self.prev_sequence = sequence

            multi_gate_seq = []
            for n in range(self.n_qubit):
                # Generate 1QB RB sequence
                single_gate_seq = []
                for i in range(N_cliffords):
                    rndnum = rnd.randint(0, 23)
                    add_singleQ_clifford(rndnum,
                                         single_gate_seq,
                                         pad_with_I=False)
                    # If interleave gate,
                    if interleave is True:
                        self.prev_interleaved_gate = interleaved_gate
                        single_gate_seq.append(
                            Gate.__getattr__(interleaved_gate))

                recovery_gate = self.get_recovery_gate(single_gate_seq)
                single_gate_seq.append(recovery_gate)
                multi_gate_seq.append(single_gate_seq)

            # transpose list of lists
            multi_gate_seq = list(map(list, zip(*multi_gate_seq)))
            self.add_gates(multi_gate_seq)
            self.prev_gate_seq = multi_gate_seq
        else:
            self.add_gates(self.prev_gate_seq)
Пример #3
0
    def generate_sequence(self, config):
        """Generate sequence by adding gates/pulses to waveforms."""
        # get parameters
        sequence = config['Sequence']
        # Number of Cliffords to generate
        N_cliffords = int(config['Number of Cliffords'])
        randomize = config['Randomize']
        interleave = config['Interleave 1-QB Gate']
        multi_seq = config.get('Output multiple sequences', False)
        write_seq = config.get('Write sequence as txt file', False)

        log.info('Assign seed %d' % (randomize))
        rnd.seed(randomize)
        if interleave is True:
            interleaved_gate = config['Interleaved 1-QB Gate']
        else:
            interleaved_gate = np.inf
        # generate new randomized clifford gates only if configuration changes
        if (self.prev_sequence != sequence or self.prev_randomize != randomize
                or self.prev_N_cliffords != N_cliffords
                or self.prev_interleave != interleave or multi_seq
                or self.prev_interleaved_gate != interleaved_gate):

            self.prev_randomize = randomize
            self.prev_N_cliffords = N_cliffords
            self.prev_interleave = interleave
            self.prev_sequence = sequence

            multi_gate_seq = []
            for n in range(self.n_qubit):
                # Generate 1QB RB sequence
                single_gate_seq = []

                for i in range(N_cliffords):
                    rndnum = rnd.randint(0, 23)
                    log.info('Random number %d' % (rndnum))
                    add_singleQ_clifford(rndnum,
                                         single_gate_seq,
                                         pad_with_I=False)
                    # If interleave gate,
                    if interleave is True:
                        self.prev_interleaved_gate = interleaved_gate
                        single_gate_seq.append(
                            Gate.__getattr__(interleaved_gate))

                recovery_gate = self.get_recovery_gate(single_gate_seq)

                # print 1QB-RB sequence
                if write_seq == True:
                    import os
                    from datetime import datetime
                    directory = os.path.join(path_currentdir, '1QB_RBseq')
                    if not os.path.exists(directory):
                        os.makedirs(directory)
                    filename = datetime.now().strftime(
                        '%Y-%m-%d %H-%M-%S-f'
                    )[:-3] + '_qbNum=%d_N_cliffords=%d_seed=%d.txt' % (
                        n, N_cliffords, randomize)
                    filepath = os.path.join(directory, filename)
                    log.info('make file: ' + filepath)
                    with open(filepath, "w") as text_file:
                        print('New Sequence', file=text_file)
                        for i in range(len(single_gate_seq)):
                            print(
                                "CliffordIndex: %d, Gate: [" % (i) +
                                cliffords.Gate_to_strGate(single_gate_seq[i]) +
                                "]",
                                file=text_file)
                        print("Corresponding recovery sequence:")
                        print("Recovery Gate: [" +
                              cliffords.Gate_to_strGate(recovery_gate) + "]",
                              file=text_file)
                single_gate_seq.append(recovery_gate)
                multi_gate_seq.append(single_gate_seq)
            # transpose list of lists
            multi_gate_seq = list(
                map(list,
                    itertools.zip_longest(*multi_gate_seq,
                                          fillvalue=Gate.I)))  # Not to chop
            self.add_gates(multi_gate_seq)
            self.prev_gate_seq = multi_gate_seq
        else:
            self.add_gates(self.prev_gate_seq)