def __init__(self, config):
    super().__init__(config)
    self.policy_model = DQN(self.config)
    self.target_model = DQN(self.config)
    self.memory = ReplayMemory(self.config)
    self.loss = HuberLoss()
    self.optim = torch.optim.RMSprop(self.policy_model.parameters())
    self.env = gym.make('CartPole-v0').unwrapped
    self.cartpole = CartPoleEnv(self.config.screen_width)
    self.current_episode = 0
    self.current_iteration = 0
    self.episode_durations = []
    self.is_cuda = torch.cuda.is_available()
    if (self.is_cuda and (not self.config.cuda)):
        self.logger.info('WARNING: You have a CUDA device, so you should probably enable CUDA')
    self.cuda = (self.is_cuda & self.config.cuda)
    if self.cuda:
        self.device = torch.device('cuda')
        torch.cuda.set_device(self.config.gpu_device)
        self.logger.info('Program will run on *****GPU-CUDA***** ')
        print_cuda_statistics()
    else:
        self.device = torch.device('cpu')
        self.logger.info('Program will run on *****CPU***** ')
    self.policy_model = self.policy_model.to(self.device)
    self.target_model = self.target_model.to(self.device)
    self.loss = self.loss.to(self.device)
    self.target_model.load_state_dict(self.policy_model.state_dict())
    self.target_model.eval()
    self.summary_writer = SummaryWriter(log_dir=self.config.summary_dir, comment='DQN')
def __init__(self, config):
    super().__init__(config)
    self.policy_model = DQN(self.config)
    self.target_model = DQN(self.config)
    self.memory = ReplayMemory(self.config)
    self.loss = HuberLoss()
    self.optim = torch.optim.RMSprop(self.policy_model.parameters())
    self.env = gym.make('CartPole-v0').unwrapped
    self.cartpole = CartPoleEnv(self.config.screen_width)
    self.current_episode = 0
    self.current_iteration = 0
    self.episode_durations = []
    self.is_cuda = torch.cuda.is_available()
    if (self.is_cuda and (not self.config.cuda)):
        self.logger.info('WARNING: You have a CUDA device, so you should probably enable CUDA')
    self.cuda = (self.is_cuda & self.config.cuda)
    if self.cuda:
        self.device = torch.device('cuda')
        torch.cuda.set_device(self.config.gpu_device)
        self.logger.info('Program will run on *****GPU-CUDA***** ')
        print_cuda_statistics()
    else:
        self.device = torch.device('cpu')
        self.logger.info('Program will run on *****CPU***** ')
    self.policy_model = self.policy_model.to(self.device)
    self.target_model = self.target_model.to(self.device)
    self.loss = self.loss.to(self.device)
    self.target_model.load_state_dict(self.policy_model.state_dict())
    self.target_model.eval()
    self.summary_writer = SummaryWriter(log_dir=self.config.summary_dir, comment='DQN')