synth.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """
  2. Copied and adapted from https://github.com/mila-iqia/babyai.
  3. Levels described in the Baby AI ICLR 2019 submission.
  4. The instructions are a synthesis of those from `PutNext`, `Open`, `GoTo`, and `Pickup`.
  5. """
  6. from minigrid.envs.babyai.core.levelgen import LevelGen
  7. class Synth(LevelGen):
  8. """
  9. Union of all instructions from PutNext, Open, Goto and PickUp. The agent
  10. may need to move objects around. The agent may have to unlock the door,
  11. but only if it is explicitly referred by the instruction.
  12. Competencies: Maze, Unblock, Unlock, GoTo, PickUp, PutNext, Open
  13. """
  14. def __init__(self, room_size=8, num_rows=3, num_cols=3, num_dists=18, **kwargs):
  15. # We add many distractors to increase the probability
  16. # of ambiguous locations within the same room
  17. super().__init__(
  18. room_size=room_size,
  19. num_rows=num_rows,
  20. num_cols=num_cols,
  21. num_dists=num_dists,
  22. instr_kinds=["action"],
  23. locations=False,
  24. unblocking=True,
  25. implicit_unlock=False,
  26. **kwargs
  27. )
  28. class SynthS5R2(Synth):
  29. def __init__(self, **kwargs):
  30. super().__init__(room_size=5, num_rows=2, num_cols=2, num_dists=7, **kwargs)
  31. class SynthLoc(LevelGen):
  32. """
  33. Like Synth, but a significant share of object descriptions involves
  34. location language like in PickUpLoc. No implicit unlocking.
  35. Competencies: Maze, Unblock, Unlock, GoTo, PickUp, PutNext, Open, Loc
  36. """
  37. def __init__(self, **kwargs):
  38. # We add many distractors to increase the probability
  39. # of ambiguous locations within the same room
  40. super().__init__(
  41. instr_kinds=["action"],
  42. locations=True,
  43. unblocking=True,
  44. implicit_unlock=False,
  45. **kwargs
  46. )
  47. class SynthSeq(LevelGen):
  48. """
  49. Like SynthLoc, but now with multiple commands, combined just like in GoToSeq.
  50. No implicit unlocking.
  51. Competencies: Maze, Unblock, Unlock, GoTo, PickUp, PutNext, Open, Loc, Seq
  52. """
  53. def __init__(self, **kwargs):
  54. # We add many distractors to increase the probability
  55. # of ambiguous locations within the same room
  56. super().__init__(
  57. locations=True, unblocking=True, implicit_unlock=False, **kwargs
  58. )
  59. class MiniBossLevel(LevelGen):
  60. def __init__(self, **kwargs):
  61. super().__init__(
  62. num_cols=2,
  63. num_rows=2,
  64. room_size=5,
  65. num_dists=7,
  66. locked_room_prob=0.25,
  67. **kwargs
  68. )
  69. class BossLevel(LevelGen):
  70. def __init__(self, **kwargs):
  71. super().__init__(**kwargs)
  72. class BossLevelNoUnlock(LevelGen):
  73. def __init__(self, **kwargs):
  74. super().__init__(locked_room_prob=0, implicit_unlock=False, **kwargs)