Skip to content

Commit

Permalink
Merge pull request #644 from StanfordVL/profiling
Browse files Browse the repository at this point in the history
Speed Improvement & Benchmark
  • Loading branch information
wensi-ai authored Mar 12, 2024
2 parents 7c26717 + 0863051 commit a816221
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 63 deletions.
7 changes: 1 addition & 6 deletions omnigibson/examples/robots/robot_control_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ def main(random_selection=False, headless=False, short_exec=False):
options=list(sorted(REGISTERED_ROBOTS.keys())), name="robot", random_selection=random_selection
)

# Create the config for generating the environment we want
env_cfg = dict()
env_cfg["action_frequency"] = 10
env_cfg["physics_frequency"] = 120

scene_cfg = dict()
if scene_model == "empty":
scene_cfg["type"] = "Scene"
Expand All @@ -92,7 +87,7 @@ def main(random_selection=False, headless=False, short_exec=False):
robot0_cfg["action_normalize"] = True

# Compile config
cfg = dict(env=env_cfg, scene=scene_cfg, robots=[robot0_cfg])
cfg = dict(scene=scene_cfg, robots=[robot0_cfg])

# Create the environment
env = og.Environment(configs=cfg)
Expand Down
55 changes: 33 additions & 22 deletions omnigibson/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,18 @@ def _launch_app():
og_log.set_channel_enabled(channel, False, lazy.omni.log.SettingBehavior.OVERRIDE)

# Possibly hide windows if in debug mode
hide_window_names = []
if not gm.RENDER_VIEWER_CAMERA:
hide_window_names.append("Viewport")
if gm.GUI_VIEWPORT_ONLY:
hide_window_names = ["Console", "Main ToolBar", "Stage", "Layer", "Property", "Render Settings", "Content",
"Flow", "Semantics Schema Editor"]
for name in hide_window_names:
window = lazy.omni.ui.Workspace.get_window(name)
if window is not None:
window.visible = False
app.update()
hide_window_names.extend(["Console", "Main ToolBar", "Stage", "Layer", "Property", "Render Settings", "Content",
"Flow", "Semantics Schema Editor"])

for name in hide_window_names:
window = lazy.omni.ui.Workspace.get_window(name)
if window is not None:
window.visible = False
app.update()

lazy.omni.kit.widget.stage.context_menu.ContextMenu.save_prim = print_save_usd_warning

Expand Down Expand Up @@ -235,9 +239,9 @@ def __init__(
self.clear()

# Set the viewer dimensions
# TODO: Make this toggleable so we don't always have a viewer if we don't want to
self.viewer_width = viewer_width
self.viewer_height = viewer_height
if gm.RENDER_VIEWER_CAMERA:
self.viewer_width = viewer_width
self.viewer_height = viewer_height

# Toggle simulator state once so that downstream omni features can be used without bugs
# e.g.: particle sampling, which for some reason requires sim.play() to be called at least once
Expand Down Expand Up @@ -331,14 +335,20 @@ def _set_physics_engine_settings(self):
self._physics_context.set_gpu_max_particle_contacts(gm.GPU_MAX_PARTICLE_CONTACTS)

def _set_renderer_settings(self):
# TODO: For now we are setting these to some reasonable high-performance values but these can be made configurable.
lazy.carb.settings.get_settings().set_bool("/rtx/reflections/enabled", False) # Can be True with a 10fps penalty
lazy.carb.settings.get_settings().set_bool("/rtx/indirectDiffuse/enabled", True) # Can be False with a 5fps gain
lazy.carb.settings.get_settings().set_bool("/rtx/directLighting/sampledLighting/enabled", True)
if gm.ENABLE_HQ_RENDERING:
lazy.carb.settings.get_settings().set_bool("/rtx/reflections/enabled", True)
lazy.carb.settings.get_settings().set_bool("/rtx/indirectDiffuse/enabled", True)
lazy.carb.settings.get_settings().set_int("/rtx/post/dlss/execMode", 3) # "Auto"
lazy.carb.settings.get_settings().set_bool("/rtx/ambientOcclusion/enabled", True)
lazy.carb.settings.get_settings().set_bool("/rtx/directLighting/sampledLighting/enabled", False)
else:
lazy.carb.settings.get_settings().set_bool("/rtx/reflections/enabled", False)
lazy.carb.settings.get_settings().set_bool("/rtx/indirectDiffuse/enabled", False)
lazy.carb.settings.get_settings().set_int("/rtx/post/dlss/execMode", 0) # "Performance"
lazy.carb.settings.get_settings().set_bool("/rtx/ambientOcclusion/enabled", False)
lazy.carb.settings.get_settings().set_bool("/rtx/directLighting/sampledLighting/enabled", True)
lazy.carb.settings.get_settings().set_int("/rtx/raytracing/showLights", 1)
lazy.carb.settings.get_settings().set_float("/rtx/sceneDb/ambientLightIntensity", 0.1)
# TODO: Think of better setting defaults. Below works well for indoor-only scenes, but if skybox is the only light source then this looks very bad
# carb.settings.get_settings().set_int("/rtx/domeLight/upperLowerStrategy", 3) # "Limited image-based"

@property
def viewer_visibility(self):
Expand Down Expand Up @@ -409,6 +419,7 @@ def enable_viewer_camera_teleoperation(self):
"""
Enables keyboard control of the active viewer camera for this simulation
"""
assert gm.RENDER_VIEWER_CAMERA, "Viewer camera must be enabled to enable teleoperation!"
self._camera_mover = CameraMover(cam=self._viewer_camera)
self._camera_mover.print_info()
return self._camera_mover
Expand Down Expand Up @@ -1288,12 +1299,12 @@ def _init_stage(
self.set_lighting_mode(mode=LightingMode.STAGE)

# Set the viewer camera, and then set its default pose
self._set_viewer_camera()
self.viewer_camera.set_position_orientation(
position=np.array(m.DEFAULT_VIEWER_CAMERA_POS),
orientation=np.array(m.DEFAULT_VIEWER_CAMERA_QUAT),
)
self.viewer_visibility = gm.RENDER_VIEWER_CAMERA
if gm.RENDER_VIEWER_CAMERA:
self._set_viewer_camera()
self.viewer_camera.set_position_orientation(
position=np.array(m.DEFAULT_VIEWER_CAMERA_POS),
orientation=np.array(m.DEFAULT_VIEWER_CAMERA_QUAT),
)

def close(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
install_requires=[
"gym~=0.26.2",
"numpy~=1.23.5",
"scipy~=1.10.1",
"GitPython~=3.1.40",
"transforms3d~=0.4.1",
"networkx~=3.2.1",
Expand All @@ -41,7 +42,7 @@
"termcolor~=2.4.0",
"progressbar~=2.5",
"pymeshlab~=2022.2",
"click~=8.1.7",
"click~=8.1.3",
"aenum~=3.1.15",
"rtree~=1.2.0"
],
Expand Down
49 changes: 15 additions & 34 deletions tests/benchmark/benchmark_interactive_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,32 @@

import os
import time

import matplotlib.pyplot as plt
import numpy as np

import omnigibson as og
from omnigibson.macros import gm
from omnigibson.robots.turtlebot import Turtlebot
from omnigibson.scenes.interactive_traversable_scene import InteractiveTraversableScene
from omnigibson.simulator import launch_simulator
from omnigibson.utils.asset_utils import get_og_assets_version


# Params to be set as needed.
SCENES = ["restaurant_hotel"]
SCENES = ["Rs_int"]
OUTPUT_DIR = os.path.join(os.path.expanduser("~"), "Desktop")
NUM_STEPS = 2000
gm.DEFAULT_VIEWER_WIDTH = 128
gm.DEFAULT_VIEWER_HEIGHT = 128

# scenes = ["Beechwood_0_int",
# "Beechwood_1_int",
# "Benevolence_0_int",
# "Benevolence_1_int",
# "Benevolence_2_int",
# "Ihlen_0_int",
# "Ihlen_1_int",
# "Merom_0_int",
# "Merom_1_int",
# "Pomaria_0_int",
# "Pomaria_1_int",
# "Pomaria_2_int",
# "Rs_int",
# "Wainscott_0_int",
# "Wainscott_1_int"]

gm.HEADLESS = False
gm.GUI_VIEWPORT_ONLY = True
gm.RENDER_VIEWER_CAMERA = False
gm.ENABLE_FLATCACHE = True
gm.USE_GPU_DYNAMICS = False
gm.ENABLE_OBJECT_STATES = False
gm.ENABLE_TRANSITION_RULES = False

# Launch the simulator
launch_simulator(physics_dt=1/60., rendering_dt=1/60.)


def benchmark_scene(scene_name, optimized=False, import_robot=True):
Expand All @@ -45,16 +38,8 @@ def benchmark_scene(scene_name, optimized=False, import_robot=True):
og.sim.import_scene(scene)
print(time.time() - start)

og.sim.viewer_camera.set_position_orientation(
position=np.array([-13.27634359, -12.70026879, -2.68970369]),
orientation=np.array([0.70597155, 0.10758371, 0.10545935, 0.69203196]),
)

# Hide main viewport
og.sim.viewer_visibility = False

if import_robot:
turtlebot = Turtlebot(prim_path="/World/robot", name="agent")
turtlebot = Turtlebot(prim_path="/World/robot", name="agent", obs_modalities=['rgb'])
og.sim.import_object(turtlebot)
og.sim.step()
if scene_name == "restaurant_hotel":
Expand All @@ -74,7 +59,7 @@ def benchmark_scene(scene_name, optimized=False, import_robot=True):
og.sim.step(render=False)
physics_end = time.time()

# og.sim.render()
og.sim.render()
end = time.time()

if i % 100 == 0:
Expand Down Expand Up @@ -123,14 +108,10 @@ def benchmark_scene(scene_name, optimized=False, import_robot=True):
OUTPUT_DIR,
"scene_benchmark_{}_o_{}_r_{}.pdf".format(scene_name, optimized, import_robot)))

from IPython import embed; embed()


def main():
for scene in SCENES:
benchmark_scene(scene, optimized=True, import_robot=True)
# og.sim.stop()
# benchmark_scene(scene, optimized=True, import_robot=False)

og.shutdown()

Expand Down

0 comments on commit a816221

Please sign in to comment.