Skip to content

Implement step_async and step_wait - #264

Open
eliasnaha wants to merge 3 commits into
edbeeching:mainfrom
eliasnaha:implement-step-async
Open

eliasnaha wants to merge 3 commits into
edbeeching:mainfrom
eliasnaha:implement-step-async

Conversation

@eliasnaha

Copy link
Copy Markdown

step_async currently runs the whole step and caches the result:

def step_async(self, actions):
    # Execute the step function asynchronously, not actually implemented in this setting
    self.results = self.step(actions)

def step_wait(self):
    return self.results

So the split the VecEnv API is built around is not there. A caller that does step_async, gets on with something else, then calls step_wait still pays the whole receive cost inside step_async.

This moves the send loop into step_async, the receive loop into step_wait, and leaves step as the two called in order. GodotEnv already exposes step_send and step_recv, so nothing changes on the protocol or plugin side.

Results are identical and actions still reach every game before the first receive, so the existing overlap between parallel instances is preserved. The tests pin the call order and check that step matches step_async followed by step_wait.

step_async ran the whole step and cached the result, so the split the sb3 VecEnv
API expects did not exist: a caller doing step_async then step_wait paid the
receive cost inside step_async. The send loop now lives in step_async, the
receive loop in step_wait, and step calls the two in order.

Results are unchanged. Actions still reach every environment before the first
receive, so the existing overlap between the parallel games is preserved.
The rllib CI jobs uninstall stable_baselines3 before running the suite, so a
module level import of the sb3 wrapper turns into a pytest collection error and
takes the whole run down. Import the wrapper inside the helper that builds the
env and skip the module when ray is present, as the other sb3 tests already do.
SBGSingleObsEnv only overrode step(), which worked because step_async used to be
self.results = self.step(actions), a virtual call. Now that step_async and
step_wait do the work themselves, sb3 never enters the subclass step(): VecEnv.step
calls the pair, VecEnvWrapper forwards step_async and VecMonitor forwards step_wait.
examples/sb3_imitation.py wraps SBGSingleObsEnv in VecMonitor and trains an
MlpPolicy, so it would receive the dict observation instead of the array behind
obs_key, and lose the terminal_observation the imitation path needs.

Override step_wait instead, which both the async pair and the inherited step()
now go through. The test drives the subclass through a real VecMonitor and fails
without this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant