Skip to content

Commit b6e5a14

Browse files
puyuan1996tAnGjIa520
authored andcommitted
fix(pu): fix muzero_evaluator compatibility when n_evaluator_episode>evaluator_env_num (opendilab#415)
1 parent 6f3e267 commit b6e5a14

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lzero/worker/muzero_evaluator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ def eval(
281281
ready_env_id = ready_env_id.union(set(list(new_available_env_id)[:remain_episode]))
282282
remain_episode -= min(len(new_available_env_id), remain_episode)
283283

284+
# In a parallel evaluation setting, it's possible for all active environments to finish their
285+
# episodes simultaneously. This can leave `ready_env_id` temporarily empty while the environments
286+
# are being reset by the manager.
287+
# To prevent processing an empty batch, which would cause an IndexError or other errors downstream,
288+
# we check if `ready_env_id` is empty. If so, we sleep briefly to prevent a busy-wait,
289+
# and `continue` to the next loop iteration to wait for newly reset environments to become available.
290+
if not ready_env_id:
291+
time.sleep(0.01)
292+
continue
293+
284294
stack_obs = {env_id: game_segments[env_id].get_obs() for env_id in ready_env_id}
285295
stack_obs = list(stack_obs.values())
286296

0 commit comments

Comments
 (0)