sail-sg / envpool

C++-based high-performance parallel environment execution engine (vectorized env) for general RL environments.
https://envpool.readthedocs.io
Apache License 2.0
1.09k stars 100 forks source link

[BUG] wrong handle in example? #274

Closed SobhanMP closed 1 year ago

SobhanMP commented 1 year ago

Describe the bug

I think https://github.com/sail-sg/envpool/blob/aacf06f694ead2eb75331f085f00dad71eec1a08/examples/xla_step.py#L93 should be handle1, new_states = recv(handle1) not handle1, new_states = recv(handle0)

or am I missing something?

mavenlin commented 1 year ago

Hi @SobhanMP good catch, I think in the second call either handle0 or handle1 works.

Even though we version the handles, behind the scene they share the same c++ object. The versioning is to force the sequence of execution.

For example, instead of versioning, we could use a single handle. This will cause send and recv to happen sequentially. recv is only executed after send.

handle = send(handle, action, states.observation.env_id)
handle, new_states = recv(handle)

The reason why we use handle0 in the recv call is to avoid waiting for the send to finish, this is safe in the asynchronous mode.

It is explained in the documentation. https://envpool.readthedocs.io/en/latest/content/xla_interface.html

SobhanMP commented 1 year ago

Oh, that's pretty neat