synth.py 2.8 KB

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