Skip to content

Conversation

@pseudo-rnd-thoughts
Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts commented Nov 5, 2025

Description

Allow users to use environments that are already vectorized for SingleAgentEnvRunner
With gymnasium.make_vec, users have the option to either use the SyncVectorEnv to vectorize a base environment or to directly create a vector environment using the vectorize_mode: gymnasium.VectorizeMode.
This PR utilises the env_runners(gym_env_vectorize_mode=...) argument to support VectorizeMode.VECTOR_ENTRY_POINT

import gymnasium as gym

config = ...
config.env_runners(
  gym_env_vectorize_mode=gym.VectorizeMode.VECTOR_ENTRY_POINT,
)

An important change related to this PR is that the values accepted for the vectorize mode is either the enum (VectorizedMode.ASYNC, etc) or the enum values ("async", etc) as before it was the string version was the enum name ("ASYNC") rather than the enum value itself.

Related issues

Completion of #57643,

Additional information

#58397 must be merged first

We should apply a similar change to the MultiAgentEnvRunner.make_env

Signed-off-by: Mark Towers <mark@anyscale.com>
@pseudo-rnd-thoughts pseudo-rnd-thoughts requested a review from a team as a code owner November 5, 2025 12:19
@pseudo-rnd-thoughts pseudo-rnd-thoughts added rllib RLlib related issues rllib-envrunners Issues around the sampling backend of RLlib labels Nov 5, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for pre-vectorized environments in SingleAgentEnvRunner by utilizing gymnasium.VectorizeMode.VECTOR_ENTRY_POINT. The changes in SingleAgentEnvRunner.make_env are well-structured to handle different environment registration types and correctly pass configurations. The accompanying tests are thorough, especially the new test_vectorize_mode and test_env_context, and the improvements to test_sample make it more robust.

I've identified a few instances where the dictionary union operator (|) is used, which is incompatible with Python 3.8, a supported version for Ray. I've left comments with suggestions for backward-compatible alternatives. Apart from that, the changes look solid.

Mark Towers added 4 commits November 5, 2025 15:11
Signed-off-by: Mark Towers <mark@anyscale.com>
Signed-off-by: Mark Towers <mark@anyscale.com>
Signed-off-by: Mark Towers <mark@anyscale.com>
Signed-off-by: Mark Towers <mark@anyscale.com>
Copy link
Contributor

@simonsays1980 simonsays1980 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the tuning @pseudo-rnd-thoughts !

@pseudo-rnd-thoughts pseudo-rnd-thoughts added the go add ONLY when ready to merge, run all tests label Nov 15, 2025
Mark Towers added 4 commits November 17, 2025 11:59
# Conflicts:
#	rllib/env/tests/test_single_agent_env_runner.py
Signed-off-by: Mark Towers <mark@anyscale.com>
Signed-off-by: Mark Towers <mark@anyscale.com>
Signed-off-by: Mark Towers <mark@anyscale.com>
@simonsays1980 simonsays1980 merged commit 885e34f into ray-project:master Nov 17, 2025
6 checks passed
Aydin-ab pushed a commit to Aydin-ab/ray-aydin that referenced this pull request Nov 19, 2025
…_env` (ray-project#58410)

## Description
Allow users to use environments that are already vectorized for
`SingleAgentEnvRunner`
With `gymnasium.make_vec`, users have the option to either use the
`SyncVectorEnv` to vectorize a base environment or to directly create a
vector environment using the `vectorize_mode: gymnasium.VectorizeMode`.
This PR utilises the `env_runners(gym_env_vectorize_mode=...)` argument
to support `VectorizeMode.VECTOR_ENTRY_POINT`

```
import gymnasium as gym

config = ...
config.env_runners(
  gym_env_vectorize_mode=gym.VectorizeMode.VECTOR_ENTRY_POINT,
)
```

An important change related to this PR is that the values accepted for
the vectorize mode is either the enum (`VectorizedMode.ASYNC`, etc) or
the enum values (`"async"`, etc) as before it was the string version was
the enum name (`"ASYNC"`) rather than the enum value itself.

## Related issues
Completion of ray-project#57643,

## Additional information
ray-project#58397 must be merged first

We should apply a similar change to the `MultiAgentEnvRunner.make_env`

---------

Signed-off-by: Mark Towers <mark@anyscale.com>
Co-authored-by: Mark Towers <mark@anyscale.com>
Signed-off-by: Aydin Abiar <aydin@anyscale.com>
ykdojo pushed a commit to ykdojo/ray that referenced this pull request Nov 27, 2025
…_env` (ray-project#58410)

## Description
Allow users to use environments that are already vectorized for
`SingleAgentEnvRunner`
With `gymnasium.make_vec`, users have the option to either use the
`SyncVectorEnv` to vectorize a base environment or to directly create a
vector environment using the `vectorize_mode: gymnasium.VectorizeMode`.
This PR utilises the `env_runners(gym_env_vectorize_mode=...)` argument
to support `VectorizeMode.VECTOR_ENTRY_POINT`

```
import gymnasium as gym

config = ...
config.env_runners(
  gym_env_vectorize_mode=gym.VectorizeMode.VECTOR_ENTRY_POINT,
)
```

An important change related to this PR is that the values accepted for
the vectorize mode is either the enum (`VectorizedMode.ASYNC`, etc) or
the enum values (`"async"`, etc) as before it was the string version was
the enum name (`"ASYNC"`) rather than the enum value itself.

## Related issues
Completion of ray-project#57643,

## Additional information
ray-project#58397 must be merged first

We should apply a similar change to the `MultiAgentEnvRunner.make_env`

---------

Signed-off-by: Mark Towers <mark@anyscale.com>
Co-authored-by: Mark Towers <mark@anyscale.com>
Signed-off-by: YK <1811651+ykdojo@users.noreply.github.com>
SheldonTsen pushed a commit to SheldonTsen/ray that referenced this pull request Dec 1, 2025
…_env` (ray-project#58410)

## Description
Allow users to use environments that are already vectorized for
`SingleAgentEnvRunner`
With `gymnasium.make_vec`, users have the option to either use the
`SyncVectorEnv` to vectorize a base environment or to directly create a
vector environment using the `vectorize_mode: gymnasium.VectorizeMode`.
This PR utilises the `env_runners(gym_env_vectorize_mode=...)` argument
to support `VectorizeMode.VECTOR_ENTRY_POINT`

```
import gymnasium as gym

config = ...
config.env_runners(
  gym_env_vectorize_mode=gym.VectorizeMode.VECTOR_ENTRY_POINT,
)
```

An important change related to this PR is that the values accepted for
the vectorize mode is either the enum (`VectorizedMode.ASYNC`, etc) or
the enum values (`"async"`, etc) as before it was the string version was
the enum name (`"ASYNC"`) rather than the enum value itself.

## Related issues
Completion of ray-project#57643, 

## Additional information
ray-project#58397 must be merged first

We should apply a similar change to the `MultiAgentEnvRunner.make_env`

---------

Signed-off-by: Mark Towers <mark@anyscale.com>
Co-authored-by: Mark Towers <mark@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests rllib RLlib related issues rllib-envrunners Issues around the sampling backend of RLlib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants