diff --git a/README.md b/README.md index 87840f385..e45b277db 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,9 @@ print(lengths) ## Running Examples -The `examples` directory contains a number of scripts that show how to implement different simulation methods using the Warp API. Most examples will generate USD files containing time-sampled animations (stored in the current working directory). Before running examples, users should ensure that the ``usd-core`` and ``matplotlib`` packages are installed using: +The `examples` directory contains a number of scripts that show how to implement different simulation methods using the Warp API. Most examples will generate USD files containing time-sampled animations (stored in the current working directory). Before running examples, users should ensure that the ``usd-core``, ``matplotlib``, and ``pyglet`` packages are installed using: - pip install usd-core matplotlib + pip install usd-core matplotlib pyglet Examples can be run from the command-line as follows: diff --git a/warp/examples/__init__.py b/warp/examples/__init__.py index e4eeb519c..66efdea19 100644 --- a/warp/examples/__init__.py +++ b/warp/examples/__init__.py @@ -12,5 +12,5 @@ def get_source_directory(): return os.path.realpath(os.path.dirname(__file__)) -def get_output_directory(): - return os.getcwd() +def get_asset_directory(): + return os.path.join(get_source_directory(), "assets") diff --git a/warp/examples/benchmarks/benchmark.bat b/warp/examples/benchmarks/benchmark.bat index 800f28135..9edec17de 100644 --- a/warp/examples/benchmarks/benchmark.bat +++ b/warp/examples/benchmarks/benchmark.bat @@ -1,15 +1,13 @@ -del outputs\benchmark.csv +del benchmark.csv python benchmark_cloth.py warp_cpu python benchmark_cloth.py warp_gpu -python benchmark_cloth.py taichi_cpu -python benchmark_cloth.py taichi_gpu +@REM python benchmark_cloth.py taichi_cpu +@REM python benchmark_cloth.py taichi_gpu python benchmark_cloth.py numpy -python benchmark_cloth.py cupy -python benchmark_cloth.py torch_cpu -python benchmark_cloth.py torch_gpu -python benchmark_cloth.py numba -python benchmark_cloth.py jax_cpu -python benchmark_cloth.py jax_gpu - - +@REM python benchmark_cloth.py cupy +@REM python benchmark_cloth.py torch_cpu +@REM python benchmark_cloth.py torch_gpu +@REM python benchmark_cloth.py numba +@REM python benchmark_cloth.py jax_cpu +@REM python benchmark_cloth.py jax_gpu diff --git a/warp/examples/benchmarks/benchmark.sh b/warp/examples/benchmarks/benchmark.sh old mode 100644 new mode 100755 index d37c8ab9e..f82289a67 --- a/warp/examples/benchmarks/benchmark.sh +++ b/warp/examples/benchmarks/benchmark.sh @@ -1,10 +1,10 @@ -rm outputs/benchmark.csv +rm benchmark.csv python3 benchmark_cloth.py warp_cpu python3 benchmark_cloth.py warp_gpu # python3 benchmark_cloth.py taichi_cpu # python3 benchmark_cloth.py taichi_gpu -# python3 benchmark_cloth.py numpy +python3 benchmark_cloth.py numpy # python3 benchmark_cloth.py cupy # python3 benchmark_cloth.py torch_cpu # python3 benchmark_cloth.py torch_gpu diff --git a/warp/examples/benchmarks/benchmark_cloth.py b/warp/examples/benchmarks/benchmark_cloth.py index 5780ae1ef..bf3287a4a 100644 --- a/warp/examples/benchmarks/benchmark_cloth.py +++ b/warp/examples/benchmarks/benchmark_cloth.py @@ -9,10 +9,8 @@ import os import sys, getopt import numpy as np -import math -import ctypes -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "."))) from pxr import Usd, UsdGeom, Gf, Sdf @@ -149,7 +147,7 @@ def run_benchmark(mode, dim, timers, render=False): if render: # set up grid for visualization - stage = Usd.Stage.CreateNew(os.path.join(os.path.dirname(__file__), "outputs/benchmark.usd")) + stage = Usd.Stage.CreateNew("benchmark.usd") stage.SetStartTimeCode(0.0) stage.SetEndTimeCode(sim_duration * sim_fps) stage.SetTimeCodesPerSecond(sim_fps) @@ -161,63 +159,63 @@ def run_benchmark(mode, dim, timers, render=False): with wp.ScopedTimer("Initialization", dict=timers): if mode == "warp_cpu": - import examples.benchmark_cloth_warp + import benchmark_cloth_warp - integrator = examples.benchmark_cloth_warp.WpIntegrator(cloth, "cpu") + integrator = benchmark_cloth_warp.WpIntegrator(cloth, "cpu") elif mode == "warp_gpu": - import examples.benchmark_cloth_warp + import benchmark_cloth_warp - integrator = examples.benchmark_cloth_warp.WpIntegrator(cloth, "cuda") + integrator = benchmark_cloth_warp.WpIntegrator(cloth, "cuda") elif mode == "taichi_cpu": - import examples.benchmark_cloth_taichi + import benchmark_cloth_taichi - integrator = examples.benchmark_cloth_taichi.TiIntegrator(cloth, "cpu") + integrator = benchmark_cloth_taichi.TiIntegrator(cloth, "cpu") elif mode == "taichi_gpu": - import examples.benchmark_cloth_taichi + import benchmark_cloth_taichi - integrator = examples.benchmark_cloth_taichi.TiIntegrator(cloth, "cuda") + integrator = benchmark_cloth_taichi.TiIntegrator(cloth, "cuda") elif mode == "numpy": - import examples.benchmark_cloth_numpy + import benchmark_cloth_numpy - integrator = examples.benchmark_cloth_numpy.NpIntegrator(cloth) + integrator = benchmark_cloth_numpy.NpIntegrator(cloth) elif mode == "cupy": - import examples.benchmark_cloth_cupy + import benchmark_cloth_cupy - integrator = examples.benchmark_cloth_cupy.CpIntegrator(cloth) + integrator = benchmark_cloth_cupy.CpIntegrator(cloth) elif mode == "numba": - import examples.benchmark_cloth_numba + import benchmark_cloth_numba - integrator = examples.benchmark_cloth_numba.NbIntegrator(cloth) + integrator = benchmark_cloth_numba.NbIntegrator(cloth) elif mode == "torch_cpu": - import examples.benchmark_cloth_pytorch + import benchmark_cloth_pytorch - integrator = examples.benchmark_cloth_pytorch.TrIntegrator(cloth, "cpu") + integrator = benchmark_cloth_pytorch.TrIntegrator(cloth, "cpu") elif mode == "torch_gpu": - import examples.benchmark_cloth_pytorch + import benchmark_cloth_pytorch - integrator = examples.benchmark_cloth_pytorch.TrIntegrator(cloth, "cuda") + integrator = benchmark_cloth_pytorch.TrIntegrator(cloth, "cuda") elif mode == "jax_cpu": os.environ["JAX_PLATFORM_NAME"] = "cpu" - import examples.benchmark_cloth_jax + import benchmark_cloth_jax - integrator = examples.benchmark_cloth_jax.JxIntegrator(cloth) + integrator = benchmark_cloth_jax.JxIntegrator(cloth) elif mode == "jax_gpu": os.environ["JAX_PLATFORM_NAME"] = "gpu" - import examples.benchmark_cloth_jax + import benchmark_cloth_jax - integrator = examples.benchmark_cloth_jax.JxIntegrator(cloth) + integrator = benchmark_cloth_jax.JxIntegrator(cloth) else: raise RuntimeError("Unknown simulation backend") @@ -260,7 +258,7 @@ def run_benchmark(mode, dim, timers, render=False): for k, v in timers.items(): print("{:16} min: {:8.2f} max: {:8.2f} avg: {:8.2f}".format(k, np.min(v), np.max(v), np.mean(v))) -report = open(os.path.join(os.path.dirname(__file__), "outputs/benchmark.csv"), "a") +report = open(os.path.join("benchmark.csv"), "a") writer = csv.writer(report, delimiter=",") if report.tell() == 0: diff --git a/warp/examples/browse.py b/warp/examples/browse.py index a149a685f..b7dd0835f 100644 --- a/warp/examples/browse.py +++ b/warp/examples/browse.py @@ -20,7 +20,7 @@ def open_file(filename): if __name__ == "__main__": import warp.examples - source_dir = wp.examples.get_source_directory() + source_dir = warp.examples.get_source_directory() print(f"Example source directory: {source_dir}") try: diff --git a/warp/examples/core/example_dem.py b/warp/examples/core/example_dem.py index 76035bb0c..8af131dd2 100644 --- a/warp/examples/core/example_dem.py +++ b/warp/examples/core/example_dem.py @@ -14,8 +14,6 @@ # ########################################################################### -import os - import numpy as np import warp as wp @@ -209,9 +207,7 @@ def particle_grid(self, dim_x, dim_y, dim_z, lower, radius, jitter): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_dem.usd") + stage_path = "example_dem.usd" example = Example(stage_path) diff --git a/warp/examples/core/example_marching_cubes.py b/warp/examples/core/example_marching_cubes.py index fad981a08..5e313b34a 100644 --- a/warp/examples/core/example_marching_cubes.py +++ b/warp/examples/core/example_marching_cubes.py @@ -15,7 +15,6 @@ ########################################################################### -import os from typing import Optional import warp as wp @@ -163,10 +162,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - this_file = os.path.basename(__file__).split(".")[0] - stage_path = os.path.join(wp.examples.get_output_directory(), f"{this_file}.usd") + stage_path = "example_marching_cubes.usd" example = Example(stage_path) for _ in range(240): diff --git a/warp/examples/core/example_mesh.py b/warp/examples/core/example_mesh.py index 118e53445..cf735d5f5 100644 --- a/warp/examples/core/example_mesh.py +++ b/warp/examples/core/example_mesh.py @@ -21,6 +21,7 @@ from pxr import Usd, UsdGeom import warp as wp +import warp.examples import warp.render wp.init() @@ -93,7 +94,7 @@ def __init__(self, stage): self.sim_margin = 0.1 - usd_stage = Usd.Stage.Open(os.path.join(os.path.dirname(__file__), "../assets/bunny.usd")) + usd_stage = Usd.Stage.Open(os.path.join(warp.examples.get_asset_directory(), "bunny.usd")) usd_geom = UsdGeom.Mesh(usd_stage.GetPrimAtPath("/bunny/bunny")) usd_scale = 10.0 @@ -142,9 +143,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_mesh.usd") + stage_path = "example_mesh.usd" example = Example(stage_path) diff --git a/warp/examples/core/example_mesh_intersect.py b/warp/examples/core/example_mesh_intersect.py index fc1347bcd..3400a18f3 100644 --- a/warp/examples/core/example_mesh_intersect.py +++ b/warp/examples/core/example_mesh_intersect.py @@ -18,6 +18,7 @@ from pxr import Usd, UsdGeom import warp as wp +import warp.examples import warp.render @@ -86,8 +87,8 @@ def __init__(self, stage): self.query_count = 1024 self.has_queried = False - self.path_0 = "../assets/cube.usda" - self.path_1 = "../assets/sphere.usda" + self.path_0 = os.path.join(warp.examples.get_asset_directory(), "cube.usda") + self.path_1 = os.path.join(warp.examples.get_asset_directory(), "sphere.usda") self.mesh_0 = self.load_mesh(self.path_0, "/Cube/Cube_001") self.mesh_1 = self.load_mesh(self.path_1, "/Sphere/Sphere") @@ -143,14 +144,14 @@ def render(self): xform = self.xforms[i] self.renderer.render_ref( f"mesh_{i}_0", - os.path.join(os.path.dirname(__file__), self.path_0), + self.path_0, pos=wp.vec3(xform.p[0] + offset, xform.p[1], xform.p[2]), rot=xform.q, scale=wp.vec3(1.0, 1.0, 1.0), ) self.renderer.render_ref( f"mesh_{i}_1", - os.path.join(os.path.dirname(__file__), self.path_1), + self.path_1, pos=wp.vec3(offset, 0.0, 0.0), rot=wp.quat_identity(), scale=wp.vec3(1.0, 1.0, 1.0), @@ -169,8 +170,7 @@ def render(self): # create collision meshes def load_mesh(self, path, prim): - usd_path = os.path.join(os.path.dirname(__file__), path) - usd_stage = Usd.Stage.Open(usd_path) + usd_stage = Usd.Stage.Open(path) usd_geom = UsdGeom.Mesh(usd_stage.GetPrimAtPath(prim)) mesh = wp.Mesh( @@ -182,9 +182,7 @@ def load_mesh(self, path, prim): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_mesh_intersect.usd") + stage_path = "example_mesh_intersect.usd" example = Example(stage_path) diff --git a/warp/examples/core/example_nvdb.py b/warp/examples/core/example_nvdb.py index a3bf95cf9..0cedc64bc 100644 --- a/warp/examples/core/example_nvdb.py +++ b/warp/examples/core/example_nvdb.py @@ -21,6 +21,7 @@ import numpy as np import warp as wp +import warp.examples import warp.render wp.init() @@ -108,7 +109,7 @@ def __init__(self, stage): self.velocities = wp.from_numpy(init_vel.astype(np.float32), dtype=wp.vec3) # load collision volume - file = open(os.path.join(os.path.dirname(__file__), "../assets/rocks.nvdb"), "rb") + file = open(os.path.join(warp.examples.get_asset_directory(), "rocks.nvdb"), "rb") # create Volume object self.volume = wp.Volume.load_from_nvdb(file) @@ -146,7 +147,7 @@ def render(self): self.renderer.render_ref( name="collision", - path=os.path.join(os.path.dirname(__file__), "../assets/rocks.usd"), + path=os.path.join(warp.examples.get_asset_directory(), "rocks.usd"), pos=wp.vec3(0.0, 0.0, 0.0), rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), math.pi), scale=wp.vec3(1.0, 1.0, 1.0), @@ -157,9 +158,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_nvdb.usd") + stage_path = "example_nvdb.usd" example = Example(stage_path) diff --git a/warp/examples/core/example_raycast.py b/warp/examples/core/example_raycast.py index a58143a75..14e87effe 100644 --- a/warp/examples/core/example_raycast.py +++ b/warp/examples/core/example_raycast.py @@ -19,6 +19,7 @@ from pxr import Usd, UsdGeom import warp as wp +import warp.examples wp.init() @@ -52,7 +53,7 @@ def __init__(self, **kwargs): self.height = 1024 self.cam_pos = (0.0, 1.0, 2.0) - asset_stage = Usd.Stage.Open(os.path.join(os.path.dirname(__file__), "../assets/bunny.usd")) + asset_stage = Usd.Stage.Open(os.path.join(warp.examples.get_asset_directory(), "bunny.usd")) mesh_geom = UsdGeom.Mesh(asset_stage.GetPrimAtPath("/bunny/bunny")) points = np.array(mesh_geom.GetPointsAttr().Get()) diff --git a/warp/examples/core/example_sph.py b/warp/examples/core/example_sph.py index 1b2a69ecf..3eca1fb04 100644 --- a/warp/examples/core/example_sph.py +++ b/warp/examples/core/example_sph.py @@ -20,8 +20,6 @@ # ########################################################################### -import os - import numpy as np import warp as wp @@ -377,9 +375,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_sph.usd") + stage_path = "example_sph.usd" example = Example(stage_path) diff --git a/warp/examples/core/example_wave.py b/warp/examples/core/example_wave.py index 83e3b7a65..4b404adb4 100644 --- a/warp/examples/core/example_wave.py +++ b/warp/examples/core/example_wave.py @@ -14,7 +14,6 @@ ########################################################################### import math -import os import warp as wp import warp.render @@ -237,9 +236,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_wave.usd") + stage_path = "example_wave.usd" example = Example(stage_path) diff --git a/warp/examples/fem/example_apic_fluid.py b/warp/examples/fem/example_apic_fluid.py index ab1e445a0..83acb092e 100644 --- a/warp/examples/fem/example_apic_fluid.py +++ b/warp/examples/fem/example_apic_fluid.py @@ -11,8 +11,6 @@ # Shows how to implement a apic fluid simulation. ########################################################################### -import os - import warp as wp import numpy as np @@ -378,11 +376,9 @@ def render(self, is_live=False): if __name__ == "__main__": - import warp.examples - wp.set_module_options({"enable_backward": False}) - stage_path = os.path.join(wp.examples.get_output_directory(), "example_apic_fluid.usd") + stage_path = "example_apic_fluid.usd" example = Example(stage_path) diff --git a/warp/examples/optim/example_bounce.py b/warp/examples/optim/example_bounce.py index a8041fba4..2e567d815 100644 --- a/warp/examples/optim/example_bounce.py +++ b/warp/examples/optim/example_bounce.py @@ -17,8 +17,6 @@ # ########################################################################### -import os - import numpy as np import warp as wp @@ -233,9 +231,7 @@ def check_grad(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_bounce.usd") + stage_path = "example_bounce.usd" example = Example(stage_path, profile=False, verbose=True) example.check_grad() diff --git a/warp/examples/optim/example_cloth_throw.py b/warp/examples/optim/example_cloth_throw.py index ca9eeca8c..dd091993e 100644 --- a/warp/examples/optim/example_cloth_throw.py +++ b/warp/examples/optim/example_cloth_throw.py @@ -18,7 +18,6 @@ ########################################################################### import math -import os import warp as wp import warp.sim @@ -196,9 +195,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_cloth_throw.usd") + stage_path = "example_cloth_throw.usd" example = Example(stage_path, profile=False, verbose=True) diff --git a/warp/examples/optim/example_diffray.py b/warp/examples/optim/example_diffray.py index b20e3c483..291b0efae 100644 --- a/warp/examples/optim/example_diffray.py +++ b/warp/examples/optim/example_diffray.py @@ -20,6 +20,7 @@ from pxr import Usd, UsdGeom import warp as wp +import warp.examples from warp.optim import SGD wp.init() @@ -308,7 +309,7 @@ def __init__(self, stage=None, rot_array=[0.0, 0.0, 0.0, 1.0], verbose=False): self.width = int(aspect * self.height) self.num_pixels = self.width * self.height - asset_stage = Usd.Stage.Open(os.path.join(os.path.dirname(__file__), "../assets/bunny.usd")) + asset_stage = Usd.Stage.Open(os.path.join(warp.examples.get_asset_directory(), "bunny.usd")) mesh_geom = UsdGeom.Mesh(asset_stage.GetPrimAtPath("/bunny/bunny")) points = np.array(mesh_geom.GetPointsAttr().Get()) diff --git a/warp/examples/optim/example_drone.py b/warp/examples/optim/example_drone.py index c45d84f72..07c56942e 100644 --- a/warp/examples/optim/example_drone.py +++ b/warp/examples/optim/example_drone.py @@ -21,6 +21,7 @@ from pxr import UsdGeom import warp as wp +import warp.examples import warp.optim import warp.sim import warp.sim.render @@ -817,11 +818,8 @@ def render(self): if __name__ == "__main__": - import warp.examples - - this_dir = os.path.realpath(os.path.dirname(__file__)) - stage_path = os.path.join(wp.examples.get_output_directory(), "example_drone.usd") - drone_path = os.path.join(this_dir, "..", "assets", "crazyflie.usd") + drone_path = os.path.join(warp.examples.get_asset_directory(), "crazyflie.usd") + stage_path = "example_drone.usd" example = Example(stage_path, drone_path, verbose=True) for i in range(example.frame_count): diff --git a/warp/examples/optim/example_inverse_kinematics.py b/warp/examples/optim/example_inverse_kinematics.py index 04eae0ee5..1a3d25351 100644 --- a/warp/examples/optim/example_inverse_kinematics.py +++ b/warp/examples/optim/example_inverse_kinematics.py @@ -13,8 +13,6 @@ # ########################################################################### -import os - import numpy as np import warp as wp @@ -156,9 +154,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_inverse_kinematics.usd") + stage_path = "example_inverse_kinematics.usd" example = Example(stage_path, device=wp.get_preferred_device(), verbose=True) diff --git a/warp/examples/optim/example_inverse_kinematics_torch.py b/warp/examples/optim/example_inverse_kinematics_torch.py index 85961fe68..063f63e32 100644 --- a/warp/examples/optim/example_inverse_kinematics_torch.py +++ b/warp/examples/optim/example_inverse_kinematics_torch.py @@ -14,8 +14,6 @@ # ########################################################################### -import os - import numpy as np import torch @@ -157,9 +155,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_inverse_kinematics_torch.usd") + stage_path = "example_inverse_kinematics_torch.usd" example = Example(stage_path, device=wp.get_preferred_device(), verbose=True) diff --git a/warp/examples/optim/example_spring_cage.py b/warp/examples/optim/example_spring_cage.py index c92f58ed0..617118399 100644 --- a/warp/examples/optim/example_spring_cage.py +++ b/warp/examples/optim/example_spring_cage.py @@ -14,8 +14,6 @@ # ########################################################################### -import os - import numpy as np import warp as wp @@ -214,9 +212,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_spring_cage.usd") + stage_path = "example_spring_cage.usd" example = Example(stage_path, verbose=True) diff --git a/warp/examples/optim/example_trajectory.py b/warp/examples/optim/example_trajectory.py index 6559ffa11..6f18e8df1 100644 --- a/warp/examples/optim/example_trajectory.py +++ b/warp/examples/optim/example_trajectory.py @@ -14,8 +14,6 @@ ########################################################################### -import os - import numpy as np import warp as wp @@ -173,10 +171,9 @@ def render(self): if __name__ == "__main__": - import warp.examples import matplotlib.pyplot as plt - stage_path = os.path.join(wp.examples.get_output_directory(), "example_trajectory.usd") + stage_path = "example_trajectory.usd" example = Example(stage_path, verbose=True) diff --git a/warp/examples/optim/example_walker.py b/warp/examples/optim/example_walker.py index 21bde5ebf..48fb50721 100644 --- a/warp/examples/optim/example_walker.py +++ b/warp/examples/optim/example_walker.py @@ -21,6 +21,7 @@ import math import warp as wp +import warp.examples import warp.sim import warp.optim import warp.sim.render @@ -92,7 +93,7 @@ def __init__(self, stage=None, profile=False, verbose=False): self.render_time = 0.0 # bear - asset_stage = Usd.Stage.Open(os.path.join(os.path.dirname(__file__), "../assets/bear.usd")) + asset_stage = Usd.Stage.Open(os.path.join(warp.examples.get_asset_directory(), "bear.usd")) geom = UsdGeom.Mesh(asset_stage.GetPrimAtPath("/bear")) points = geom.GetPointsAttr().Get() @@ -280,9 +281,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_walker.usd") + stage_path = "example_walker.usd" example = Example(stage_path, profile=False, verbose=True) diff --git a/warp/examples/sim/example_cartpole.py b/warp/examples/sim/example_cartpole.py index 27c71fa5d..75eabec27 100644 --- a/warp/examples/sim/example_cartpole.py +++ b/warp/examples/sim/example_cartpole.py @@ -20,6 +20,7 @@ import numpy as np import warp as wp +import warp.examples import warp.sim import warp.sim.render @@ -35,7 +36,7 @@ def __init__(self, stage=None, num_envs=1, print_timers=True): articulation_builder = wp.sim.ModelBuilder() wp.sim.parse_urdf( - os.path.join(os.path.dirname(__file__), "../assets/cartpole.urdf"), + os.path.join(warp.examples.get_asset_directory(), "cartpole.urdf"), articulation_builder, xform=wp.transform(wp.vec3(), wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)), floating=False, @@ -116,9 +117,9 @@ def render(self): if __name__ == "__main__": - stage = os.path.join(os.path.dirname(__file__), "example_cartpole.usd") + stage_path = "example_cartpole.usd" - example = Example(stage, num_envs=10) + example = Example(stage_path, num_envs=10) for _ in range(example.episode_frames): example.step() diff --git a/warp/examples/sim/example_cloth.py b/warp/examples/sim/example_cloth.py index 926719fe2..d3a6e8534 100644 --- a/warp/examples/sim/example_cloth.py +++ b/warp/examples/sim/example_cloth.py @@ -21,6 +21,7 @@ from pxr import Usd, UsdGeom import warp as wp +import warp.examples import warp.sim import warp.sim.render @@ -85,7 +86,7 @@ def __init__(self, stage, integrator=IntegratorType.EULER): spring_kd=0.0, ) - usd_stage = Usd.Stage.Open(os.path.join(os.path.dirname(__file__), "../assets/bunny.usd")) + usd_stage = Usd.Stage.Open(os.path.join(warp.examples.get_asset_directory(), "bunny.usd")) usd_geom = UsdGeom.Mesh(usd_stage.GetPrimAtPath("/bunny/bunny")) mesh_points = np.array(usd_geom.GetPointsAttr().Get()) @@ -158,7 +159,6 @@ def render(self): if __name__ == "__main__": import argparse - import warp.examples parser = argparse.ArgumentParser() parser.add_argument( @@ -171,7 +171,7 @@ def render(self): args = parser.parse_args() - stage_path = os.path.join(wp.examples.get_output_directory(), "example_cloth.usd") + stage_path = "example_cloth.usd" example = Example(stage_path, integrator=args.integrator) diff --git a/warp/examples/sim/example_granular.py b/warp/examples/sim/example_granular.py index 6af8ba17f..c66071529 100644 --- a/warp/examples/sim/example_granular.py +++ b/warp/examples/sim/example_granular.py @@ -13,8 +13,6 @@ # ########################################################################### -import os - import warp as wp import warp.sim import warp.sim.render @@ -101,9 +99,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_granular.usd") + stage_path = "example_granular.usd" example = Example(stage_path) diff --git a/warp/examples/sim/example_granular_collision_sdf.py b/warp/examples/sim/example_granular_collision_sdf.py index b46254dcd..168e5e611 100644 --- a/warp/examples/sim/example_granular_collision_sdf.py +++ b/warp/examples/sim/example_granular_collision_sdf.py @@ -21,6 +21,7 @@ import numpy as np import warp as wp +import warp.examples import warp.sim import warp.sim.render @@ -55,7 +56,7 @@ def __init__(self, stage): mass=0.1, jitter=self.radius * 0.1, ) - rock_file = open(os.path.join(os.path.dirname(__file__), "../assets/rocks.nvdb"), "rb") + rock_file = open(os.path.join(warp.examples.get_asset_directory(), "rocks.nvdb"), "rb") rock_vdb = wp.Volume.load_from_nvdb(rock_file.read()) rock_file.close() @@ -154,7 +155,7 @@ def render(self): # Note the extra wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), math.pi) is because .usd is oriented differently from .nvdb self.renderer.render_ref( name="collision", - path=os.path.join(os.path.dirname(__file__), "../assets/rocks.usd"), + path=os.path.join(warp.examples.get_asset_directory(), "rocks.usd"), pos=wp.vec3(0.0, 0.0, 0.0), rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -0.5 * math.pi) * wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), math.pi), @@ -173,9 +174,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_granular_collision_sdf.usd") + stage_path = "example_granular_collision_sdf.usd" example = Example(stage_path) diff --git a/warp/examples/sim/example_jacobian_ik.py b/warp/examples/sim/example_jacobian_ik.py index 878df1678..08dc0a13b 100644 --- a/warp/examples/sim/example_jacobian_ik.py +++ b/warp/examples/sim/example_jacobian_ik.py @@ -22,6 +22,7 @@ import numpy as np import warp as wp +import warp.examples import warp.sim import warp.sim.render @@ -56,7 +57,7 @@ def __init__(self, stage, num_envs=1): articulation_builder = wp.sim.ModelBuilder() wp.sim.parse_urdf( - os.path.join(os.path.dirname(__file__), "../assets/cartpole.urdf"), + os.path.join(warp.examples.get_asset_directory(), "cartpole.urdf"), articulation_builder, xform=wp.transform_identity(), floating=False, @@ -185,9 +186,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_jacobian_ik.usd") + stage_path = "example_jacobian_ik.usd" example = Example(stage_path, num_envs=10) diff --git a/warp/examples/sim/example_particle_chain.py b/warp/examples/sim/example_particle_chain.py index 636c671f7..27054461c 100644 --- a/warp/examples/sim/example_particle_chain.py +++ b/warp/examples/sim/example_particle_chain.py @@ -14,7 +14,6 @@ ########################################################################### import math -import os import warp as wp import warp.sim @@ -94,9 +93,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_particle_chain.usd") + stage_path = "example_particle_chain.usd" example = Example(stage_path) diff --git a/warp/examples/sim/example_quadruped.py b/warp/examples/sim/example_quadruped.py index 65fc7ce8b..500f25314 100644 --- a/warp/examples/sim/example_quadruped.py +++ b/warp/examples/sim/example_quadruped.py @@ -20,6 +20,7 @@ import numpy as np import warp as wp +import warp.examples import warp.sim import warp.sim.render @@ -73,7 +74,7 @@ def __init__(self, stage=None, num_envs=1, print_timers=True): self.num_envs = num_envs articulation_builder = wp.sim.ModelBuilder() wp.sim.parse_urdf( - os.path.join(os.path.dirname(__file__), "../assets/quadruped.urdf"), + os.path.join(warp.examples.get_asset_directory(), "quadruped.urdf"), articulation_builder, xform=wp.transform([0.0, 0.7, 0.0], wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)), floating=True, @@ -167,9 +168,9 @@ def render(self): if __name__ == "__main__": - stage = os.path.join(os.path.dirname(__file__), "example_quadruped.usd") + stage_path = "example_quadruped.usd" - example = Example(stage, num_envs=8) + example = Example(stage_path, num_envs=8) for _ in range(example.episode_frames): example.step() diff --git a/warp/examples/sim/example_rigid_chain.py b/warp/examples/sim/example_rigid_chain.py index 2a763343c..846ec959d 100644 --- a/warp/examples/sim/example_rigid_chain.py +++ b/warp/examples/sim/example_rigid_chain.py @@ -14,8 +14,6 @@ # ########################################################################### -import os - import numpy as np import warp as wp @@ -177,9 +175,9 @@ def render(self): if __name__ == "__main__": - stage = os.path.join(os.path.dirname(__file__), "example_rigid_chain.usd") + stage_path = "example_rigid_chain.usd" - example = Example(stage) + example = Example(stage_path) for _ in range(example.episode_frames): example.step() diff --git a/warp/examples/sim/example_rigid_contact.py b/warp/examples/sim/example_rigid_contact.py index 8729c3319..84816ecd1 100644 --- a/warp/examples/sim/example_rigid_contact.py +++ b/warp/examples/sim/example_rigid_contact.py @@ -20,6 +20,7 @@ from pxr import Usd, UsdGeom import warp as wp +import warp.examples import warp.sim import warp.sim.render @@ -88,7 +89,7 @@ def __init__(self, stage): builder.body_qd[i] = (0.0, 2.0, 10.0, 0.0, 0.0, 0.0) # meshes - bunny = self.load_mesh(os.path.join(os.path.dirname(__file__), "../assets/bunny.usd"), "/bunny/bunny") + bunny = self.load_mesh(os.path.join(warp.examples.get_asset_directory(), "bunny.usd"), "/bunny/bunny") for i in range(self.num_bodies): b = builder.add_body( origin=wp.transform( @@ -164,9 +165,9 @@ def render(self): if __name__ == "__main__": - stage = os.path.join(os.path.dirname(__file__), "example_rigid_contact.usd") + stage_path = "example_rigid_contact.usd" - example = Example(stage) + example = Example(stage_path) for _ in range(example.episode_frames): example.step() diff --git a/warp/examples/sim/example_rigid_force.py b/warp/examples/sim/example_rigid_force.py index eb7d6bd03..32a2a91c8 100644 --- a/warp/examples/sim/example_rigid_force.py +++ b/warp/examples/sim/example_rigid_force.py @@ -13,7 +13,6 @@ # ########################################################################### -import os import argparse import warp as wp @@ -105,9 +104,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_rigid_force.usd") + stage_path = "example_rigid_force.usd" args = Example.parser.parse_args() diff --git a/warp/examples/sim/example_rigid_gyroscopic.py b/warp/examples/sim/example_rigid_gyroscopic.py index 04971ea27..45368edfb 100644 --- a/warp/examples/sim/example_rigid_gyroscopic.py +++ b/warp/examples/sim/example_rigid_gyroscopic.py @@ -13,8 +13,6 @@ # ########################################################################### -import os - import warp as wp import warp.sim import warp.sim.render @@ -85,9 +83,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_rigid_gyroscopic.usd") + stage_path = "example_rigid_gyroscopic.usd" example = Example(stage_path) diff --git a/warp/examples/sim/example_rigid_soft_contact.py b/warp/examples/sim/example_rigid_soft_contact.py index 1724052c3..7098ba0d3 100644 --- a/warp/examples/sim/example_rigid_soft_contact.py +++ b/warp/examples/sim/example_rigid_soft_contact.py @@ -13,8 +13,6 @@ # ########################################################################### -import os - import warp as wp import warp.sim import warp.sim.render @@ -112,9 +110,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_rigid_soft_contact.usd") + stage_path = "example_rigid_soft_contact.usd" example = Example(stage_path) diff --git a/warp/examples/sim/example_soft_body.py b/warp/examples/sim/example_soft_body.py index 4c94f5dde..ca60a9e82 100644 --- a/warp/examples/sim/example_soft_body.py +++ b/warp/examples/sim/example_soft_body.py @@ -14,7 +14,6 @@ ########################################################################### import math -import os import warp as wp import warp.sim @@ -166,9 +165,7 @@ def render(self): if __name__ == "__main__": - import warp.examples - - stage_path = os.path.join(wp.examples.get_output_directory(), "example_soft_body.usd") + stage_path = "example_soft_body.usd" example = Example(stage_path)