simonmeister/pysc2-rl-agents

List index out of range

jaejaywoo opened this issue · 1 comments

Hello, I was running the agent on CollectMineralShards, and I often encountered following index error.

Traceback (most recent call last):
  File "/home/hyunjaewoo/.virtualenvs/pysc2/lib/python3.5/site-packages/pudb/__init__.py", line 119, in runscript
    dbg._runscript(mainpyfile)
  File "/home/hyunjaewoo/.virtualenvs/pysc2/lib/python3.5/site-packages/pudb/debugger.py", line 457, in _runscript
    self.run(statement, globals=globals_, locals=locals_)
  File "/usr/lib/python3.5/bdb.py", line 431, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "run.py", line 189, in <module>
    main()
  File "run.py", line 164, in main
    result = runner.run_batch(train_summary=write_summary)
  File "/home/hyunjaewoo/research/pysc2-rl-agents/rl/agents/a2c/runner.py", line 77, in run_batch
    actions = mask_unused_argument_samples(actions)
  File "/home/hyunjaewoo/research/pysc2-rl-agents/rl/agents/a2c/runner.py", line 171, in mask_unused_argument_samples
    unused_types = set(ACTION_TYPES) - set(FUNCTIONS._func_list[a_0].args)
IndexError: list index out of range

After I looked up what was going on, I figured out that often times, variable a_0 was assigned to a value 524, which is the actual size of the action.FUNCTIONS and which causes the index error in the code.

This actually happens in both of the functions mask_unused_argument_samples() and actions_to_pysc2(), so I am thinking that the problem is somewhere in the process of sampling the actions from the policy, but I couldn't find the cause. Have you ever encountered similar error message?

def mask_unused_argument_samples(actions):
"""Replace sampled argument id by -1 for all arguments not used
in a steps action (in-place).
"""
fn_id, arg_ids = actions
for n in range(fn_id.shape[0]):
a_0 = fn_id[n]
if a_0 == G_FUNCTION_NUMBER: #modified by roger
fn_id[n], a_0 = 0, 0
unused_types = set(TYPES) - set(FUNCTIONS._func_list[a_0].args)
for arg_type in unused_types:
arg_ids[arg_type][n] = -1
return (fn_id, arg_ids)