docstr: Embed state after either reset() or step()
docstr_tok: ["Embed","state","after","either","reset","(",")","or","step","(",")"]
code: def embed_state(self, state):
      """Embed state after either reset() or step()"""
      assert len(self.recent_states) == len(self.recent_actions)
      old_mdnrnn_mode = self.mdnrnn.mdnrnn.training
      self.mdnrnn.mdnrnn.eval()
  
      # Embed the state as the hidden layer's output
      # until the previous step + current state
      if len(self.recent_states) == 0:
          mdnrnn_state = np.zeros((1, self.raw_state_dim))
          mdnrnn_action = np.zeros((1, self.action_dim))
      else:
          mdnrnn_state = np.array(list(self.recent_states))
          mdnrnn_action = np.array(list(self.recent_actions))
  
      mdnrnn_state = torch.tensor(
          mdnrnn_state, dtype=torch.float
      ).unsqueeze(1)
      mdnrnn_action = torch.tensor(
          mdnrnn_action, dtype=torch.float
      ).unsqueeze(1)
      mdnrnn_output = self.mdnrnn(
          rlt.FeatureData(mdnrnn_state), rlt.FeatureData(mdnrnn_action)
      )
      hidden_embed = (
          mdnrnn_output.all_steps_lstm_hidden[-1]
          .squeeze()
          .detach()
          .cpu()
          .numpy()
      )
      state_embed = np.hstack((hidden_embed, state))
      self.mdnrnn.mdnrnn.train(old_mdnrnn_mode)
      logger.debug(
          f"Embed_state\nrecent states: {np.array(self.recent_states)}\n"
          f"recent actions: {np.array(self.recent_actions)}\n"
          f"state_embed{state_embed}\n"
      )
      return state_embed
  
file_path: ReAgent/reagent/gym/envs/pomdp/state_embed_env.py
imports: import logging
  from collections import deque
  from typing import Optional
  import gym
  import numpy
  import reagent.core.types
  import torch
  from gym.spaces import Box
  from reagent.gym.envs import EnvWrapper
  from reagent.models.world_model import MemoryNetwork
label_desc: Use image node_id 4 for calling the StateEmbedEnvironment obj's underlying member method code with example usage: obj.embed_state(state) and returns: state_embed