# Ray RLlib environment with Ray Tune parameters

**URL:** <https://discuss.ray.io/t/ray-rllib-environment-with-ray-tune-parameters/2341>\
**Category:** RLlib\
**Created:** [May 31, 2021, 8:40am UTC](https://discuss.ray.io/t/ray-rllib-environment-with-ray-tune-parameters/2341 "2021-05-31T08:40:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![XavierM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xavierm/32/2684_2.png) [@XavierM](https://discuss.ray.io/u/XavierM)\
**Post date:** [May 31, 2021, 8:40am UTC](https://discuss.ray.io/t/ray-rllib-environment-with-ray-tune-parameters/2341/1 "2021-05-31T08:40:13Z")

</div>

I would like to use Ray RLlib and Ray Tune so that my FooEnv (which extends MultiAgentEnv) can try different hyper-parameters coming from Ray Tune.

However, I do not see how to register my FooEnv with the set of hyperparameters coming from Tune. Is there any example where I could investigate that?

---

<div class="post-metadata">

**Author:** ![sven1977](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sven1977/32/53_2.png) [@sven1977](https://discuss.ray.io/u/sven1977)\
**Post date:** [June 1, 2021, 12:45pm UTC](https://discuss.ray.io/t/ray-rllib-environment-with-ray-tune-parameters/2341/2 "2021-06-01T12:45:33Z")

</div>

Hey @XavierM , could you try this?

```auto
tune.register_env("my_foo_env", lambda env_ctx: FooEnv(env_ctx)) # <- use env_ctx as a config dict inside your env's c'tor. This is where the tune hyperparams should arrive (see below).

tune.run("PPO", {
    "env": "my_foo_env",
    "env_config": {
        "num_foo_robots": tune.grid_search([2, 4, 42]),
        "type_bar_weapons": tune.grid_search(["laser", "light-saber"]),
    }
})

```

Does the above make sense?

---

<div class="post-metadata">

**Author:** ![XavierM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xavierm/32/2684_2.png) [@XavierM](https://discuss.ray.io/u/XavierM)\
**Post date:** [June 2, 2021, 7:58am UTC](https://discuss.ray.io/t/ray-rllib-environment-with-ray-tune-parameters/2341/3 "2021-06-02T07:58:45Z")

</div>

Yes, this solves what I wanted to do. Thank you so much @sven1977!

---

<div class="post-metadata">

**Author:** ![XavierM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xavierm/32/2684_2.png) [@XavierM](https://discuss.ray.io/u/XavierM)\
**Post date:** [June 2, 2021, 8:05am UTC](https://discuss.ray.io/t/ray-rllib-environment-with-ray-tune-parameters/2341/4 "2021-06-02T08:05:39Z")

</div>

With hindsight, I now realise that with more experience I should also have found a part of the answer in [https://github.com/ray-project/ray/blob/master/doc/source/rllib-env.rst](https://github.com/ray-project/ray/blob/master/doc/source/rllib-env.rst).
