Exemplo n.º 1
0
    def simulation(self, sweep_dict: Dict[str, List[Any]],
                   states_list: List[Dict[str, Any]],
                   configs: List[Tuple[List[Callable], List[Callable]]],
                   env_processes: Dict[str, Callable], time_seq: range,
                   runs: int) -> List[List[Dict[str, Any]]]:
        def execute_run(sweep_dict, states_list, configs, env_processes,
                        time_seq, run) -> List[Dict[str, Any]]:
            run += 1

            def generate_init_sys_metrics(genesis_states_list):
                for d in genesis_states_list:
                    d['run'], d['substep'], d['timestep'] = run, 0, 0
                    yield d

            states_list_copy: List[Dict[str, Any]] = list(
                generate_init_sys_metrics(deepcopy(states_list)))

            first_timestep_per_run: List[Dict[str, Any]] = self.run_pipeline(
                sweep_dict, states_list_copy, configs, env_processes, time_seq,
                run)
            del states_list_copy

            return first_timestep_per_run

        tp = TPool(runs)
        pipe_run: List[List[Dict[str, Any]]] = flatten(
            tp.map(
                lambda run: execute_run(sweep_dict, states_list, configs,
                                        env_processes, time_seq, run),
                list(range(runs))))

        tp.clear()
        return pipe_run
Exemplo n.º 2
0

if __name__ == '__main__':
    from pathos.pools import ThreadPool as TPool
    tpool = TPool()

    print("Evaluate 10 items on 1 thread")
    tpool.nthreads = 1
    res3 = tpool.map(host, range(10))
    print(tpool)
    print('\n'.join(res3))
    print('')

    print("Evaluate 10 items on 2 threads")
    tpool.nthreads = 2
    res5 = tpool.map(host, range(10))
    print(tpool)
    print('\n'.join(res5))
    print('')

    print("Evaluate 10 items on ? threads")
    tpool.nthreads = None
    res9 = tpool.map(host, range(10))
    print(tpool)
    print('\n'.join(res9))
    print('')

    tpool.clear()

# end of file