def save_model(model_file, agent_models, agent_opts, start_time, episode):
    state = {}
    for i in range(2):
        state[('agent%s' % i)] = {}
        state[('agent%s' % i)]['model_state'] = agent_models[i].state_dict()
        state[('agent%s' % i)]['opt_state'] = agent_opts[i].state_dict()
    state['episode'] = episode
    state['elapsed_time'] = (time.time() - start_time)
    with open((model_file + '.tmp'), 'wb') as f:
        torch.save(state, f)
    os.rename((model_file + '.tmp'), model_file)
def save_model(model_file, agent_models, agent_opts, start_time, episode):
    state = {}
    for i in range(2):
        state[('agent%s' % i)] = {}
        state[('agent%s' % i)]['model_state'] = agent_models[i].state_dict()
        state[('agent%s' % i)]['opt_state'] = agent_opts[i].state_dict()
    state['episode'] = episode
    state['elapsed_time'] = (time.time() - start_time)
    with open((model_file + '.tmp'), 'wb') as f:
        torch.save(state, f)
    os.rename((model_file + '.tmp'), model_file)