xavierpuigf / virtualhome

API to run VirtualHome, a Multi-Agent Household Simulator
http://virtual-home.org
MIT License
487 stars 66 forks source link

How to get environment_graph after rander_script() ? #89

Open Xianqi-Zhang opened 1 year ago

Xianqi-Zhang commented 1 year ago

Hi I use comm.render_script() to execute actions and comm.environment_graph() to get state infromation, but the state (environment_graph) is not changed.

import sys
sys.path.append('./virtualhome/simulation')
sys.path.append('./virtualhome/dataset_utils')
from virtualhome.simulation.unity_simulator.comm_unity import UnityCommunication

if __name__ == '__main__':
    exec_file_path = './virtualhome/linux_exec.v2.3.0.x86_64'
    comm = UnityCommunication(file_name=exec_file_path, port='8080', x_display='0')

    print('Loading graph')
    comm.reset(0)
    comm.add_character()
    _, initial_graph = comm.environment_graph()

    tv_node = [x for x in initial_graph['nodes'] if x['class_name'] == 'tv'][0]
    tv_id = tv_node['id']

    script = [
        '<char0> [Walk] <tv> ({})'.format(tv_id),
        '<char0> [SwitchOn] <tv> ({})'.format(tv_id)
    ]

    print('--' * 20)
    print('tv_node: {}'.format(tv_node))
    print('tv state before script: {}'.format(tv_node['states']))
    print('--' * 20)

    success, message = comm.render_script(script=script,
                                          processing_time_limit=60,
                                          find_solution=False,
                                          image_width=320,
                                          image_height=240,
                                          skip_animation=False,
                                          recording=True,
                                          save_pose_data=True,
                                          file_name_prefix='test_vh')
    print(success, message)

    success, final_graph = comm.environment_graph()

    print('--' * 20)
    tv_node_final = [x for x in final_graph['nodes'] if x['class_name'] == 'tv'][0]
    print('tv_node: {}'.format(tv_node_final))
    print('tv state after script: {}'.format(tv_node_final['states']))
    print('--' * 20)

Output:

Getting connection...
Loading graph
----------------------------------------
tv_node: {'id': 264, 'category': 'Electronics', 'class_name': 'tv', 'prefab_name': 'PRE_ELE_TV_01', 'obj_transform': {'position': [-1.704, 0.495, -8.825], 'rotation': [0.0, -0.7070805, 0.0, 0.7071332], 'scale': [0.531408548, 0.531408548, 0.531408548]}, 'bounding_box': {'center': [-1.70399857, 0.834420145, -8.825], 'size': [0.912024, 0.6788422, 0.1941805]}, 'properties': ['HAS_SWITCH', 'LOOKABLE', 'HAS_PLUG'], 'states': ['OFF']}
tv state before script: ['OFF']
----------------------------------------
True {'0': {'message': 'Success'}}
----------------------------------------
tv_node: {'id': 264, 'category': 'Electronics', 'class_name': 'tv', 'prefab_name': 'PRE_ELE_TV_01', 'obj_transform': {'position': [-1.704, 0.495, -8.825], 'rotation': [0.0, -0.7070805, 0.0, 0.7071332], 'scale': [0.531408548, 0.531408548, 0.531408548]}, 'bounding_box': {'center': [-1.70399857, 0.834420145, -8.825], 'size': [0.912024, 0.6788422, 0.1941805]}, 'properties': ['HAS_SWITCH', 'LOOKABLE', 'HAS_PLUG'], 'states': ['OFF']}
tv state after script: ['OFF']
----------------------------------------

The state of tv is not changed to ON, despite the message is 'Success'. So, how to get environment_graph after rander_script() ?

Thank you for your any replay.

xavierpuigf commented 1 year ago

Seems like a bug. Could you try exeucting the script one step at a time, and looking at the graph differences? Could you check whether the character position(the position of the char node) changes between the init and end graph?

Alexandara commented 6 months ago

I am encountering the same issue. The character position does change, however the TV does not update to be "ON" (despite the TV being visibly on in the simulation).

gmt20 commented 2 months ago

I am facing the same issue. There is no difference character position or the TV state in initial and final graphs. Although the simulation output images show the change in character position and TV being ON. Did anyone find a solution for this bug?

Loading` graph
----------------------------------------
tv_node: {'id': 264, 'category': 'Electronics', 'class_name': 'tv', 'prefab_name': 'PRE_ELE_TV_01', 'obj_transform': {'position': [-1.704, 0.495, -8.825], 'rotation': [0.0, -0.7070805, 0.0, 0.7071332], 'scale': [0.531408548, 0.531408548, 0.531408548]}, 'bounding_box': {'center': [-1.70399857, 0.834420145, -8.825], 'size': [0.912024, 0.6788422, 0.1941805]}, 'properties': ['HAS_SWITCH', 'LOOKABLE', 'HAS_PLUG'], 'states': ['OFF']}
tv state before script: ['OFF']
----------------------------------------
----------------------------------------
character_node: {'id': 1, 'category': 'Characters', 'class_name': 'character', 'prefab_name': 'Male1', 'obj_transform': {'position': [4.11006451, 1.25, -4.83880663], 'rotation': [0.0, -0.484741, 0.0, 0.87465775], 'scale': [1.0, 1.0, 1.0]}, 'bounding_box': {'center': [4.129957, 2.121052, -4.851241], 'size': [1.15185833, 1.86971855, 1.41674614]}, 'properties': [], 'states': []}
character position before script: [4.11006451, 1.25, -4.83880663]
----------------------------------------
in render script ['<char0> [Walk] <tv> (264)', '<char0> [SwitchOn] <tv> (264)']
message form unity simulator {'0': {'message': 'Success'}}
True {'0': {'message': 'Success'}}
----------------------------------------
tv_node: {'id': 264, 'category': 'Electronics', 'class_name': 'tv', 'prefab_name': 'PRE_ELE_TV_01', 'obj_transform': {'position': [-1.704, 0.495, -8.825], 'rotation': [0.0, -0.7070805, 0.0, 0.7071332], 'scale': [0.531408548, 0.531408548, 0.531408548]}, 'bounding_box': {'center': [-1.70399857, 0.834420145, -8.825], 'size': [0.912024, 0.6788422, 0.1941805]}, 'properties': ['HAS_SWITCH', 'LOOKABLE', 'HAS_PLUG'], 'states': ['OFF']}
tv state after script: ['OFF']
----------------------------------------
----------------------------------------
character_node: {'id': 1, 'category': 'Characters', 'class_name': 'character', 'prefab_name': 'Male1', 'obj_transform': {'position': [4.11006451, 1.25, -4.83880663], 'rotation': [0.0, -0.484741, 0.0, 0.87465775], 'scale': [1.0, 1.0, 1.0]}, 'bounding_box': {'center': [-2.11021233, 0.865708947, -8.02998352], 'size': [1.42151368, 1.87983155, 1.02503109]}, 'properties': [], 'states': []}
character position after script: [4.11006451, 1.25, -4.83880663]
----------------------------------------