openai / procgen

Procgen Benchmark: Procedurally-Generated Game-Like Gym-Environments

Home Page:https://openai.com/blog/procgen-benchmark/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass variable size array to info dict

jordan-schneider opened this issue · comments

I'm trying to pass the entire miner grid through to the info dict, and I'm not sure how best to do it.

I'm looking at the structs in https://github.com/openai/gym3/blob/master/gym3/libenv.h and all of them seem to require a fixed array, where the grid can be one of three sizes based on hardness. I could define the size to be the maximum possible size, but that's inefficient/gross.

The only other alternative I can think of is to define a new C++/python interface with ffi, and that looks even worse.

Maximum size is how I would do it, and then two fixed values for the actual dimensions (if required). C loves fixed sized arrays (and not allocating memory), which is why all the libenv stuff uses fixed size arrays. It's not particularly inefficient, especially if you're reusing the array each time, which libenv likely does. The grossest part is that you have this dangerous ability to read the wrong size grid, but C doesn't even check normal array bounds, so it's nothing special there.

Yeah looks like it creates a single info array and reuses it: https://github.com/openai/gym3/blob/master/gym3/libenv.py#L142

reuse_arrays is a confusing name, but can be set to True to avoid a returning a copy. Returning a copy is a lot safer, for instance, if you gather all your observations from an episode into a list with reuse_arrays=True, they'll all be the same observation.