Example #1
0
def main():
    parser = GooeyParser(description='Create_concrete_experiment')
    parser.add_argument('Experiment_file_name',
                        widget='FileChooser',
                        help='Choose experiment file with general info')
    parser.add_argument('Participant_ID', type=str)
    parser.add_argument('Participant_Age', default=0, type=int)
    parser.add_argument('Participant_Sex', default='M', choices=['M', 'F'])
    parser.add_argument('Random',
                        default='True',
                        choices=['True', 'False'],
                        help="Present trials in random order")
    parser.add_argument('EEG_connected',
                        default='0',
                        choices=['1', '0'],
                        help='Choice')
    parser.add_argument('NIRS_connected',
                        default='0',
                        choices=['1', '0'],
                        help='Choice')

    args = parser.parse_args()

    number_of_blocks, data = load_info(args.Experiment_file_name)

    experiment = Experiment([], args.Participant_ID, args.Participant_Sex,
                            args.Participant_Age, int(args.EEG_connected),
                            int(args.NIRS_connected))

    for idx in range(number_of_blocks):
        block = Block([])
        experiment.list_of_blocks.append(block)

    for idx in range(len(data)):
        trial_info = data[idx]
        block_number = trial_info['BLOCK_NUMBER']
        if trial_info['SAMPLE_TYPE'] == 'instruction':
            if trial_info['INSTRUCTION'][-3:] == 'txt':
                instruction_type = 'text'
            elif trial_info['INSTRUCTION'][-3:] == 'bmp' or trial_info[
                    'INSTRUCTION'][-3:] == 'jpg':
                instruction_type = 'image'
            else:
                raise AssertionError("wrong instruction file type")
            trial = Instruction(trial_info['INSTRUCTION'], instruction_type,
                                trial_info['STIMTIME'])
        else:
            trial = Trial(trial_info['SAMPLE_TYPE'], trial_info['N'],
                          trial_info['NR'], trial_info['STIMTIME'],
                          trial_info['RESPTIME'], trial_info['FEEDB'],
                          trial_info['FEEDB_TIME'], trial_info['WAIT'],
                          trial_info['EXP'], trial_info['BIN'],
                          trial_info['TRAIL_TYPE'])
            trial.create_sample()
        experiment.list_of_blocks[block_number -
                                  1].list_of_trials.append(trial)

    if args.Random:
        experiment.randomize()
    experiment.save()
Example #2
0
 def execute_program(self):
     while self.__iterator < len(self.lines):
         self.__iterator_changed = False
         row = Instruction(self)
         row = self.lines[self.__iterator]
         row.execute_instruction()
         if not self.__iterator_changed:
             self.__iterator = self.__iterator + 1
def main():
    parser = GooeyParser(description="Create_concrete_experiment")
    parser.add_argument("Experiment_file_name", widget="FileChooser", help="Choose experiment file with general info")
    parser.add_argument("Participant_ID", type=str)
    parser.add_argument("Participant_Age", default=0, type=int)
    parser.add_argument("Participant_Sex", default="M", choices=["M", "F"])
    parser.add_argument("Random", default="True", choices=["True", "False"], help="Present trials in random order")
    parser.add_argument("EEG_connected", default="1", choices=["1", "0"], help="Choice")

    args = parser.parse_args()

    number_of_blocks, data = load_info(args.Experiment_file_name)

    experiment = Experiment(
        [], args.Participant_ID, args.Participant_Sex, args.Participant_Age, int(args.EEG_connected)
    )

    for idx in range(number_of_blocks):
        block = Block([])
        experiment.list_of_blocks.append(block)

    for idx in range(len(data)):
        trial_info = data[idx]
        block_number = trial_info["BLOCK_NUMBER"]
        if trial_info["SAMPLE_TYPE"] == "instruction":
            if trial_info["INSTRUCTION"][-3:] == "txt":
                instruction_type = "text"
            elif trial_info["INSTRUCTION"][-3:] == "bmp" or trial_info["INSTRUCTION"][-3:] == "jpg":
                instruction_type = "image"
            else:
                raise AssertionError("wrong instruction file type")
            trial = Instruction(trial_info["INSTRUCTION"], instruction_type, trial_info["SHOW_TIME"])
        else:
            trial = Trial(
                trial_info["SAMPLE_TYPE"],
                trial_info["N"],
                trial_info["NR"],
                trial_info["MEMORY"],
                trial_info["INTEGR"],
                trial_info["SHOW_TIME"],
                trial_info["RESP_TIME"],
                trial_info["MAX_TIME"],
                trial_info["FEEDB"],
                trial_info["FEEDB_TIME"],
                trial_info["WAIT"],
                trial_info["EXP"],
                trial_info["FIX_TIME"],
                trial_info["LIST_VIEW"],
            )
            trial.create_sample()
        experiment.list_of_blocks[block_number - 1].list_of_trials.append(trial)

    if args.Random:
        experiment.randomize()
    experiment.save()
Example #4
0
 def insert_instruction(self, address, instruction):
     """
     This inserts instructions into the memory dictionary.
     :param instruction: list containing parts of the instruction.
     """
     byte_instruction = Instruction(instruction).parse()
     self.memory[address] = byte_instruction[0]
     self.memory[address+1] = byte_instruction[1]
     self.memory[address+2] = byte_instruction[2]
     self.memory[address+3] = byte_instruction[3]
Example #5
0
def main():
    parser = GooeyParser(description='Create_concrete_experiment')
    parser.add_argument('Experiment_file_name', widget='FileChooser', help='Choose experiment file with general info')
    parser.add_argument('Participant_ID', type=str)
    parser.add_argument('Participant_Age', default=0, type=int)
    parser.add_argument('Participant_Sex', default='M', choices=['M', 'F'])
    parser.add_argument('Random', default='True', choices=['True', 'False'], help="Present trials in random order")
    parser.add_argument('EEG_connected', default='0', choices=['1', '0'], help='Choice')
    parser.add_argument('NIRS_connected', default='0', choices=['1', '0'], help='Choice')

    args = parser.parse_args()

    number_of_blocks, data = load_info(args.Experiment_file_name)

    experiment = Experiment([], args.Participant_ID, args.Participant_Sex, args.Participant_Age,
                            int(args.EEG_connected), int(args.NIRS_connected))

    for idx in range(number_of_blocks):
        block = Block([])
        experiment.list_of_blocks.append(block)

    for idx in range(len(data)):
        trial_info = data[idx]
        block_number = trial_info['BLOCK_NUMBER']
        if trial_info['SAMPLE_TYPE'] == 'instruction':
            if trial_info['INSTRUCTION'][-3:] == 'txt':
                instruction_type = 'text'
            elif trial_info['INSTRUCTION'][-3:] == 'bmp' or trial_info['INSTRUCTION'][-3:] == 'jpg':
                instruction_type = 'image'
            else:
                raise AssertionError("wrong instruction file type")
            trial = Instruction(trial_info['INSTRUCTION'], instruction_type, trial_info['STIMTIME'])
        else:
            trial = Trial(trial_info['SAMPLE_TYPE'], trial_info['N'], trial_info['NR'], trial_info['STIMTIME'],
                          trial_info['RESPTIME'], trial_info['FEEDB'], trial_info['FEEDB_TIME'], trial_info['WAIT'],
                          trial_info['EXP'], trial_info['BIN'], trial_info['TRAIL_TYPE'])
            trial.create_sample()
        experiment.list_of_blocks[block_number - 1].list_of_trials.append(trial)

    if args.Random:
        experiment.randomize()
    experiment.save()
Example #6
0
 def decode(self, fetch_object):
     """
     This function decodes the raw instruction into a Instruction object.
     :param raw_instruction: binary string of MIPS instruction.
     :return: Instruction object.
     """
     instructions = []
     for instruction in fetch_object:
         if instruction is not None:
             decoded_instruction = Instruction(instruction)
             instructions.append(decoded_instruction)
             key = self.reorder_buffer.insert_entry(decoded_instruction)
             decoded_instruction.rob_entry = key
             operands = self._get_operands(decoded_instruction)
             decoded_instruction.operands = operands
             self._writeback_analysis(decoded_instruction, key)
             self.reservation_station.add_instruction(decoded_instruction)
         else:
             instructions.append(None)
     return instructions
Example #7
0
 def load_file_to_lines(self, name):
     with open(name) as f:
         lines_1 = f.readlines()
         for line in lines_1:
             line = [x.strip() for x in line.split(',')]
             instruction = Instruction(self)
             if len(line) == 4:
                 instruction.command = line[0]
                 instruction.parameter1 = line[1]
                 instruction.parameter2 = line[2]
                 instruction.parameter3 = line[3]
                 self.lines.append(instruction)
             elif len(line) == 3:
                 instruction.command = line[0]
                 instruction.parameter1 = line[1]
                 instruction.parameter2 = line[2]
                 self.lines.append(instruction)
             elif len(line) == 2:
                 instruction.parameter1 = line[1]
                 instruction.command = line[0]
                 self.lines.append(instruction)
             elif len(line) == 1:
                 instruction.command = line[0]
                 self.lines.append(instruction)
             else:
                 sys.exit("Bad format of instruction")
Example #8
0
 def print_state(self, written_to):
     """
     This function prints the current state of the simulator to the terminal
     :param written_to: List of registers written to in this cycle.
     """
     self.stdscr.addstr(3, 10,
                        "Program Counter: "
                        + str(self.pc),
                        curses.color_pair(2))
     self.stdscr.addstr(4, 10,
                        "Clock Cycles Taken: "
                        + str(self.clock),
                        curses.color_pair(3))
     self.stdscr.addstr(5, 10,
                        "Instructions Per Cycle: "
                        + str(round(self.instructions_executed/self.clock, 2)),
                        curses.color_pair(3))
     self.stdscr.addstr(5, 40,
                        "Instructions Executed: "
                        + str(self.instructions_executed),
                        curses.color_pair(3))
     for i in range(34):
         offset = 100
         if i >= 20:
             offset += 25
         color = 4
         if i in written_to:
             color = 1
         if self.register_file.reg[i]["valid"]:
             valid = "\u2713"
         else:
             valid = "\u002E"
         self.stdscr.addstr(i % 20 + 2, offset,
                            str(self.register_file.reg[i]["name"]) + " v: " +
                            valid + " " +
                            str(self.register_file.reg[i]["value"])[:6] + " rob: " +
                            str(self.register_file.reg[i]["rob_entry"]).ljust(16),
                            curses.color_pair(color))
     for i in range(N):
         try:
             self.stdscr.addstr(14 + i, 10,
                                "Pipeline Fetch:     "
                                + str(Instruction(self.raw_instructions[i]).description().ljust(64)),
                                curses.color_pair(4))
         except:
             self.stdscr.addstr(14 + i, 10,
                                "Pipeline Fetch:     Empty".ljust(72),
                                curses.color_pair(4))
         try:
             self.stdscr.addstr(14 + N + i + 1, 10,
                                "Pipeline Decode:    "
                                + str(Instruction(self.prev_raw_instructions[i]).description().ljust(64)),
                                curses.color_pair(1))
         except:
             self.stdscr.addstr(14 + N + i + 1, 10,
                                "Pipeline Decode:    Empty".ljust(72),
                                curses.color_pair(1))
         try:
             self.stdscr.addstr(18 + 2*N + i + 3, 10,
                                "Pipeline Writeback: "
                                + str(self.now_writing[i].description().ljust(64)),
                                curses.color_pair(5))
         except:
             self.stdscr.addstr(18 + 2*N + i + 3, 10,
                                "Pipeline Writeback: Empty".ljust(72),
                                curses.color_pair(5))
     for i in range(4):
         try:
             self.stdscr.addstr(14 + 2*N + i + 2, 10,
                                "Pipeline Execute:   "
                                + str(self.now_executing[i].description().ljust(64)),
                                curses.color_pair(6))
         except:
             self.stdscr.addstr(14 + 2*N + i + 2, 10,
                                "Pipeline Execute:   Empty".ljust(72),
                                curses.color_pair(6))
     self.reservation_station.print(self.stdscr)
     self.branch_predictor.print(self.stdscr)
     self.reorder_buffer.print(self.stdscr)
     self.stdscr.refresh()
     if not self.intercept:
         time.sleep(instruction_time)
     if self.intercept and self.stdscr.getch() == 32:
         self.intercept = False
         self.stdscr.addstr(51, 0, "".ljust(92))
Example #9
0
    def __think(self, feed):
        # perform sell strategies check
        # the holding list need a deep copy as it might be changed by Hugo
        holdingList = copy.deepcopy(
            self.portfolio.getOpenedHoldingListByTicker(feed.ticker))
        for holding in holdingList:
            instruction = Instruction()
            instruction.ticker = feed.ticker
            instruction.timestamp = feed.timestamp
            instruction.price = feed.price
            instruction.quantity = holding['Quantity']
            instruction.action = 'Hold'
            instruction.reason = ''
            instruction.holding_id = holding['Holding_id']

            instruction = str_sell_kdj(feed, holding, instruction)
            self.__broadcastFeed(instruction)

        # perform buy strategies check
        # we have enough cash to buy
        if self.portfolio.hasEnoughCashToInvest() and (
                not self.portfolio.hasReachedMaxNumHoldingsPerStock(
                    feed.ticker)):
            instruction = Instruction()
            instruction.ticker = feed.ticker
            instruction.timestamp = feed.timestamp
            instruction.price = feed.price
            instruction.action = 'Hold'
            instruction.reason = ''

            instruction = str_buy_kdj(feed, instruction)
            self.__broadcastFeed(instruction)