phy-q / benchmark

Phy-Q: A Testbed for Physical Reasoning
https://github.com/phy-q/benchmark
MIT License
40 stars 5 forks source link

KeyError: 'Object' in headless server #7

Closed yueyang130 closed 7 months ago

yueyang130 commented 7 months ago

When I run ./TestPythonHeuristicAgent.sh RandomAgent or ./TrainLearningAgent.sh within_template, it raises the following error:

  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/mnt/bn/yueyang/phyq-benchmark/sciencebirdsagents/HeuristicAgents/HeuristicAgentThread.py", line 23, in run
    self.env.make(agent=self.agent, start_level=self.agent.level_list[0],
  File "/mnt/bn/yueyang/phyq-benchmark/sciencebirdsagents/SBEnvironment/SBEnvironmentWrapper.py", line 122, in make
    self.reload_current_level()
  File "/mnt/bn/yueyang/phyq-benchmark/sciencebirdsagents/SBEnvironment/SBEnvironmentWrapper.py", line 360, in reload_current_level
    self.total_num_birds = self.__get_num_birds(self.env_state)
  File "/mnt/bn/yueyang/phyq-benchmark/sciencebirdsagents/SBEnvironment/SBEnvironmentWrapper.py", line 411, in __get_num_birds
    birds = SymbolicStateDevReader(state, self.model, self.target_class).find_birds()
  File "/mnt/bn/yueyang/phyq-benchmark/sciencebirdsagents/StateReader/SymbolicStateDevReader.py", line 64, in __init__
    self._parseJsonToGameObject()
  File "/mnt/bn/yueyang/phyq-benchmark/sciencebirdsagents/StateReader/SymbolicStateDevReader.py", line 245, in _parseJsonToGameObject
    game_object = GameObject(rect, GameObjectType(self.type_transformer[obj_types[obj_num]]), vertices)
KeyError: 'Object'`

I try to print input json file and found the labels of objects are

['Ground' 'Slingshot' 'Object' 'Object' 'Object' 'Object' 'Object'].

However, the object types are defined as follows, thus raising an error.

self.type_transformer = { 'bird_blue': 'blueBird', 'bird_yellow': 'yellowBird', 'bird_black': 'blackBird', 'bird_red': 'redBird', 'bird_white': 'whiteBird', 'platform': 'platform', 'pig_basic_big': 'pig', 'pig_basic_small': 'pig', 'pig_basic_medium': 'pig', 'TNT': 'TNT', 'Slingshot': 'slingshot', 'ice': 'ice', 'stone': 'stone', 'wood': 'wood', 'unknown': 'unknown', }

I guess 'Object' should be sepcific name such as 'bird_blue' or 'pig_basic_bid' to smoothly run? Simply add 'Object': 'unknown' can avoid error while probably cuasing some other problem for agents I guess. Any help for solving the error would be appreciated!

yueyang130 commented 7 months ago

It seems the problem of initializing server dependent on machine...

When I try to run code in local linux machine instead of cloud cluster, it runs well.

yueyang130 commented 7 months ago

Well, I finally got a workaround for running env with image in headless Linux server, i.e., running virtual display and virtual GUI.

  1. setup virtual display

install sudo apt-get install xvfb

start Xvfb :99 -screen 0 1024x768x24 &

Set the DISPLAY environment variable export DISPLAY=:99

2.setup Windows terminal emulator

install sudo apt-get install xterm

run xterm &

  1. intialize server with xterm, use the following code to replace server setup command

xterm -e "bash -c 'cd ../sciencebirdsgames/{} && java -jar ./game_playing_interface.jar --headless --dev; bash'" &