From 52d4b5a36c75ae4064b4771057aea01f11f20cd3 Mon Sep 17 00:00:00 2001 From: ebuehrle <43623224+ebuehrle@users.noreply.github.com> Date: Fri, 21 Jan 2022 10:20:08 +0100 Subject: [PATCH] Refactor LL buffer --- scratch/etienne/intersimple/data/generate.sh | 3 ++- scratch/etienne/intersimple/gail/options2.py | 13 +++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/scratch/etienne/intersimple/data/generate.sh b/scratch/etienne/intersimple/data/generate.sh index b17f59b..066af5d 100755 --- a/scratch/etienne/intersimple/data/generate.sh +++ b/scratch/etienne/intersimple/data/generate.sh @@ -11,4 +11,5 @@ #python -m expert --env=NRasterizedRouteRandomAgentLocation --min_timesteps=100000 --env_args='{width:70,height:70,m_per_px:1,map_color:128}' --policy_args='{mu:0.001}' --path='NormalizedIntersimpleExpertMu.001N100000_NRasterizedRouteRandomAgentLocationw70h70mppx1mapc128.pkl' #python -m expert --env=NRasterizedRouteSpeedRandomAgentLocation --min_timesteps=10000 --env_args='{width:70,height:70,m_per_px:1,map_color:128,mu:0.001}' --policy_args='{mu:0.001}' --path='NormalizedIntersimpleExpertMu.001N10000_NRasterizedRouteSpeedRandomAgentLocationw70h70mppx1mapc128mu.001.pkl' #python -m data.expert --env=NRasterizedRouteSpeedRandomAgentLocation --min_timesteps=10000 --env_args='{width:70,height:70,m_per_px:1,map_color:128,mu:0.001,skip_frames:5}' --policy_args='{mu:0.001}' --path='NormalizedIntersimpleExpertMu.001N10000_NRasterizedRouteSpeedRandomAgentLocationw70h70mppx1mapc128mu.001skip5.pkl' -python -m data.expert --env=TLNRasterizedRouteRandomAgentLocation --min_timesteps=100000 --env_args='{width:70,height:70,m_per_px:1,mu:0.001,random_skip:True,max_episode_steps:50}' --policy_args='{mu:0.001}' --path='NormalizedIntersimpleExpertMu.001N100000_TLNRasterizedRouteRandomAgentLocationw70h70mppx1mu.001rskips50.pkl' +#python -m data.expert --env=TLNRasterizedRouteRandomAgentLocation --min_timesteps=100000 --env_args='{width:70,height:70,m_per_px:1,mu:0.001,random_skip:True,max_episode_steps:50}' --policy_args='{mu:0.001}' --path='NormalizedIntersimpleExpertMu.001N100000_TLNRasterizedRouteRandomAgentLocationw70h70mppx1mu.001rskips50.pkl' +python -m data.expert --env=TLNRasterizedRouteRandomAgentLocation --min_timesteps=50000 --env_args='{width:70,height:70,m_per_px:1,mu:0.001,random_skip:True,max_episode_steps:50}' --policy_args='{mu:0.001}' --path='NormalizedIntersimpleExpertMu.001N50000_TLNRasterizedRouteRandomAgentLocationw70h70mppx1mu.001rskips50.pkl' diff --git a/scratch/etienne/intersimple/gail/options2.py b/scratch/etienne/intersimple/gail/options2.py index 4745157..67afa8f 100644 --- a/scratch/etienne/intersimple/gail/options2.py +++ b/scratch/etienne/intersimple/gail/options2.py @@ -14,7 +14,7 @@ def imitation_discriminator(discriminator): class OptionsEnv(gym.Wrapper): - def __init__(self, env, options, discriminator, discount, ll_buffer_capacity, *args, **kwargs): + def __init__(self, env, options, discriminator, discount, ll_buffer, *args, **kwargs): super().__init__(env, *args, **kwargs) self.options = options @@ -27,8 +27,7 @@ class OptionsEnv(gym.Wrapper): self.discriminator = discriminator self.discount = discount - self.ll_buffer_capacity = ll_buffer_capacity - self.ll_buffer = deque(maxlen=ll_buffer_capacity) + self.ll_buffer = ll_buffer @staticmethod def _hl_observation(obs, mask): @@ -77,17 +76,11 @@ class OptionsEnv(gym.Wrapper): self.m = available_actions(self.env, self.options) return self._hl_observation(self.obs, self.m), reward, self.done, info - - def sample_ll(self, n): - assert n <= self.ll_buffer_capacity, f'Sample size of {n} exceeds buffer capacity of {self.ll_buffer_capacity}' - assert n <= len(self.ll_buffer), f'Sample size of {n} exceeds buffer size of {len(self.ll_buffer)}' - ind = np.random.randint(len(self.ll_buffer), size=n) - return list(self.ll_buffer[i] for i in ind) class RenderOptions(OptionsEnv): def __init__(self, env, options, *args, **kwargs): - super().__init__(env, options, discriminator=lambda s, a, n, d: 0, discount=1, ll_buffer_capacity=0, *args, **kwargs) + super().__init__(env, options, discriminator=lambda s, a, n, d: 0, discount=1, ll_buffer=deque(maxlen=0), *args, **kwargs) def _ll_step(self, action): out = super()._ll_step(action)