Skip to content

Commit

Permalink
Merge pull request #649 from StanfordVL/profiling
Browse files Browse the repository at this point in the history
Profiling
  • Loading branch information
wensi-ai authored Mar 14, 2024
2 parents 317b4e9 + dc82dea commit a90a318
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions tests/benchmark/benchmark_interactive_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import numpy as np

import omnigibson as og
from omnigibson.objects import DatasetObject
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

from omnigibson.utils.constants import PrimType
from omnigibson.systems import get_system

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

Expand All @@ -25,37 +27,63 @@
gm.USE_GPU_DYNAMICS = False
gm.ENABLE_OBJECT_STATES = False
gm.ENABLE_TRANSITION_RULES = False
gm.DEFAULT_VIEWER_WIDTH = 128
gm.DEFAULT_VIEWER_HEIGHT = 128


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


def benchmark_scene(scene_name, optimized=False, import_robot=True):
def benchmark_scene(scene_name, non_rigid_simulation=False, import_robot=True):
assets_version = get_og_assets_version()
print("assets_version", assets_version)
scene = InteractiveTraversableScene(scene_name)
start = time.time()
og.sim.import_scene(scene)

if gm.RENDER_VIEWER_CAMERA:
og.sim.viewer_camera.set_position_orientation([0, 0, 0.2], [0.5, -0.5, -0.5, 0.5])
print(time.time() - start)

if import_robot:
turtlebot = Turtlebot(prim_path="/World/robot", name="agent", obs_modalities=['rgb'])
og.sim.import_object(turtlebot)
og.sim.step()
if scene_name == "restaurant_hotel":
turtlebot.set_position_orientation([-12.2627573, -10.60511875, -3.4790891], [0, 0, 0, 1.0])

if non_rigid_simulation:
cloth = DatasetObject(
name="cloth",
prim_path="/World/cloth",
category="t_shirt",
model="kvidcx",
prim_type=PrimType.CLOTH,
abilities={"cloth": {}},
bounding_box=[0.3, 0.5, 0.7],
)
og.sim.import_object(cloth)
og.sim.step()
water_system = get_system("water")
for i in range(100):
water_system.generate_particles(
positions=[np.array([0.5, 0, 0.5]) + np.random.randn(3) * 0.1]
)
og.sim.step()


og.sim.play()
if non_rigid_simulation:
cloth.set_position([1, 0, 1])
og.sim.step()
fps = []
physics_fps = []
render_fps = []
obj_awake = []
print(len(og.sim.scene.objects))
for i in range(NUM_STEPS):
start = time.time()
if import_robot:
# Apply random actions.
turtlebot.apply_action(turtlebot.action_space.sample())
turtlebot.apply_action(np.zeros(2))
og.sim.step(render=False)
physics_end = time.time()

Expand All @@ -70,15 +98,14 @@ def benchmark_scene(scene_name, optimized=False, import_robot=True):
fps.append(1 / (end - start))
physics_fps.append(1 / (physics_end - start))
render_fps.append(1 / (end - physics_end))
# obj_awake.append(sim.body_links_awake)

plt.figure(figsize=(7, 25))
ax = plt.subplot(6, 1, 1)
plt.hist(render_fps)
ax.set_xlabel("Render fps")
ax.set_title(
"Scene {} version {}\noptimized {} num_obj {}\n import_robot {}".format(
scene_name, assets_version, optimized, scene.n_objects, import_robot
"Scene {} version {}\nnon_physics {} num_obj {}\n import_robot {}".format(
scene_name, assets_version, non_rigid_simulation, scene.n_objects, import_robot
)
)
ax = plt.subplot(6, 1, 2)
Expand All @@ -99,19 +126,15 @@ def benchmark_scene(scene_name, optimized=False, import_robot=True):
plt.plot(fps)
ax.set_xlabel("Overall fps with time, converge to {}".format(np.mean(fps[-100:])))
ax.set_ylabel("fps")
# TODO! Reading objects' wake state not available yet from omniverse
# ax = plt.subplot(6, 1, 6)
# plt.plot(obj_awake)
# ax.set_xlabel("Num object links awake, converge to {}".format(np.mean(obj_awake[-100:])))
plt.tight_layout()
plt.savefig(os.path.join(
OUTPUT_DIR,
"scene_benchmark_{}_o_{}_r_{}.pdf".format(scene_name, optimized, import_robot)))
"scene_benchmark_{}_np_{}_r_{}.pdf".format(scene_name, non_rigid_simulation, import_robot)))


def main():
for scene in SCENES:
benchmark_scene(scene, optimized=True, import_robot=True)
benchmark_scene(scene, non_rigid_simulation=False, import_robot=True)

og.shutdown()

Expand Down

0 comments on commit a90a318

Please sign in to comment.