Giter Site home page Giter Site logo

Comments (2)

samvelyan avatar samvelyan commented on August 22, 2024

Hi @jlin816

Thanks for pointing this out and apologies for a late reply.

I see where the issue is. Firstly, MiniHack's seeding is slightly different from that of NLE's. The seeds argument in of a MiniHack environment assumes a list of integers which is used as a training distribution for an agent, e.g. [1, 3, 9, 27]. (Perhaps the documentation should make this clearer)

minihack/minihack/base.py

Lines 175 to 177 in 2054e7f

seeds (list or None):
A list of random seeds for sampling episodes. If none, the
entire level distribution is used. Defaults to None.

Specifically, when a reset function is called, minihack randomly samples one of the seeds, e.g. 27, (they are now stores as self._level_seeds since we treat them as levels of the same environment) and sets it using nle.seed(27, 27, False) like this

minihack/minihack/base.py

Lines 325 to 327 in 2054e7f

if self._level_seeds is not None:
seed = random.choice(self._level_seeds)
self.seed(seed, seed, reseed=False)

I understand this made the seed() function ignored if seeds was originally passed to the environment. Therefore, I added a new parameter in the reset() function of minihack called sample_seed (defaults to True). If True, the reset() function will randomly sample a level from the original list. If False, it will not do so, hence the manually setting the level seed with NLE's seed() function will work as desired.

Here is the PR #68. Please let me know if it works for you.

from minihack.

samvelyan avatar samvelyan commented on August 22, 2024

With this new PR, here is how one would use the seeding functionality

import minihack, gym
env = gym.make("MiniHack-KeyRoom-Fixed-S5-v0",
    observation_keys=("pixel", "colors", "chars", "glyphs", "tty_chars"),
    seeds=[1, 3, 9, 27])

For now let's sample random episodes a few times

obs = env.reset()
env.render()
print(env.get_seeds())

This outputs

You are lucky!  Full moon tonight.










                                          |
                                    ----..|
                                    |.....|
                                    |@.(..|
                                    -------






Agent the Footpad              St:13 Dx:17 Co:13 In:13 Wi:13 Ch:9 Chaotic S:0
Dlvl:1 $:0 HP:12(12) Pw:2(2) AC:7 Xp:1/0

(27, 27, False)

or perhaps

You are lucky!  Full moon tonight.








                                       ----
                                       |..|
                                       +..|
                                    ----..|
                                    |.....|
                                    |.(..@|
                                    -------






Agent the Footpad              St:14 Dx:18 Co:13 In:9 Wi:12 Ch:9 Chaotic S:0
Dlvl:1 $:0 HP:12(12) Pw:2(2) AC:7 Xp:1/0

(3, 3, False)

Now when we manually set the seed and use sample_seed=False, we will get the exact level we want

env.seed(42, 42, False)
obs = env.reset(sample_seed=False)
env.render()
print(env.get_seeds())

will result in the following.

You are lucky!  Full moon tonight.








                                       ----
                                       |..|
                                       +(.|
                                    ----..|
                                    |.....|
                                    |...@.|
                                    -------






Agent the Footpad              St:18/02 Dx:18 Co:13 In:8 Wi:9 Ch:7 Chaotic S:0
Dlvl:1 $:0 HP:12(12) Pw:2(2) AC:7 Xp:1/0

(42, 42, False)

from minihack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.