Hi Guys,
I am just creating an OpenAI Gym RLLib project where the agent needs to learn to place small boxes into different big boxes. Within an observation/run the observation space won’t change but it will be that in every new run it will change. So within one run the observation space is discrete.
So I build the observation space dynamically as a DICT.
class PlacementEnv(gym.Env)
def __init__(self, sb, bb):
self.reward = None
self.smallBoxes = sb
self.bigBoxes = bb
# Define the observation space
i = 1
space_to_observe = {}
for smallbox in self.smallBoxes:
highx = smallbox.pointMax_X
highy = smallbox.pointMax_Y
space_single_smallbox = {
'points_smallbox' + str(i): gym.spaces.Box(low=np.array([0, 0]), high=np.array([highx, highy]),
shape=(2,), dtype=int),
'bbID_smallbox' + str(i): gym.spaces.Discrete(len(self.bigBoxes))}
space_to_observe = space_to_observe | space_single_smallbox
i = i+1
dict_space = gym.spaces.Dict(space_to_observe)
self.observation_space = dict_space
# Define action space
self.action_space = spaces.Tuple((
spaces.Discrete(len(self.bigBoxes)),
spaces.Box(low=0, high=3000, shape=(2,), dtype=int),
spaces.Discrete(8))
))
def reset(self):
i = 0
space_to_observe = {}
for smallbox in self.smallBoxes:
smallbox.bb_id = None
smallbox.insertion_point = (0, 0)
smallbox.rotation_angle = 0
highx = smallbox.pointMax_X
highy = smallbox.pointMax_Y
space_single_smallbox = {
'points_smallbox' + str(i): gym.spaces.Box(low=np.array([0, 0]), high=np.array([highx, highy]),
shape=(2,), dtype=int),
'bbID_smallbox' + str(i): gym.spaces.Discrete(len(self.bigBoxes))}
space_to_observe = space_to_observe | space_single_smallbox
i = i+1
dict_space = gym.spaces.Dict(space_to_observe)
self.observation_space = dict_space
return self.observation_space
Now when I run it I get the following eror:
AssertionError: ERROR:
elem
(Box(0, 2, (2,), int16)) must be np.array, float or int!
I think it is based on that line:
gym.spaces.Box(low=np.array([0, 0]), high=np.array([highx, highy]), shape=(2,), dtype=int)
But even when I put: low=0 and high = 5 it produces the same error
I am totaly lost now and Internet and even ChatGPT are not helpful anymore.
I am absolute beginner to Python and OpenAI Gym/RLLib. This is my first project.
Thanks for any helpful reply.