Skip to content

[Question] How is np_random set for AsyncVectorEnvs and why does the generator change? #1435

@Daraan

Description

@Daraan

Question

Hello :)
In my setting I change the np_random generator of my envs

seed_sequence = np.random.SeedSequence(
            env_seed,
            spawn_key=(worker_index, env_context.vector_index, env_runner.config.in_evaluation),
        )
rng = np.random.default_rng(seed_sequence)
rngs = rng.spawn(env.num_envs if _is_async(env) else 1)
# env: SyncVectorEnv | AsyncVectorEnv
env.set_attr("np_random", rngs)
env.np_random  # <-- if async new generator, based on rngs but not the same as rngs

For sync environments the generators are like I expected identical.

For an async ones the final env.np_random that I get back from the pipe is not the same. What I wonder is, why does entropy and seed_sequence of the bit generator differ?
What I can tell is that my original rngs are used to create new random generators. I would like to now how and where in the code this happens.
In the end I would like to test if the framework that I use does not overwrite my own generators, with their own seed logic, which currently a bit difficult.
Thank you very much if you can provide me some insights.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions