Ejemplo n.º 1
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 2,
                     (globals.CANVAS_DIMS[1] / 9) * 3)),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 6,
                     (globals.CANVAS_DIMS[1] / 9) * 4)),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5,
                     (globals.CANVAS_DIMS[1] / 9) * 7)),
         SuperMeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 8,
                          (globals.CANVAS_DIMS[1] / 9) * 1))
     ]
     self.RangedEnemies = [
         RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 2,
                      (globals.CANVAS_DIMS[1] / 9) * 8)),
         RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 6,
                      (globals.CANVAS_DIMS[1] / 9) * 1))
     ]
     self.Rocks = [
         Rock(((globals.CANVAS_DIMS[0] / 7) * 2,
               (globals.CANVAS_DIMS[1] / 3) * 1)),
         Rock(((globals.CANVAS_DIMS[0] / 5) * 4,
               (globals.CANVAS_DIMS[1] / 5) * 3)),
         Rock(((globals.CANVAS_DIMS[0] / 7) * 3,
               (globals.CANVAS_DIMS[1] / 3) * 2))
     ]
     self.Gates = [Gate(3, 2, 1), Gate(0, 2, 3), Gate(1, 2, 4)]
     self.Room = Room()
Ejemplo n.º 2
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 2,
                     (globals.CANVAS_DIMS[1] / 9) * 4)),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 7,
                     (globals.CANVAS_DIMS[1] / 9))),
         MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5,
                     (globals.CANVAS_DIMS[1] / 9) * 4))
     ]
     self.RangedEnemies = [
         RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 5,
                      (globals.CANVAS_DIMS[1] / 9) * 3))
     ]
     self.Rocks = [
         Rock(((globals.CANVAS_DIMS[0] / 3) * 2,
               (globals.CANVAS_DIMS[1] / 2))),
         Rock(((globals.CANVAS_DIMS[0] / 9) * 7,
               (globals.CANVAS_DIMS[1] / 5) * 2)),
         Rock(((globals.CANVAS_DIMS[0] / 7) * 2,
               (globals.CANVAS_DIMS[1] / 6) * 5)),
         Rock(((globals.CANVAS_DIMS[0] / 5) * 3,
               (globals.CANVAS_DIMS[1] / 9) * 2))
     ]
     self.Gates = [Gate(2, 1, 0), Gate(1, 1, 2)]
     self.Room = Room()
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5, (globals.CANVAS_DIMS[1] / 9) * 2)),
                          MeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 8, (globals.CANVAS_DIMS[1] / 9) * 7))]
     self.RangedEnemies = []
     self.Rocks = [Rock(((globals.CANVAS_DIMS[0] / 6) * 2, (globals.CANVAS_DIMS[1] / 8) * 3)),
                   Rock(((globals.CANVAS_DIMS[0] / 9) * 7, (globals.CANVAS_DIMS[1] / 5) * 4))]
     self.Gates = [Gate(0, 0, 1)]
     self.Room = Room()
Ejemplo n.º 5
0
 def __init__(self):
     Levels.levels.append(self)
     self.MeleeEnemies = [SuperMeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 3, (globals.CANVAS_DIMS[1] / 9) * 6)),
                          SuperMeleeEnemy(((globals.CANVAS_DIMS[0] / 9) * 5, (globals.CANVAS_DIMS[1] / 9) * 1))]
     self.RangedEnemies = [RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 2, (globals.CANVAS_DIMS[1] / 9) * 3)),
                           RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 7, (globals.CANVAS_DIMS[1] / 9))),
                           RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 4, (globals.CANVAS_DIMS[1] / 9) * 8)),
                           RangedEnemy(((globals.CANVAS_DIMS[0] / 9) * 8, (globals.CANVAS_DIMS[1] / 9) * 5))]
     self.Rocks = [Rock(((globals.CANVAS_DIMS[0] / 6) * 1, (globals.CANVAS_DIMS[1] / 8) * 6)),
                   Rock(((globals.CANVAS_DIMS[0] / 9) * 4, (globals.CANVAS_DIMS[1] / 8) * 5))]
     self.Gates = [Gate(3, 4, 2)]
     self.Room = Room()
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def add_gate(self, gate: gates.Gate):
     gate.set_circuit_n_qubits(self.n_qubits)
     self.gates.append(gate)
Ejemplo n.º 8
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)