Ejemplo n.º 1
0
    def constraint_1(self):
        stresss_name = "sigmaEq"
        executor = Executor(self.execution_config, self.mesh_config,
                            self.fragmentation_config)
        executor.run()
        results = executor.get_results()
        print("==== stress constraint_1")

        self.__debug_message(results)
        return results[stresss_name] - self.k_max_stress
Ejemplo n.º 2
0
    def constraint_0(self):
        deformation_name = "D"
        # FIXME execution for reproduced constrain. Need to use hash if possible
        executor = Executor(self.execution_config, self.mesh_config,
                            self.fragmentation_config)
        executor.run()
        results = executor.get_results()
        print("==== D constraint_0")
        self.__debug_message(results)

        return results[deformation_name] - self.k_max_deformation
Ejemplo n.º 3
0
 def constraint_1(self):
     stresss_name = "D"
     executor = Executor(self.execution_config, self.mesh_config,
                         self.fragmentation_config)
     executor.run()
     results = executor.get_results()
     print("==== stress constraint_1")
     print(results)
     print(results[stresss_name])
     print(results[stresss_name] < self.k_max_stress)
     print(results[stresss_name] - self.k_max_stress)
     return results[stresss_name] - self.k_max_stress
 def __init__(self, executor_options, debug=False):
     """
     Init file based Executor.
     Args:
         executor_options: dictionary, for configuration usage.
         debug: boolean, whether enable debug mode.
     """
     Executor.__init__(self, executor_options, debug)
     # File path for proving key and contract code.
     self.__proving_key_path = executor_options['proving_key_path']
     self.__abi_path = executor_options['abi_path']
     self.__code_path = executor_options['code_path']
     self.__working_folder_path = executor_options['working_path']
     self.__zokrates_path = executor_options['zokrates_path']
     self.__chain_config = executor_options['chain_config']
Ejemplo n.º 5
0
class TradeWorker(object):
    def __init__(self):
        # This block initializes the lists, that you need to trade.
        self.all_item_classes = set()
        self.in_buy_item_classes = set()
        self.in_sell_item_classes = set()
        self.in_freeze_item_classes = set()
        self.in_check_item_classes = set()

        self.controller = TradeWorkerController(self)
        self.executor = Executor()
        self.searcher = Searcher()

        # Initializes controller, executor and checker_items_prices threads.
        self.checker_price_thread = threading.Thread(target=self.searcher.start,
                                                     name='SearcherThread',
                                                     kwargs={'output_queue': self.controller.get_input_queue()})
        self.executor_thread = threading.Thread(target=self.executor.start,
                                                name='ExecutorThread',
                                                kwargs={'output_queue': self.controller.get_input_queue()})
        self.trade_worker_controller_thread = threading.Thread(target=self.controller.start_routing,
                                                               name='TradeWorkerControllerThread')

        self.__start()

    def __start(self):
        self.__load_start_data()
        self.__start_threads()
        self.__start_main_event_loop()

    def __load_start_data(self):
        # This is temporary block. It's necessary before checker and executor was finale finished.
        self.all_item_classes = set(ItemClass.get_default_itemclass_list()[:200])
        self.in_buy_item_classes = set(list(self.all_item_classes)[5:50])
        self.in_sell_item_classes = set(list(self.all_item_classes)[51:100])
        self.refresh_in_check_item_classes()

        self.controller.set_output_queue_searcher(self.searcher.get_input_queue())
        self.controller.set_output_queue_executor(self.executor.get_input_queue())

    def __start_threads(self):
        # Start threads.
        self.trade_worker_controller_thread.start()
        # self.checker_price_thread.start()
        self.executor_thread.start()

    def __start_main_event_loop(self):
        while True:
            print 'Generate new loop!'
            # self.search_trade_value_item_classes()
            self.controller.output_queue_executor.put(1)
            time.sleep(10)

    def search_trade_value_item_classes(self):
        for item_class in self.in_check_item_classes:
            task = CheckProfitTradeTask(item_class)
            self.controller.get_output_queue_searcher().put(task)

    def refresh_in_check_item_classes(self):
        self.in_check_item_classes = self.all_item_classes - self.in_buy_item_classes - self.in_sell_item_classes
 def _load_executor(self, cpt_dir):
     """
     Load executor from checkpoint
     """
     with open(cpt_dir / "train.yaml", "r") as f:
         conf = yaml.load(f, Loader=yaml.FullLoader)
     nnet_type = conf["nnet_type"]
     if nnet_type not in supported_nnet:
         raise RuntimeError(f"Unknown network type: {nnet_type}")
     nnet = supported_nnet[nnet_type](**conf["nnet_conf"])
     executor = Executor(nnet, extractor_kwargs=conf["extractor_conf"], get_mask=self.get_mask)
     return executor
Ejemplo n.º 7
0
def run(root_collection,
        config,
        include_collections=False,
        overwrite=False,
        num_workers=4,
        catalogue_file='catalogue.txt',
        progress_file='progress.txt',
        resume=False,
        refresh=False):
    irods_session = irods_wrapper.create_session()
    executor = Executor(irods_session, num_workers)
    catalogue = irods_wrapper.get_irods_catalogue(root_collection)
    if not resume:

        # with open(catalogue_file, 'w') as cf:
        #     json.dump(catalogue, cf)
        with open(progress_file, 'w') as pf:
            for plan in planner.generate_plans(catalogue, config,
                                               progress_file, resume,
                                               include_collections):
                executor.execute_plan(plan, overwrite, refresh)
                pf.write(plan.path + "\n")
    else:
        # with open(catalogue_file, 'r') as cf:
        #     catalogue = json.load(cf)
        with open(progress_file, 'a') as pf:
            for plan in planner.generate_plans(catalogue, config,
                                               progress_file, resume,
                                               include_collections):
                executor.execute_plan(plan, overwrite, refresh)
                pf.write(plan.path + "\n")
Ejemplo n.º 8
0
    def __init__(self):
        # This block initializes the lists, that you need to trade.
        self.all_item_classes = set()
        self.in_buy_item_classes = set()
        self.in_sell_item_classes = set()
        self.in_freeze_item_classes = set()
        self.in_check_item_classes = set()

        self.controller = TradeWorkerController(self)
        self.executor = Executor()
        self.searcher = Searcher()

        # Initializes controller, executor and checker_items_prices threads.
        self.checker_price_thread = threading.Thread(target=self.searcher.start,
                                                     name='SearcherThread',
                                                     kwargs={'output_queue': self.controller.get_input_queue()})
        self.executor_thread = threading.Thread(target=self.executor.start,
                                                name='ExecutorThread',
                                                kwargs={'output_queue': self.controller.get_input_queue()})
        self.trade_worker_controller_thread = threading.Thread(target=self.controller.start_routing,
                                                               name='TradeWorkerControllerThread')

        self.__start()
Ejemplo n.º 9
0
def epsilon_greedy_strategy(device,
                            package,
                            step,
                            episode,
                            epsilon=epsilon_default,
                            recorda_input_path=None,
                            recorda_output_path=None):
    start_time = datetime.datetime.now()
    if recorda_input_path and recorda_output_path:
        dp = DataProcessor(recorda_output_path)
        with open(recorda_input_path, 'r') as data_file:
            events = json.load(data_file)
        dp.process_all_events(events)
        agent = Agent(alpha, gamma, recorda_path=recorda_output_path)
    else:
        agent = Agent(alpha, gamma)
    observer = GuiObserver(device)
    executor = Executor(device)
    for j in tqdm(range(episode)):
        logger.info("------------Episode {}---------------".format(j))
        for i in tqdm(range(step)):
            # start = datetime.datetime.now()
            if not (observer.activity and observer.actionable_events):
                observer.dump_gui(package)

            # if is_launcher(observer.activity) or 'Application Error' in observer.activity:
            #     back_to_app()
            #     observer.reset()
            #     continue
            # elif is_out_of_app(observer.activity):
            #     executor.perform_back()
            #     continue
            # else:
            if agent.next_state:
                agent.current_state = agent.next_state
            else:
                print("No next state")
                agent.set_current_state(observer.activity,
                                        observer.actionable_events)
            # print("Step 1: {}".format(datetime.datetime.now() - start))

            if len(agent.get_available_action()) > 0:
                r = random.uniform(0.0, 1.0)
                if r < epsilon:
                    agent.current_action = random.choice(
                        agent.get_available_action().keys())
                    logger.info('Select randomly')
                else:
                    max_q_key = max(agent.current_state.q_value.iteritems(),
                                    key=operator.itemgetter(1))[0]
                    if agent.current_state.q_value[max_q_key] != 0:
                        hash_action = max_q_key.split("||")[1]
                        agent.current_action = hash_action
                    logger.info(
                        "Select action with highest q value = {}".format(
                            agent.current_state.q_value[max_q_key]))
            # print("Step 2: {}".format(datetime.datetime.now() - start))
            if not agent.current_action or agent.current_action == 'None':
                x = randint(0, 540)
                y = randint(0, 540)
                executor.perform_random_click(x, y)
            else:
                executor.perform_action(agent.actions[agent.current_action][1])
            # print("Step 3: {}".format(datetime.datetime.now() - start))
            time.sleep(0.2)
            observer.dump_gui(package)
            # print("Step 4: {}".format(datetime.datetime.now() - start))
            if not (is_launcher(observer.activity)
                    or is_out_of_app(observer.activity)
                    or 'Application Error' in observer.activity):
                agent.set_next_state(observer.activity,
                                     observer.actionable_events)
                agent.add_reward(agent.current_state, agent.next_state)
                agent.add_reward_unvisited_action()
                agent.update_q()
            else:
                back_to_app()
                observer.reset()
                continue
            agent.reset()
            # print("Step 5: {}".format(datetime.datetime.now() - start))
        """ 
        End of and episode, start from a random state from the list of states that have been explored
        """
        for i in range(len(agent.states)):
            random_state = agent.get_random_state()
            output = jump_to_activity(random_state.activity)
            if 'Error' not in output:
                break
    """ LOGGING """
    logger.info("#############STATE###########")
    for s in agent.states.values():
        logger.info(str(s))
    logger.info("#############Q value##########")
    logger.info(agent.q_value)

    logger.info("End of process. Time: {}".format(datetime.datetime.now() -
                                                  start_time))
Ejemplo n.º 10
0
    # FIXME Hardcoded
    script_dir = os.path.dirname(os.path.abspath(__file__))
    rail_pos = script_dir.rfind("Beam")
    foam_pos = script_dir.rfind("OpenFOAM-wrapper")
    if rail_pos == -1 or foam_pos == -1:
        raise Exception("Failed to find Beam folder in path")
    else:
        execution_conf.execution_folder = script_dir[:foam_pos]

    print("[!!!!] WARNING: prepare script and openfoam folder is hardcoded")
    execution_conf.prepare_env_script = "/home/lenferd/prog/OpenFOAM/OpenFOAM-dev/etc/bashrc_modified"
    execution_conf.openfoam_folder = "/home/lenferd/prog/OpenFOAM/"

    # TODO No fragmentation iters for now
    for width in range(args.geom_width_start, args.geom_width_end + 1,
                       args.geom_width_diff):
        for height in range(args.geom_height_start, args.geom_height_end + 1,
                            args.geom_height_diff):
            for length in range(args.geom_length_start,
                                args.geom_length_end + 1,
                                args.geom_length_diff):
                mesh_conf = SimpleBlockMeshConfig(width, height, length)
                mesh = SimpleBlockMeshGenerator(mesh_conf, fragmentation_conf,
                                                execution_conf)
                mesh.create()
                mesh.generate()
                executor = Executor(execution_conf, mesh_conf,
                                    fragmentation_conf)
                executor.run()