def test_multiagent_ngsim_env(self): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filename = 'trajdata_i101_trajectories-0750am-0805am.txt' filepaths = [os.path.join(basedir, filename)] n_veh = 5 env = JuliaEnv(env_id='MultiagentNGSIMEnv', env_params=dict(n_veh=n_veh, trajectory_filepaths=filepaths, H=200, primesteps=50), using='AutoEnvs') low, high = env.action_space.low, env.action_space.high env = TfEnv(env) policy = GaussianMLPPolicy(name="policy", env_spec=env.spec, hidden_sizes=(32, 32), std_hidden_sizes=(32, 32), adaptive_std=True, output_nonlinearity=None, learn_std=True) baseline = ZeroBaseline(env_spec=env.spec) algo = TRPO(env=env, policy=policy, baseline=baseline, n_itr=1, batch_size=1000, sampler_args=dict(n_envs=n_veh)) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) try: algo.train(sess=sess) except Exception as e: self.fail('exception incorrectly raised: {}'.format(e))
def build_ngsim_env( args, exp_dir='/tmp', alpha=0.001, vectorize=False, render_params=None, videoMaking=False): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filepaths = [os.path.join(basedir, args.ngsim_filename)] if render_params is None: render_params = dict( viz_dir=os.path.join(exp_dir, 'imitate/viz'), zoom=5. ) env_params = dict( trajectory_filepaths=filepaths, H=args.env_H, primesteps=args.env_primesteps, action_repeat=args.env_action_repeat, terminate_on_collision=False, terminate_on_off_road=False, render_params=render_params, n_envs=args.n_envs, n_veh=args.n_envs, remove_ngsim_veh=args.remove_ngsim_veh, reward=args.env_reward ) # order matters here because multiagent is a subset of vectorized # i.e., if you want to run with multiagent = true, then vectorize must # also be true if args.env_multiagent: env_id = 'MultiagentNGSIMEnv' if videoMaking: print('RAUNAK BHATTACHARRYA VIDEO MAKER IS ON') env_id='MultiagentNGSIMEnvVideoMaker' alpha = alpha * args.n_envs normalize_wrapper = vectorized_normalized_env elif vectorize: env_id = 'VectorizedNGSIMEnv' alpha = alpha * args.n_envs normalize_wrapper = vectorized_normalized_env else: env_id = 'NGSIMEnv' normalize_wrapper = normalize_env env = JuliaEnv( env_id=env_id, env_params=env_params, using='AutoEnvs' ) # get low and high values for normalizing _real_ actions low, high = env.action_space.low, env.action_space.high env = TfEnv(normalize_wrapper(env, normalize_obs=True, obs_alpha=alpha)) add_kwargs_to_reset(env) return env, low, high
def test_julia_env(self): env = JuliaEnv(env_id='DeterministicSingleStepDebugEnv', env_params={}, using='AutoEnvs') x = env.reset() nx, r, t, info = env.step(1) self.assertEqual(x, 0) self.assertEqual(nx, 0) self.assertEqual(r, 1) self.assertEqual(t, True)
def build_ngsim_env(args, exp_dir='/tmp', alpha=0.001, vectorize=False, render_params=None): basedir = os.path.expanduser('~/.julia/v0.6/NGSIM/data') filepaths = [os.path.join(basedir, args.ngsim_filename)] if render_params is None: render_params = dict(viz_dir=os.path.join(exp_dir, 'imitate/viz'), zoom=5.) env_params = dict(trajectory_filepaths=filepaths, H=args.env_H, primesteps=args.env_primesteps, action_repeat=args.env_action_repeat, terminate_on_collision=False, terminate_on_off_road=False, render_params=render_params, n_envs=args.n_envs, n_veh=args.n_envs) # order matters here because multiagent is a subset of vectorized # i.e., if you want to run with multiagent = true, then vectorize must # also be true normalize_kwargs = dict(normalize_obs=True, obs_alpha=alpha) if not args.adaptive_normalization: # only apply clipping when running without adaptive normalization normalize_kwargs[ 'clip_std_multiple'] = args.normalize_clip_std_multiple if args.env_multiagent: env_id = 'MultiagentNGSIMEnv' alpha = alpha * args.n_envs normalize_wrapper = vectorized_normalized_env elif vectorize: env_id = 'VectorizedNGSIMEnv' alpha = alpha * args.n_envs normalize_wrapper = vectorized_normalized_env else: env_id = 'NGSIMEnv' normalize_wrapper = normalize_env if not args.adaptive_normalization: raise NotImplementedError( '''non vectorized env not implemented for use without adaptive normalization''') env = JuliaEnv(env_id=env_id, env_params=env_params, using='AutoEnvs') # get low and high values for normalizing _real_ actions low, high = env.action_space.low, env.action_space.high env = TfEnv(normalize_wrapper(env, **normalize_kwargs)) add_kwargs_to_reset(env) return env, low, high
def perf_ngsim_env_step(): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filename = 'trajdata_i101_trajectories-0750am-0805am.txt' filepaths = [os.path.join(basedir, filename)] env = JuliaEnv(env_id='NGSIMEnv', env_params=dict(trajectory_filepaths=filepaths, ), using='AutoEnvs') n_steps = 10000 action = np.array([1., 0.]) env.reset() with ContextTimer(): for _ in range(n_steps): _, _, terminal, _ = env.step(action) if terminal: env.reset()
def test_ngsim_env(self): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filename = 'trajdata_i80_trajectories-0400-0415.txt' filepaths = [os.path.join(basedir, filename)] env = JuliaEnv(env_id='NGSIMEnv', env_params=dict(trajectory_filepaths=filepaths), using='AutoEnvs') x = env.reset() nx, r, t, info = env.step(np.array([0., 0.])) self.assertTrue(np.sum(np.abs(x - nx)) > 1e-1) # complex reset x = env.reset(offset=250, egoid=3194, start=8886) nx = env.reset(offset=250, egoid=3194, start=8886) np.testing.assert_array_almost_equal(x, nx, 4)
def perf_vectorized_ngsim_env_step(): basedir = os.path.expanduser('~/.julia/packages/NGSIM/9OYUa/data') filename = 'trajdata_i101_trajectories-0750am-0805am.txt' filepaths = [os.path.join(basedir, filename)] n_envs = 100 env = JuliaEnv(env_id='VectorizedNGSIMEnv', env_params=dict( n_envs=n_envs, trajectory_filepaths=filepaths, ), using='AutoEnvs') n_steps = 10000 action = np.zeros((n_envs, 2)) action[:, 0] = 1. env.reset() with ContextTimer(): for _ in range(0, n_steps, n_envs): _, _, terminal, _ = env.step(action) env.reset(terminal)