def parallel_collect_trajectories(args, params, egoids, starts, n_proc, env_fn=build_env.build_ngsim_env, max_steps=200, use_hgail=False, random_seed=None, lbd=0.99, adapt_steps=1): # build manager and dictionary mapping ego ids to list of trajectories tf_policy = False parallel = False # set policy function policy_fn = validate_utils.build_policy if tf_policy else algorithms.utils.build_policy # partition egoids proc_egoids = utils.partition_list(egoids, n_proc) if parallel: manager = mp.Manager() error_dict = manager.list() # pool of processes, each with a set of ego ids pool = mp.Pool(processes=n_proc) # print(('Creating parallel env Running time: %s Seconds' % (end_time - start_time))) # run collection results = [] for pid in range(n_proc): res = pool.apply_async(collect_trajectories, args=(args, params, proc_egoids[pid], starts, error_dict, pid, env_fn, policy_fn, max_steps, use_hgail, random_seed, lbd, adapt_steps)) results.append(res) [res.get() for res in results] pool.close() else: error_dict = [] error_dict = collect_trajectories(args, params, proc_egoids[0], starts, error_dict, 0, env_fn, policy_fn, max_steps, use_hgail, random_seed, lbd, adapt_steps) # wait for the processes to finish print("Vehicle Counter: {}".format(Veh_counter)) # let the julia processes finish up time.sleep(10) return error_dict[0]
def parallel_collect_trajectories( args, params, egoids, starts, n_proc, env_fn=utils.build_ngsim_env, max_steps=200, use_hgail=False, random_seed=None): # build manager and dictionary mapping ego ids to list of trajectories manager = mp.Manager() trajlist = manager.list() # set policy function policy_fn = utils.build_hierarchy if use_hgail else utils.build_policy # partition egoids proc_egoids = utils.partition_list(egoids, n_proc) # pool of processes, each with a set of ego ids pool = mp.Pool(processes=n_proc) # run collection results = [] for pid in range(n_proc): res = pool.apply_async( collect_trajectories, args=( args, params, proc_egoids[pid], starts, trajlist, pid, env_fn, policy_fn, max_steps, use_hgail, random_seed ) ) results.append(res) # wait for the processes to finish [res.get() for res in results] pool.close() # let the julia processes finish up time.sleep(20) return trajlist