Skip to content

Commit a816221

Browse files
authored
Merge pull request #644 from StanfordVL/profiling
Speed Improvement & Benchmark
2 parents 7c26717 + 0863051 commit a816221

File tree

4 files changed

+51
-63
lines changed

4 files changed

+51
-63
lines changed

omnigibson/examples/robots/robot_control_example.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ def main(random_selection=False, headless=False, short_exec=False):
7272
options=list(sorted(REGISTERED_ROBOTS.keys())), name="robot", random_selection=random_selection
7373
)
7474

75-
# Create the config for generating the environment we want
76-
env_cfg = dict()
77-
env_cfg["action_frequency"] = 10
78-
env_cfg["physics_frequency"] = 120
79-
8075
scene_cfg = dict()
8176
if scene_model == "empty":
8277
scene_cfg["type"] = "Scene"
@@ -92,7 +87,7 @@ def main(random_selection=False, headless=False, short_exec=False):
9287
robot0_cfg["action_normalize"] = True
9388

9489
# Compile config
95-
cfg = dict(env=env_cfg, scene=scene_cfg, robots=[robot0_cfg])
90+
cfg = dict(scene=scene_cfg, robots=[robot0_cfg])
9691

9792
# Create the environment
9893
env = og.Environment(configs=cfg)

omnigibson/simulator.py

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ def _launch_app():
128128
og_log.set_channel_enabled(channel, False, lazy.omni.log.SettingBehavior.OVERRIDE)
129129

130130
# Possibly hide windows if in debug mode
131+
hide_window_names = []
132+
if not gm.RENDER_VIEWER_CAMERA:
133+
hide_window_names.append("Viewport")
131134
if gm.GUI_VIEWPORT_ONLY:
132-
hide_window_names = ["Console", "Main ToolBar", "Stage", "Layer", "Property", "Render Settings", "Content",
133-
"Flow", "Semantics Schema Editor"]
134-
for name in hide_window_names:
135-
window = lazy.omni.ui.Workspace.get_window(name)
136-
if window is not None:
137-
window.visible = False
138-
app.update()
135+
hide_window_names.extend(["Console", "Main ToolBar", "Stage", "Layer", "Property", "Render Settings", "Content",
136+
"Flow", "Semantics Schema Editor"])
137+
138+
for name in hide_window_names:
139+
window = lazy.omni.ui.Workspace.get_window(name)
140+
if window is not None:
141+
window.visible = False
142+
app.update()
139143

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

@@ -235,9 +239,9 @@ def __init__(
235239
self.clear()
236240

237241
# Set the viewer dimensions
238-
# TODO: Make this toggleable so we don't always have a viewer if we don't want to
239-
self.viewer_width = viewer_width
240-
self.viewer_height = viewer_height
242+
if gm.RENDER_VIEWER_CAMERA:
243+
self.viewer_width = viewer_width
244+
self.viewer_height = viewer_height
241245

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

333337
def _set_renderer_settings(self):
334-
# TODO: For now we are setting these to some reasonable high-performance values but these can be made configurable.
335-
lazy.carb.settings.get_settings().set_bool("/rtx/reflections/enabled", False) # Can be True with a 10fps penalty
336-
lazy.carb.settings.get_settings().set_bool("/rtx/indirectDiffuse/enabled", True) # Can be False with a 5fps gain
337-
lazy.carb.settings.get_settings().set_bool("/rtx/directLighting/sampledLighting/enabled", True)
338+
if gm.ENABLE_HQ_RENDERING:
339+
lazy.carb.settings.get_settings().set_bool("/rtx/reflections/enabled", True)
340+
lazy.carb.settings.get_settings().set_bool("/rtx/indirectDiffuse/enabled", True)
341+
lazy.carb.settings.get_settings().set_int("/rtx/post/dlss/execMode", 3) # "Auto"
342+
lazy.carb.settings.get_settings().set_bool("/rtx/ambientOcclusion/enabled", True)
343+
lazy.carb.settings.get_settings().set_bool("/rtx/directLighting/sampledLighting/enabled", False)
344+
else:
345+
lazy.carb.settings.get_settings().set_bool("/rtx/reflections/enabled", False)
346+
lazy.carb.settings.get_settings().set_bool("/rtx/indirectDiffuse/enabled", False)
347+
lazy.carb.settings.get_settings().set_int("/rtx/post/dlss/execMode", 0) # "Performance"
348+
lazy.carb.settings.get_settings().set_bool("/rtx/ambientOcclusion/enabled", False)
349+
lazy.carb.settings.get_settings().set_bool("/rtx/directLighting/sampledLighting/enabled", True)
338350
lazy.carb.settings.get_settings().set_int("/rtx/raytracing/showLights", 1)
339351
lazy.carb.settings.get_settings().set_float("/rtx/sceneDb/ambientLightIntensity", 0.1)
340-
# 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
341-
# carb.settings.get_settings().set_int("/rtx/domeLight/upperLowerStrategy", 3) # "Limited image-based"
342352

343353
@property
344354
def viewer_visibility(self):
@@ -409,6 +419,7 @@ def enable_viewer_camera_teleoperation(self):
409419
"""
410420
Enables keyboard control of the active viewer camera for this simulation
411421
"""
422+
assert gm.RENDER_VIEWER_CAMERA, "Viewer camera must be enabled to enable teleoperation!"
412423
self._camera_mover = CameraMover(cam=self._viewer_camera)
413424
self._camera_mover.print_info()
414425
return self._camera_mover
@@ -1288,12 +1299,12 @@ def _init_stage(
12881299
self.set_lighting_mode(mode=LightingMode.STAGE)
12891300

12901301
# Set the viewer camera, and then set its default pose
1291-
self._set_viewer_camera()
1292-
self.viewer_camera.set_position_orientation(
1293-
position=np.array(m.DEFAULT_VIEWER_CAMERA_POS),
1294-
orientation=np.array(m.DEFAULT_VIEWER_CAMERA_QUAT),
1295-
)
1296-
self.viewer_visibility = gm.RENDER_VIEWER_CAMERA
1302+
if gm.RENDER_VIEWER_CAMERA:
1303+
self._set_viewer_camera()
1304+
self.viewer_camera.set_position_orientation(
1305+
position=np.array(m.DEFAULT_VIEWER_CAMERA_POS),
1306+
orientation=np.array(m.DEFAULT_VIEWER_CAMERA_QUAT),
1307+
)
12971308

12981309
def close(self):
12991310
"""

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
install_requires=[
2424
"gym~=0.26.2",
2525
"numpy~=1.23.5",
26+
"scipy~=1.10.1",
2627
"GitPython~=3.1.40",
2728
"transforms3d~=0.4.1",
2829
"networkx~=3.2.1",
@@ -41,7 +42,7 @@
4142
"termcolor~=2.4.0",
4243
"progressbar~=2.5",
4344
"pymeshlab~=2022.2",
44-
"click~=8.1.7",
45+
"click~=8.1.3",
4546
"aenum~=3.1.15",
4647
"rtree~=1.2.0"
4748
],

tests/benchmark/benchmark_interactive_scene.py

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,32 @@
22

33
import os
44
import time
5-
65
import matplotlib.pyplot as plt
76
import numpy as np
87

98
import omnigibson as og
109
from omnigibson.macros import gm
1110
from omnigibson.robots.turtlebot import Turtlebot
1211
from omnigibson.scenes.interactive_traversable_scene import InteractiveTraversableScene
12+
from omnigibson.simulator import launch_simulator
1313
from omnigibson.utils.asset_utils import get_og_assets_version
1414

1515

1616
# Params to be set as needed.
17-
SCENES = ["restaurant_hotel"]
17+
SCENES = ["Rs_int"]
1818
OUTPUT_DIR = os.path.join(os.path.expanduser("~"), "Desktop")
1919
NUM_STEPS = 2000
20-
gm.DEFAULT_VIEWER_WIDTH = 128
21-
gm.DEFAULT_VIEWER_HEIGHT = 128
22-
23-
# scenes = ["Beechwood_0_int",
24-
# "Beechwood_1_int",
25-
# "Benevolence_0_int",
26-
# "Benevolence_1_int",
27-
# "Benevolence_2_int",
28-
# "Ihlen_0_int",
29-
# "Ihlen_1_int",
30-
# "Merom_0_int",
31-
# "Merom_1_int",
32-
# "Pomaria_0_int",
33-
# "Pomaria_1_int",
34-
# "Pomaria_2_int",
35-
# "Rs_int",
36-
# "Wainscott_0_int",
37-
# "Wainscott_1_int"]
20+
21+
gm.HEADLESS = False
22+
gm.GUI_VIEWPORT_ONLY = True
23+
gm.RENDER_VIEWER_CAMERA = False
24+
gm.ENABLE_FLATCACHE = True
25+
gm.USE_GPU_DYNAMICS = False
26+
gm.ENABLE_OBJECT_STATES = False
27+
gm.ENABLE_TRANSITION_RULES = False
28+
29+
# Launch the simulator
30+
launch_simulator(physics_dt=1/60., rendering_dt=1/60.)
3831

3932

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

48-
og.sim.viewer_camera.set_position_orientation(
49-
position=np.array([-13.27634359, -12.70026879, -2.68970369]),
50-
orientation=np.array([0.70597155, 0.10758371, 0.10545935, 0.69203196]),
51-
)
52-
53-
# Hide main viewport
54-
og.sim.viewer_visibility = False
55-
5641
if import_robot:
57-
turtlebot = Turtlebot(prim_path="/World/robot", name="agent")
42+
turtlebot = Turtlebot(prim_path="/World/robot", name="agent", obs_modalities=['rgb'])
5843
og.sim.import_object(turtlebot)
5944
og.sim.step()
6045
if scene_name == "restaurant_hotel":
@@ -74,7 +59,7 @@ def benchmark_scene(scene_name, optimized=False, import_robot=True):
7459
og.sim.step(render=False)
7560
physics_end = time.time()
7661

77-
# og.sim.render()
62+
og.sim.render()
7863
end = time.time()
7964

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

126-
from IPython import embed; embed()
127-
128111

129112
def main():
130113
for scene in SCENES:
131114
benchmark_scene(scene, optimized=True, import_robot=True)
132-
# og.sim.stop()
133-
# benchmark_scene(scene, optimized=True, import_robot=False)
134115

135116
og.shutdown()
136117

0 commit comments

Comments
 (0)