[英]Error while running Linux commands in Jupyter notebook on windows
[英]Getting error in Jupyter Notebook on Linux but not on Windows
我正在嘗試在 Linux 上運行以下筆記本 ( https://github.com/carlosnatalino/optical-rl-gym/blob/master/examples/stable_baselines/DeepRMSA.ipynb ) 但我在塊 8 中不斷收到以下錯誤:
KeyError Traceback (most recent call last)
<ipython-input-8-4b84d49bf60d> in <module>()
----> 1 agent.learn(total_timesteps=100000, callback=callback)
~/.conda/envs/project4/lib/python3.7/site-packages/stable_baselines/ppo2/ppo2.py in learn(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps)
334 callback.on_rollout_start()
335 # true_reward is the reward without discount
--> 336 rollout = self.runner.run(callback)
337 # Unpack
338 obs, returns, masks, actions, values, neglogpacs, states, ep_infos, true_reward = rollout
~/.conda/envs/project4/lib/python3.7/site-packages/stable_baselines/common/runners.py in run(self, callback)
46 self.callback = callback
47 self.continue_training = True
---> 48 return self._run()
49
50 @abstractmethod
~/.conda/envs/project4/lib/python3.7/site-packages/stable_baselines/ppo2/ppo2.py in _run(self)
480 if isinstance(self.env.action_space, gym.spaces.Box):
481 clipped_actions = np.clip(actions, self.env.action_space.low, self.env.action_space.high)
--> 482 self.obs[:], rewards, self.dones, infos = self.env.step(clipped_actions)
483
484 self.model.num_timesteps += self.n_envs
~/.conda/envs/project4/lib/python3.7/site-packages/stable_baselines/common/vec_env/base_vec_env.py in step(self, actions)
148 """
149 self.step_async(actions)
--> 150 return self.step_wait()
151
152 def get_images(self, *args, **kwargs) -> Sequence[np.ndarray]:
~/.conda/envs/project4/lib/python3.7/site-packages/stable_baselines/common/vec_env/dummy_vec_env.py in step_wait(self)
40 for env_idx in range(self.num_envs):
41 obs, self.buf_rews[env_idx], self.buf_dones[env_idx], self.buf_infos[env_idx] =\
---> 42 self.envs[env_idx].step(self.actions[env_idx])
43 if self.buf_dones[env_idx]:
44 # save final observation where user can get it, then reset
~/.conda/envs/project4/lib/python3.7/site-packages/stable_baselines/bench/monitor.py in step(self, action)
97 ep_info = {"r": round(ep_rew, 6), "l": eplen, "t": round(time.time() - self.t_start, 6)}
98 for key in self.info_keywords:
---> 99 ep_info[key] = info[key]
100 self.episode_rewards.append(ep_rew)
101 self.episode_lengths.append(eplen)
KeyError: 'service_blocking_rate_since_reset'
筆記本在 windows 中運行良好(具有不同的目錄 ofc),我確保在兩個環境中安裝相同版本的 python 和相同的包(創建一個 environment.yml 並將其安裝在 linux 上)。 使用 linux 時出現此錯誤的原因是什么?
您確定在DeepRMSA.pynb筆記本中收到此錯誤嗎? 我僅在https://github.com/carlosnatalino/optical-rl-gym/blob/main/examples/stable_baselines/QoSConstrainedRA.ipynb筆記本中收到此錯誤。
您指向的代碼似乎不准確。 QoSConstrainedRA 使用此子類實例化環境: https://github.com/carlosnatalino/optical-rl-gym/blob/main/optical_rl_gym/envs/qos_constrained_ra.py此子類使用以下字典顯式返回每個步驟的信息:
info = {
'service_blocking_rate': (self.services_processed - self.services_accepted) / self.services_processed,
'episode_service_blocking_rate': (self.episode_services_processed - self.episode_services_accepted) / self.episode_services_processed,
}
因此,當在單元格 7 中使用以下info_keywords
定義環境變量時:
env = Monitor(env, log_dir + 'training', info_keywords=('service_blocking_rate_since_reset',))
它只能在以下穩定基線行中崩潰https://github.com/hill-a/stable-baselines/blob/b3f414f4f2900403107357a2206f80868af16da3/stable_baselines/bench/monitor.py#L99
為了快速修復,您可以將單元格 7 的上述行替換為以下內容:
env = Monitor(env, log_dir + 'training', info_keywords=('service_blocking_rate','episode_service_blocking_rate'))
為什么會在 Windows 運行,我真的不知道。 對我來說,如果沒有,那將是有道理的。 你確定你在兩個平台上測試了同一個筆記本嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.