def __init__(self, *args, **kwargs): """ [OPTIONAL] Initialize the agent with the `test_case_id` (string), which might be important if your agent is test case dependent. For example, you might want to load the appropriate neural networks weight in this method. """ test_case_id = kwargs.get("test_case_id") """ # Uncomment to help debugging print(">>> __INIT__ >>>") print("test_case_id:", test_case_id) """ self.device = torch.device( "cuda:0" if torch.cuda.is_available() else "cpu") env = construct_random_lane_env() env.reset() self.dqn = AtariDQN(env.observation_space.shape, env.action_space.n).to(self.device) self.dqn.load_state_dict( torch.load(MODEL_NAME, map_location=lambda storage, loc: storage)) self.dqn.to(self.device) self.dqn.eval()
def get_task(): tcs = [('t2_tmax50', 50), ('t2_tmax40', 40)] return { 'time_limit': 600, 'testcases': [{ 'id': tc, 'env': construct_random_lane_env(), 'runs': 300, 't_max': t_max } for tc, t_max in tcs] }
def get_task(): tcs = [("t2_tmax50", 50), ("t2_tmax40", 40)] return { "time_limit": 600, "testcases": [{ "id": tc, "env": construct_random_lane_env(), "runs": 300, "t_max": t_max } for tc, t_max in tcs] }
''' # try: # server-compatible import statement # from models import * # except: pass # try: # local-compatible import statement # from .models import * # except: pass import torch from mcts import * from dqn import * from env import * from models import AtariDQN import torch.optim as optim env = construct_random_lane_env() device = torch.device("cuda" if torch.cuda.is_available() else "cpu") script_path = os.path.dirname(os.path.realpath(__file__)) model_path = os.path.join(script_path, 'model.pt') train_steps = 10 #dqn training steps T = 1 RANDOM_SEED = 1234 max_iterations = 100 #dagger iteration numiters = 100 #mcts iterations # Transition = collections.namedtuple('Transition', ('state', 'action', 'reward', 'next_state', 'done')) def simulatePolicy(state, model, env): ''' Policy followed in MCTS simulation for playout '''