microsoft / TextWorld

​TextWorld is a sandbox learning environment for the training and evaluation of reinforcement learning (RL) agents on text-based games.
Other
1.23k stars 189 forks source link

Sort list of paths returned by glob #176

Closed MarcCote closed 5 years ago

MarcCote commented 5 years ago

A sneaky bug was happening when generating games on different machines.

Indirectly, the ordering of the dictionary Type.children was depending on the ordering of the *.twl files as returned by the OS (via glob.glob). As a result, the order of the child types was machine-dependent (see https://github.com/microsoft/TextWorld/blob/master/textworld/logic/__init__.py#L263)

tavianator commented 5 years ago

Hmm. I think we should (also?) fix this in the logic layer. Actually what's wrong with having a different ordering for the child types?

xingdi-eric-yuan commented 5 years ago

Same seed will generate different games on different machines.

MarcCote commented 5 years ago

@tavianator I agree we should fix it in the logic but I needed a quick fix. Also, I wasn't entirely sure if simply sorting the children would be enough or would the order in which we read the logic files might affect other parts of GameLogic!

As an example, let say we want to sample an object which has some attributes.

HOLDER_TYPES = list(itertools.chain(*M.kb.logic.types.multi_descendants(HOLDER_TYPES)))
type = rng.choice(HOLDER_TYPES)

OBJECTS_TYPES = list(M.kb.logic.types.get("o").subtypes)
type = rng.choice(OBJECTS_TYPES)
tavianator commented 5 years ago

I made https://github.com/microsoft/TextWorld/pull/177 with an alternative fix, let me know if that works

MarcCote commented 5 years ago

Closed in favor of #177