RLLib – testing my trained agent gives bad results

I’m using Ray (version 1.8.0) to train an agent. The agent controls a unit in a simulation, and the simulation can end in one of three different ways: “UnitADestroyed”, “UnitBDestroyed” or “Timeout”. My aim is to maximize the probability of the outcome “UnitADestroyed”, so I give rewards accordingly. I also log the outcome of each simulation.

My code for training the agent looks like this:

config = {
    "env": "MyEnv-v0",
    "num_workers": 40,
    "num_cpus_per_worker": 1.0,
    "train_batch_size": 32000,
    "num_sgd_iter": 2,
    "framework": "torch",
    "log_level": "INFO",
    "callbacks": EpisodeEndCallbacks,  # This basically just logs the outcome to stdout
}

trainer = ppo.PPOTrainer(config=config, logger_creator=lambda config: ray.tune.logger.UnifiedLogger(config, logdir))

print("Starting training...")
for i in range(numIterations):
    result = trainer.train()

This seems to work, and in TensorBoard I can see the development of the average of my custom metrics. This is the average of “UnitADestroyed” in one of my runs:

This is the average of “UnitBDestroyed”:

And this is the average of “Timeout”:

So as you can see, “UnitADestroyed” increases from almost nothing in the beginning (which I think is realistic with a completely random agent) to about 25-30%. This is all very nice. I have also verified this by looking at a few log files from the simulations (each simulation creates its own log file).

But the problem begins when I try to test the agent after training. I do this:

for seed in range(100):
    env = MyEnv()
    env.MySeed = seed + 1001 # during training, MySeed is not set, and will therefore get a random value
    state = env.reset()
    done = False
    total_reward = 0
    while not done:
        action = trainer.compute_action(state, explore=False)
        state, reward, done, _ = env.step(action)
        total_reward += reward

This runs the simulation 100 times (the simulation is initialized with seeds from 1 to 100, for reproducability – during training the seeds are random). I had expected to see the “UnitADestroyed” outcome 25-30 times, but didn’t – it only occured 3 times on average (I have of course repeated this whole process a lot of times now), the “UnitBDestroyed” occured around anywhere between 0 and 40 times and the rest was “Timeout”.

I have also tried saving the weights to files, and restoring them in a whole new process, with the exact same results. And I have tried using explore = True, but that gave even worse results (“Timeout” all the time).

So what have I done wrong? It looks very promising during training, so something is clearly being achieved here, but I’m not able to reproduce that success afterwards. I suspect I may be doing something wrong when I extract the trained agent, since the results after training seem so random???

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật