warp-lang 1.0.0b5__py3-none-manylinux2014_x86_64.whl → 1.0.0b6__py3-none-manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. docs/conf.py +3 -4
  2. examples/env/env_ant.py +1 -1
  3. examples/env/env_cartpole.py +1 -1
  4. examples/env/env_humanoid.py +1 -1
  5. examples/example_dem.py +28 -26
  6. examples/example_diffray.py +37 -30
  7. examples/example_fluid.py +7 -3
  8. examples/example_jacobian_ik.py +1 -1
  9. examples/example_mesh_intersect.py +10 -7
  10. examples/example_nvdb.py +3 -3
  11. examples/example_render_opengl.py +19 -10
  12. examples/example_sim_cartpole.py +9 -5
  13. examples/example_sim_cloth.py +29 -25
  14. examples/example_sim_fk_grad.py +2 -2
  15. examples/example_sim_fk_grad_torch.py +3 -3
  16. examples/example_sim_grad_bounce.py +11 -8
  17. examples/example_sim_grad_cloth.py +12 -9
  18. examples/example_sim_granular.py +2 -2
  19. examples/example_sim_granular_collision_sdf.py +13 -13
  20. examples/example_sim_neo_hookean.py +3 -3
  21. examples/example_sim_particle_chain.py +2 -2
  22. examples/example_sim_quadruped.py +8 -5
  23. examples/example_sim_rigid_chain.py +8 -5
  24. examples/example_sim_rigid_contact.py +13 -10
  25. examples/example_sim_rigid_fem.py +2 -2
  26. examples/example_sim_rigid_gyroscopic.py +2 -2
  27. examples/example_sim_rigid_kinematics.py +1 -1
  28. examples/example_sim_trajopt.py +3 -2
  29. examples/fem/example_apic_fluid.py +5 -7
  30. examples/fem/example_diffusion_mgpu.py +18 -16
  31. warp/__init__.py +3 -2
  32. warp/bin/warp.so +0 -0
  33. warp/build_dll.py +29 -9
  34. warp/builtins.py +206 -7
  35. warp/codegen.py +58 -38
  36. warp/config.py +3 -1
  37. warp/context.py +234 -128
  38. warp/fem/__init__.py +2 -2
  39. warp/fem/cache.py +2 -1
  40. warp/fem/field/nodal_field.py +18 -17
  41. warp/fem/geometry/hexmesh.py +11 -6
  42. warp/fem/geometry/quadmesh_2d.py +16 -12
  43. warp/fem/geometry/tetmesh.py +19 -8
  44. warp/fem/geometry/trimesh_2d.py +18 -7
  45. warp/fem/integrate.py +341 -196
  46. warp/fem/quadrature/__init__.py +1 -1
  47. warp/fem/quadrature/pic_quadrature.py +138 -53
  48. warp/fem/quadrature/quadrature.py +81 -9
  49. warp/fem/space/__init__.py +1 -1
  50. warp/fem/space/basis_space.py +169 -51
  51. warp/fem/space/grid_2d_function_space.py +2 -2
  52. warp/fem/space/grid_3d_function_space.py +2 -2
  53. warp/fem/space/hexmesh_function_space.py +2 -2
  54. warp/fem/space/partition.py +9 -6
  55. warp/fem/space/quadmesh_2d_function_space.py +2 -2
  56. warp/fem/space/shape/cube_shape_function.py +27 -15
  57. warp/fem/space/shape/square_shape_function.py +29 -18
  58. warp/fem/space/tetmesh_function_space.py +2 -2
  59. warp/fem/space/topology.py +10 -0
  60. warp/fem/space/trimesh_2d_function_space.py +2 -2
  61. warp/fem/utils.py +10 -5
  62. warp/native/array.h +49 -8
  63. warp/native/builtin.h +31 -14
  64. warp/native/cuda_util.cpp +8 -3
  65. warp/native/cuda_util.h +1 -0
  66. warp/native/exports.h +1177 -1108
  67. warp/native/intersect.h +4 -4
  68. warp/native/intersect_adj.h +8 -8
  69. warp/native/mat.h +65 -6
  70. warp/native/mesh.h +126 -5
  71. warp/native/quat.h +28 -4
  72. warp/native/vec.h +76 -14
  73. warp/native/warp.cu +1 -6
  74. warp/render/render_opengl.py +261 -109
  75. warp/sim/import_mjcf.py +13 -7
  76. warp/sim/import_urdf.py +14 -14
  77. warp/sim/inertia.py +17 -18
  78. warp/sim/model.py +67 -67
  79. warp/sim/render.py +1 -1
  80. warp/sparse.py +6 -6
  81. warp/stubs.py +19 -81
  82. warp/tape.py +1 -1
  83. warp/tests/__main__.py +3 -6
  84. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  85. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  86. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  87. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  88. warp/tests/aux_test_unresolved_func.py +14 -0
  89. warp/tests/aux_test_unresolved_symbol.py +14 -0
  90. warp/tests/{test_kinematics.py → disabled_kinematics.py} +10 -12
  91. warp/tests/run_coverage_serial.py +31 -0
  92. warp/tests/test_adam.py +102 -106
  93. warp/tests/test_arithmetic.py +39 -40
  94. warp/tests/test_array.py +46 -48
  95. warp/tests/test_array_reduce.py +25 -19
  96. warp/tests/test_atomic.py +62 -26
  97. warp/tests/test_bool.py +16 -11
  98. warp/tests/test_builtins_resolution.py +1292 -0
  99. warp/tests/test_bvh.py +9 -12
  100. warp/tests/test_closest_point_edge_edge.py +53 -57
  101. warp/tests/test_codegen.py +164 -134
  102. warp/tests/test_compile_consts.py +13 -19
  103. warp/tests/test_conditional.py +30 -32
  104. warp/tests/test_copy.py +9 -12
  105. warp/tests/test_ctypes.py +90 -98
  106. warp/tests/test_dense.py +20 -14
  107. warp/tests/test_devices.py +34 -35
  108. warp/tests/test_dlpack.py +74 -75
  109. warp/tests/test_examples.py +215 -97
  110. warp/tests/test_fabricarray.py +15 -21
  111. warp/tests/test_fast_math.py +14 -11
  112. warp/tests/test_fem.py +280 -97
  113. warp/tests/test_fp16.py +19 -15
  114. warp/tests/test_func.py +177 -194
  115. warp/tests/test_generics.py +71 -77
  116. warp/tests/test_grad.py +83 -32
  117. warp/tests/test_grad_customs.py +7 -9
  118. warp/tests/test_hash_grid.py +6 -10
  119. warp/tests/test_import.py +9 -23
  120. warp/tests/test_indexedarray.py +19 -21
  121. warp/tests/test_intersect.py +15 -9
  122. warp/tests/test_large.py +17 -19
  123. warp/tests/test_launch.py +14 -17
  124. warp/tests/test_lerp.py +63 -63
  125. warp/tests/test_lvalue.py +84 -35
  126. warp/tests/test_marching_cubes.py +9 -13
  127. warp/tests/test_mat.py +388 -3004
  128. warp/tests/test_mat_lite.py +9 -12
  129. warp/tests/test_mat_scalar_ops.py +2889 -0
  130. warp/tests/test_math.py +10 -11
  131. warp/tests/test_matmul.py +104 -100
  132. warp/tests/test_matmul_lite.py +72 -98
  133. warp/tests/test_mesh.py +35 -32
  134. warp/tests/test_mesh_query_aabb.py +18 -25
  135. warp/tests/test_mesh_query_point.py +39 -23
  136. warp/tests/test_mesh_query_ray.py +9 -21
  137. warp/tests/test_mlp.py +8 -9
  138. warp/tests/test_model.py +89 -93
  139. warp/tests/test_modules_lite.py +15 -25
  140. warp/tests/test_multigpu.py +87 -114
  141. warp/tests/test_noise.py +10 -12
  142. warp/tests/test_operators.py +14 -21
  143. warp/tests/test_options.py +10 -11
  144. warp/tests/test_pinned.py +16 -18
  145. warp/tests/test_print.py +16 -20
  146. warp/tests/test_quat.py +121 -88
  147. warp/tests/test_rand.py +12 -13
  148. warp/tests/test_reload.py +27 -32
  149. warp/tests/test_rounding.py +7 -10
  150. warp/tests/test_runlength_encode.py +105 -106
  151. warp/tests/test_smoothstep.py +8 -9
  152. warp/tests/test_snippet.py +13 -22
  153. warp/tests/test_sparse.py +30 -29
  154. warp/tests/test_spatial.py +179 -174
  155. warp/tests/test_streams.py +100 -107
  156. warp/tests/test_struct.py +98 -67
  157. warp/tests/test_tape.py +11 -17
  158. warp/tests/test_torch.py +89 -86
  159. warp/tests/test_transient_module.py +9 -12
  160. warp/tests/test_types.py +328 -50
  161. warp/tests/test_utils.py +217 -218
  162. warp/tests/test_vec.py +133 -2133
  163. warp/tests/test_vec_lite.py +8 -11
  164. warp/tests/test_vec_scalar_ops.py +2099 -0
  165. warp/tests/test_volume.py +391 -382
  166. warp/tests/test_volume_write.py +122 -135
  167. warp/tests/unittest_serial.py +35 -0
  168. warp/tests/unittest_suites.py +291 -0
  169. warp/tests/{test_base.py → unittest_utils.py} +138 -25
  170. warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
  171. warp/tests/{test_debug.py → walkthough_debug.py} +2 -15
  172. warp/thirdparty/unittest_parallel.py +257 -54
  173. warp/types.py +119 -98
  174. warp/utils.py +14 -0
  175. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/METADATA +2 -1
  176. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/RECORD +182 -178
  177. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
  178. warp/tests/test_all.py +0 -239
  179. warp/tests/test_conditional_unequal_types_kernels.py +0 -14
  180. warp/tests/test_coverage.py +0 -38
  181. warp/tests/test_unresolved_func.py +0 -7
  182. warp/tests/test_unresolved_symbol.py +0 -7
  183. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  184. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  185. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  186. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  187. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
docs/conf.py CHANGED
@@ -14,14 +14,13 @@ import os
14
14
  import sys
15
15
  from datetime import date
16
16
 
17
- import warp as wp
18
-
19
- sys.path.insert(0, os.path.abspath(".."))
17
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
18
+ import warp as wp # noqa: E402
20
19
 
21
20
  # -- Project information -----------------------------------------------------
22
21
 
23
22
  project = "Warp"
24
- copyright = f"{date.today().year}, NVIDIA"
23
+ copyright = f"2022-{date.today().year}, NVIDIA"
25
24
  author = "NVIDIA"
26
25
 
27
26
  version = wp.__version__
examples/env/env_ant.py CHANGED
@@ -54,7 +54,7 @@ class AntEnvironment(Environment):
54
54
  up_axis="y",
55
55
  )
56
56
  builder.joint_q[7:] = [0.0, 1.0, 0.0, -1.0, 0.0, -1.0, 0.0, 1.0]
57
- builder.joint_q[:7] = [0.0, 0.7, 0.0, *wp.quat_from_axis_angle((1.0, 0.0, 0.0), -math.pi * 0.5)]
57
+ builder.joint_q[:7] = [0.0, 0.7, 0.0, *wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)]
58
58
 
59
59
 
60
60
  if __name__ == "__main__":
@@ -39,7 +39,7 @@ class CartpoleEnvironment(Environment):
39
39
  wp.sim.parse_urdf(
40
40
  os.path.join(os.path.dirname(__file__), "../assets/cartpole.urdf"),
41
41
  builder,
42
- xform=wp.transform((0.0, 0.0, 0.0), wp.quat_from_axis_angle((1.0, 0.0, 0.0), -math.pi * 0.5)),
42
+ xform=wp.transform((0.0, 0.0, 0.0), wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)),
43
43
  floating=False,
44
44
  armature=0.1,
45
45
  stiffness=0.0,
@@ -58,7 +58,7 @@ class HumanoidEnvironment(Environment):
58
58
  up_axis="y",
59
59
  )
60
60
 
61
- builder.joint_q[:7] = [0.0, 1.7, 0.0, *wp.quat_from_axis_angle((1.0, 0.0, 0.0), -math.pi * 0.5)]
61
+ builder.joint_q[:7] = [0.0, 1.7, 0.0, *wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)]
62
62
 
63
63
 
64
64
  if __name__ == "__main__":
examples/example_dem.py CHANGED
@@ -118,6 +118,8 @@ def integrate(
118
118
 
119
119
  class Example:
120
120
  def __init__(self, stage):
121
+ self.device = wp.get_device()
122
+
121
123
  self.frame_dt = 1.0 / 60
122
124
  self.frame_count = 400
123
125
 
@@ -150,32 +152,32 @@ class Example:
150
152
  self.use_graph = wp.get_device().is_cuda
151
153
 
152
154
  if self.use_graph:
153
- wp.capture_begin()
154
-
155
- for _ in range(self.sim_substeps):
156
- with wp.ScopedTimer("forces", active=False):
157
- wp.launch(
158
- kernel=apply_forces,
159
- dim=len(self.x),
160
- inputs=[
161
- self.grid.id,
162
- self.x,
163
- self.v,
164
- self.f,
165
- self.point_radius,
166
- self.k_contact,
167
- self.k_damp,
168
- self.k_friction,
169
- self.k_mu,
170
- ],
171
- )
172
- wp.launch(
173
- kernel=integrate,
174
- dim=len(self.x),
175
- inputs=[self.x, self.v, self.f, (0.0, -9.8, 0.0), self.sim_dt, self.inv_mass],
176
- )
177
-
178
- self.graph = wp.capture_end()
155
+ wp.capture_begin(self.device)
156
+ try:
157
+ for _ in range(self.sim_substeps):
158
+ with wp.ScopedTimer("forces", active=False):
159
+ wp.launch(
160
+ kernel=apply_forces,
161
+ dim=len(self.x),
162
+ inputs=[
163
+ self.grid.id,
164
+ self.x,
165
+ self.v,
166
+ self.f,
167
+ self.point_radius,
168
+ self.k_contact,
169
+ self.k_damp,
170
+ self.k_friction,
171
+ self.k_mu,
172
+ ],
173
+ )
174
+ wp.launch(
175
+ kernel=integrate,
176
+ dim=len(self.x),
177
+ inputs=[self.x, self.v, self.f, (0.0, -9.8, 0.0), self.sim_dt, self.inv_mass],
178
+ )
179
+ finally:
180
+ self.graph = wp.capture_end(self.device)
179
181
 
180
182
  def update(self):
181
183
  with wp.ScopedTimer("simulate", active=True):
@@ -304,6 +304,8 @@ class Example:
304
304
  """
305
305
 
306
306
  def __init__(self, stage=None, rot_array=[0.0, 0.0, 0.0, 1.0], verbose=False):
307
+ self.device = wp.get_device()
308
+
307
309
  self.verbose = verbose
308
310
  cam_pos = wp.vec3(0.0, 0.75, 7.0)
309
311
  cam_rot = wp.quat(0.0, 0.0, 0.0, 1.0)
@@ -416,12 +418,14 @@ class Example:
416
418
  self.loss = wp.zeros(1, dtype=float, requires_grad=True)
417
419
 
418
420
  # capture graph
419
- wp.capture_begin()
420
- self.tape = wp.Tape()
421
- with self.tape:
422
- self.compute_loss()
423
- self.tape.backward(self.loss)
424
- self.graph = wp.capture_end()
421
+ wp.capture_begin(self.device)
422
+ try:
423
+ self.tape = wp.Tape()
424
+ with self.tape:
425
+ self.compute_loss()
426
+ self.tape.backward(self.loss)
427
+ finally:
428
+ self.graph = wp.capture_end(self.device)
425
429
 
426
430
  self.optimizer = SGD(
427
431
  [self.render_mesh.rot],
@@ -432,33 +436,36 @@ class Example:
432
436
  )
433
437
 
434
438
  def ray_trace(self, is_live=False):
435
- with wp.ScopedDevice("cuda:0"):
436
- # raycast
437
- wp.launch(
438
- kernel=draw_kernel,
439
- dim=self.num_rays,
440
- inputs=[
441
- self.render_mesh,
442
- self.camera,
443
- self.texture,
444
- self.rays_width,
445
- self.rays_height,
446
- self.rays,
447
- self.lights,
448
- self.render_mode,
449
- ],
450
- )
451
-
452
- # downsample
453
- wp.launch(
454
- kernel=downsample_kernel,
455
- dim=self.num_pixels,
456
- inputs=[self.rays, self.pixels, self.rays_width, pow(2, self.num_samples)],
457
- )
439
+ # raycast
440
+ wp.launch(
441
+ kernel=draw_kernel,
442
+ dim=self.num_rays,
443
+ inputs=[
444
+ self.render_mesh,
445
+ self.camera,
446
+ self.texture,
447
+ self.rays_width,
448
+ self.rays_height,
449
+ self.rays,
450
+ self.lights,
451
+ self.render_mode,
452
+ ],
453
+ device=self.device,
454
+ )
455
+
456
+ # downsample
457
+ wp.launch(
458
+ kernel=downsample_kernel,
459
+ dim=self.num_pixels,
460
+ inputs=[self.rays, self.pixels, self.rays_width, pow(2, self.num_samples)],
461
+ device=self.device,
462
+ )
458
463
 
459
464
  def compute_loss(self):
460
465
  self.ray_trace()
461
- wp.launch(loss_kernel, dim=self.num_pixels, inputs=[self.pixels, self.target_pixels, self.loss])
466
+ wp.launch(
467
+ loss_kernel, dim=self.num_pixels, inputs=[self.pixels, self.target_pixels, self.loss], device=self.device
468
+ )
462
469
 
463
470
  def get_image(self):
464
471
  return self.pixels.numpy().reshape((self.height, self.width, 3))
examples/example_fluid.py CHANGED
@@ -165,6 +165,8 @@ def init(rho: wp.array2d(dtype=float), u: wp.array2d(dtype=wp.vec2), radius: int
165
165
 
166
166
  class Example:
167
167
  def __init__(self, **kwargs):
168
+ self.device = wp.get_device()
169
+
168
170
  self.sim_fps = 60.0
169
171
  self.sim_substeps = 2
170
172
  self.iterations = 100
@@ -187,9 +189,11 @@ class Example:
187
189
 
188
190
  # capture pressure solve as a CUDA graph
189
191
  if self.device.is_cuda:
190
- wp.capture_begin()
191
- self.pressure_iterations()
192
- self.graph = wp.capture_end()
192
+ wp.capture_begin(self.device)
193
+ try:
194
+ self.pressure_iterations()
195
+ finally:
196
+ self.graph = wp.capture_end(self.device)
193
197
 
194
198
  def update(self):
195
199
  with wp.ScopedTimer("update"):
@@ -87,7 +87,7 @@ class Example:
87
87
  builder.add_builder(
88
88
  articulation_builder,
89
89
  xform=wp.transform(
90
- np.array((i * 2.0, 4.0, 0.0)), wp.quat_from_axis_angle((1.0, 0.0, 0.0), -math.pi * 0.5)
90
+ wp.vec3(i * 2.0, 4.0, 0.0), wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)
91
91
  ),
92
92
  )
93
93
  self.target_origin.append((i * 2.0, 4.0, 0.0))
@@ -83,6 +83,9 @@ def intersect(
83
83
 
84
84
  class Example:
85
85
  def __init__(self, stage):
86
+ rng = np.random.default_rng()
87
+
88
+ self.device = wp.get_device()
86
89
  self.query_count = 1024
87
90
  self.has_queried = False
88
91
 
@@ -102,10 +105,10 @@ class Example:
102
105
 
103
106
  for i in range(self.query_count):
104
107
  # random offset
105
- p = (np.random.rand(3) * 0.5 - 0.5) * 5.0
108
+ p = wp.vec3(rng.random(3) * 0.5 - 0.5) * 5.0
106
109
 
107
110
  # random orientation
108
- axis = wp.normalize(np.random.rand(3) * 0.5 - 0.5)
111
+ axis = wp.normalize(wp.vec3(rng.random(3) * 0.5 - 0.5))
109
112
  angle = float(np.random.rand(1)[0])
110
113
 
111
114
  q = wp.quat_from_axis_angle(wp.normalize(axis), angle)
@@ -115,8 +118,8 @@ class Example:
115
118
  self.array_result = wp.zeros(self.query_count, dtype=int)
116
119
  self.array_xforms = wp.array(self.xforms, dtype=wp.transform)
117
120
 
118
- # force module load (for accurate profiling)
119
- wp.force_load()
121
+ # compile and load the module up front (for accurate profiling)
122
+ wp.load_module(device=self.device)
120
123
 
121
124
  def update(self):
122
125
  with wp.ScopedTimer("intersect", active=True):
@@ -143,14 +146,14 @@ class Example:
143
146
  os.path.join(os.path.dirname(__file__), self.path_0),
144
147
  pos=wp.vec3(xform.p[0] + offset, xform.p[1], xform.p[2]),
145
148
  rot=xform.q,
146
- scale=(1.0, 1.0, 1.0),
149
+ scale=wp.vec3(1.0, 1.0, 1.0),
147
150
  )
148
151
  self.renderer.render_ref(
149
152
  f"mesh_{i}_1",
150
153
  os.path.join(os.path.dirname(__file__), self.path_1),
151
- pos=(offset, 0.0, 0.0),
154
+ pos=wp.vec3(offset, 0.0, 0.0),
152
155
  rot=wp.quat_identity(),
153
- scale=(1.0, 1.0, 1.0),
156
+ scale=wp.vec3(1.0, 1.0, 1.0),
154
157
  )
155
158
 
156
159
  # if pair intersects then draw a small box above the pair
examples/example_nvdb.py CHANGED
@@ -143,9 +143,9 @@ class Example:
143
143
  self.renderer.render_ref(
144
144
  name="collision",
145
145
  path=os.path.join(os.path.dirname(__file__), "assets/rocks.usd"),
146
- pos=(0.0, 0.0, 0.0),
147
- rot=wp.quat_from_axis_angle((1.0, 0.0, 0.0), math.pi),
148
- scale=(1.0, 1.0, 1.0),
146
+ pos=wp.vec3(0.0, 0.0, 0.0),
147
+ rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), math.pi),
148
+ scale=wp.vec3(1.0, 1.0, 1.0),
149
149
  )
150
150
  self.renderer.render_points(name="points", points=self.positions.numpy(), radius=self.sim_margin)
151
151
 
@@ -27,6 +27,8 @@ split_up_tiles = True
27
27
  custom_tile_arrangement = False
28
28
  # whether to display the pixels in a matplotlib figure
29
29
  show_plot = True
30
+ # whether to render depth image to a Warp array
31
+ render_mode = "depth"
30
32
 
31
33
  renderer = wp.render.OpenGLRenderer(vsync=False)
32
34
  instance_ids = []
@@ -51,11 +53,12 @@ if num_tiles > 1:
51
53
 
52
54
  renderer.render_ground()
53
55
 
56
+ channels = 1 if render_mode == "depth" else 3
54
57
  if show_plot:
55
58
  import matplotlib.pyplot as plt
56
59
 
57
60
  if split_up_tiles:
58
- pixels = wp.zeros((num_tiles, renderer.tile_height, renderer.tile_width, 3), dtype=wp.float32)
61
+ pixels = wp.zeros((num_tiles, renderer.tile_height, renderer.tile_width, channels), dtype=wp.float32)
59
62
  ncols = int(np.ceil(np.sqrt(num_tiles)))
60
63
  nrows = int(np.ceil(num_tiles / float(ncols)))
61
64
  img_plots = []
@@ -70,17 +73,23 @@ if show_plot:
70
73
  sharey=True,
71
74
  num=1,
72
75
  )
73
- tile_temp = np.zeros((renderer.tile_height, renderer.tile_width, 3), dtype=np.float32)
76
+ tile_temp = np.zeros((renderer.tile_height, renderer.tile_width, channels), dtype=np.float32)
74
77
  for dim in range(ncols * nrows):
75
78
  ax = axes[dim // ncols, dim % ncols]
76
79
  if dim >= num_tiles:
77
80
  ax.axis("off")
78
81
  continue
79
- img_plots.append(ax.imshow(tile_temp))
82
+ if render_mode == "depth":
83
+ img_plots.append(ax.imshow(tile_temp, vmin=renderer.camera_near_plane, vmax=renderer.camera_far_plane))
84
+ else:
85
+ img_plots.append(ax.imshow(tile_temp))
80
86
  else:
81
87
  fig = plt.figure(1)
82
- pixels = wp.zeros((renderer.screen_height, renderer.screen_width, 3), dtype=wp.float32)
83
- img_plot = plt.imshow(pixels.numpy())
88
+ pixels = wp.zeros((renderer.screen_height, renderer.screen_width, channels), dtype=wp.float32)
89
+ if render_mode == "depth":
90
+ img_plot = plt.imshow(pixels.numpy(), vmin=renderer.camera_near_plane, vmax=renderer.camera_far_plane)
91
+ else:
92
+ img_plot = plt.imshow(pixels.numpy())
84
93
 
85
94
  plt.ion()
86
95
  plt.show()
@@ -95,14 +104,14 @@ while renderer.is_running():
95
104
  renderer.render_cylinder(
96
105
  "cylinder",
97
106
  [3.2, 1.0, np.sin(time + 0.5)],
98
- np.array(wp.quat_from_axis_angle((1.0, 0.0, 0.0), np.sin(time + 0.5))),
107
+ np.array(wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), wp.sin(time + 0.5))),
99
108
  radius=0.5,
100
109
  half_height=0.8,
101
110
  )
102
111
  renderer.render_cone(
103
112
  "cone",
104
113
  [-1.2, 1.0, 0.0],
105
- np.array(wp.quat_from_axis_angle((0.707, 0.707, 0.0), time)),
114
+ np.array(wp.quat_from_axis_angle(wp.vec3(0.707, 0.707, 0.0), time)),
106
115
  radius=0.5,
107
116
  half_height=0.8,
108
117
  )
@@ -110,15 +119,15 @@ while renderer.is_running():
110
119
 
111
120
  if show_plot and plt.fignum_exists(1):
112
121
  if split_up_tiles:
113
- pixel_shape = (num_tiles, renderer.tile_height, renderer.tile_width, 3)
122
+ pixel_shape = (num_tiles, renderer.tile_height, renderer.tile_width, channels)
114
123
  else:
115
- pixel_shape = (renderer.screen_height, renderer.screen_width, 3)
124
+ pixel_shape = (renderer.screen_height, renderer.screen_width, channels)
116
125
 
117
126
  if pixel_shape != pixels.shape:
118
127
  # make sure we resize the pixels array to the right dimensions if the user resizes the window
119
128
  pixels = wp.zeros(pixel_shape, dtype=wp.float32)
120
129
 
121
- renderer.get_pixels(pixels, split_up_tiles=split_up_tiles)
130
+ renderer.get_pixels(pixels, split_up_tiles=split_up_tiles, mode=render_mode)
122
131
 
123
132
  if split_up_tiles:
124
133
  pixels_np = pixels.numpy()
@@ -28,6 +28,8 @@ wp.init()
28
28
 
29
29
  class Example:
30
30
  def __init__(self, stage=None, num_envs=1, enable_rendering=True, print_timers=True):
31
+ self.device = wp.get_device()
32
+
31
33
  builder = wp.sim.ModelBuilder()
32
34
 
33
35
  self.num_envs = num_envs
@@ -37,7 +39,7 @@ class Example:
37
39
  wp.sim.parse_urdf(
38
40
  os.path.join(os.path.dirname(__file__), "assets/cartpole.urdf"),
39
41
  articulation_builder,
40
- xform=wp.transform(np.zeros(3), wp.quat_from_axis_angle((1.0, 0.0, 0.0), -math.pi * 0.5)),
42
+ xform=wp.transform(wp.vec3(), wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.5)),
41
43
  floating=False,
42
44
  density=100,
43
45
  armature=0.1,
@@ -98,13 +100,15 @@ class Example:
98
100
 
99
101
  if self.use_graph:
100
102
  # create update graph
101
- wp.capture_begin()
102
- self.update()
103
- self.graph = wp.capture_end()
103
+ wp.capture_begin(self.device)
104
+ try:
105
+ self.update()
106
+ finally:
107
+ self.graph = wp.capture_end(self.device)
104
108
 
105
109
  def update(self):
106
110
  with wp.ScopedTimer("simulate", active=True, print=self.print_timers):
107
- if self.use_graph is False or self.graph is None:
111
+ if not self.use_graph or self.graph is None:
108
112
  for _ in range(self.sim_substeps):
109
113
  self.state.clear_forces()
110
114
  self.state = self.integrator.simulate(self.model, self.state, self.state, self.sim_dt)
@@ -37,19 +37,10 @@ class IntegratorType(Enum):
37
37
 
38
38
 
39
39
  class Example:
40
- def __init__(self, stage):
41
- self.parser = argparse.ArgumentParser()
42
- self.parser.add_argument(
43
- "--integrator",
44
- help="Type of integrator",
45
- type=IntegratorType,
46
- choices=list(IntegratorType),
47
- default=IntegratorType.EULER,
48
- )
49
-
50
- args = self.parser.parse_args()
40
+ def __init__(self, stage, integrator=IntegratorType.EULER):
41
+ self.device = wp.get_device()
51
42
 
52
- self.integrator_type = args.integrator
43
+ self.integrator_type = integrator
53
44
 
54
45
  self.sim_width = 64
55
46
  self.sim_height = 32
@@ -68,9 +59,9 @@ class Example:
68
59
 
69
60
  if self.integrator_type == IntegratorType.EULER:
70
61
  builder.add_cloth_grid(
71
- pos=(0.0, 4.0, 0.0),
72
- rot=wp.quat_from_axis_angle((1.0, 0.0, 0.0), math.pi * 0.5),
73
- vel=(0.0, 0.0, 0.0),
62
+ pos=wp.vec3(0.0, 4.0, 0.0),
63
+ rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), math.pi * 0.5),
64
+ vel=wp.vec3(0.0, 0.0, 0.0),
74
65
  dim_x=self.sim_width,
75
66
  dim_y=self.sim_height,
76
67
  cell_x=0.1,
@@ -83,9 +74,9 @@ class Example:
83
74
  )
84
75
  else:
85
76
  builder.add_cloth_grid(
86
- pos=(0.0, 4.0, 0.0),
87
- rot=wp.quat_from_axis_angle((1.0, 0.0, 0.0), math.pi * 0.5),
88
- vel=(0.0, 0.0, 0.0),
77
+ pos=wp.vec3(0.0, 4.0, 0.0),
78
+ rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), math.pi * 0.5),
79
+ vel=wp.vec3(0.0, 0.0, 0.0),
89
80
  dim_x=self.sim_width,
90
81
  dim_y=self.sim_height,
91
82
  cell_x=0.1,
@@ -109,9 +100,9 @@ class Example:
109
100
  builder.add_shape_mesh(
110
101
  body=-1,
111
102
  mesh=mesh,
112
- pos=(1.0, 0.0, 1.0),
113
- rot=wp.quat_from_axis_angle((0.0, 1.0, 0.0), math.pi * 0.5),
114
- scale=(2.0, 2.0, 2.0),
103
+ pos=wp.vec3(1.0, 0.0, 1.0),
104
+ rot=wp.quat_from_axis_angle(wp.vec3(0.0, 1.0, 0.0), math.pi * 0.5),
105
+ scale=wp.vec3(2.0, 2.0, 2.0),
115
106
  ke=1.0e2,
116
107
  kd=1.0e2,
117
108
  kf=1.0e1,
@@ -135,9 +126,11 @@ class Example:
135
126
 
136
127
  if self.sim_use_graph:
137
128
  # create update graph
138
- wp.capture_begin()
139
- self.update()
140
- self.graph = wp.capture_end()
129
+ wp.capture_begin(self.device)
130
+ try:
131
+ self.update()
132
+ finally:
133
+ self.graph = wp.capture_end(self.device)
141
134
 
142
135
  def update(self):
143
136
  with wp.ScopedTimer("simulate", dict=self.profiler):
@@ -168,9 +161,20 @@ class Example:
168
161
 
169
162
 
170
163
  if __name__ == "__main__":
164
+ parser = argparse.ArgumentParser()
165
+ parser.add_argument(
166
+ "--integrator",
167
+ help="Type of integrator",
168
+ type=IntegratorType,
169
+ choices=list(IntegratorType),
170
+ default=IntegratorType.EULER,
171
+ )
172
+
173
+ args = parser.parse_args()
174
+
171
175
  stage_path = os.path.join(os.path.dirname(__file__), "outputs/example_sim_cloth.usd")
172
176
 
173
- example = Example(stage_path)
177
+ example = Example(stage_path, integrator=args.integrator)
174
178
 
175
179
  for i in range(example.sim_frames):
176
180
  example.update()
@@ -84,12 +84,12 @@ class Example:
84
84
 
85
85
  if i == chain_length - 1:
86
86
  # create end effector
87
- builder.add_shape_sphere(pos=(0.0, 0.0, 0.0), radius=0.1, density=10.0, body=b)
87
+ builder.add_shape_sphere(pos=wp.vec3(0.0, 0.0, 0.0), radius=0.1, density=10.0, body=b)
88
88
 
89
89
  else:
90
90
  # create shape
91
91
  builder.add_shape_box(
92
- pos=(chain_width * 0.5, 0.0, 0.0), hx=chain_width * 0.5, hy=0.1, hz=0.1, density=10.0, body=b
92
+ pos=wp.vec3(chain_width * 0.5, 0.0, 0.0), hx=chain_width * 0.5, hy=0.1, hz=0.1, density=10.0, body=b
93
93
  )
94
94
 
95
95
  self.device = wp.get_device(device)
@@ -95,7 +95,7 @@ class Example:
95
95
  builder.add_joint_revolute(
96
96
  parent=parent,
97
97
  child=b,
98
- axis=(0.0, 0.0, 1.0),
98
+ axis=wp.vec3(0.0, 0.0, 1.0),
99
99
  parent_xform=parent_joint_xform,
100
100
  child_xform=wp.transform_identity(),
101
101
  limit_lower=-np.deg2rad(60.0),
@@ -108,12 +108,12 @@ class Example:
108
108
 
109
109
  if i == chain_length - 1:
110
110
  # create end effector
111
- builder.add_shape_sphere(pos=(0.0, 0.0, 0.0), radius=0.1, density=10.0, body=b)
111
+ builder.add_shape_sphere(pos=wp.vec3(0.0, 0.0, 0.0), radius=0.1, density=10.0, body=b)
112
112
 
113
113
  else:
114
114
  # create shape
115
115
  builder.add_shape_box(
116
- pos=(chain_width * 0.5, 0.0, 0.0), hx=chain_width * 0.5, hy=0.1, hz=0.1, density=10.0, body=b
116
+ pos=wp.vec3(chain_width * 0.5, 0.0, 0.0), hx=chain_width * 0.5, hy=0.1, hz=0.1, density=10.0, body=b
117
117
  )
118
118
 
119
119
  # finalize model
@@ -45,6 +45,7 @@ def step_kernel(x: wp.array(dtype=wp.vec3), grad: wp.array(dtype=wp.vec3), alpha
45
45
 
46
46
  class Example:
47
47
  def __init__(self, stage=None, enable_rendering=True, profile=False, adapter=None, verbose=False):
48
+ self.device = wp.get_device()
48
49
  self.verbose = verbose
49
50
 
50
51
  # seconds
@@ -71,8 +72,8 @@ class Example:
71
72
  mu = 0.2
72
73
 
73
74
  builder = wp.sim.ModelBuilder()
74
- builder.add_particle(pos=(-0.5, 1.0, 0.0), vel=(5.0, -5.0, 0.0), mass=1.0)
75
- builder.add_shape_box(body=-1, pos=(2.0, 1.0, 0.0), hx=0.25, hy=1.0, hz=1.0, ke=ke, kf=kf, kd=kd, mu=mu)
75
+ builder.add_particle(pos=wp.vec3(-0.5, 1.0, 0.0), vel=wp.vec3(5.0, -5.0, 0.0), mass=1.0)
76
+ builder.add_shape_box(body=-1, pos=wp.vec3(2.0, 1.0, 0.0), hx=0.25, hy=1.0, hz=1.0, ke=ke, kf=kf, kd=kd, mu=mu)
76
77
 
77
78
  self.device = wp.get_device(adapter)
78
79
  self.profile = profile
@@ -106,12 +107,14 @@ class Example:
106
107
  self.renderer = wp.sim.render.SimRenderer(self.model, stage, scaling=1.0)
107
108
 
108
109
  # capture forward/backward passes
109
- wp.capture_begin()
110
- self.tape = wp.Tape()
111
- with self.tape:
112
- self.compute_loss()
113
- self.tape.backward(self.loss)
114
- self.graph = wp.capture_end()
110
+ wp.capture_begin(self.device)
111
+ try:
112
+ self.tape = wp.Tape()
113
+ with self.tape:
114
+ self.compute_loss()
115
+ self.tape.backward(self.loss)
116
+ finally:
117
+ self.graph = wp.capture_end(self.device)
115
118
 
116
119
  def compute_loss(self):
117
120
  # run control loop
@@ -53,6 +53,7 @@ def step_kernel(x: wp.array(dtype=wp.vec3), grad: wp.array(dtype=wp.vec3), alpha
53
53
 
54
54
  class Example:
55
55
  def __init__(self, stage, profile=False, adapter=None, verbose=False):
56
+ self.device = wp.get_device()
56
57
  self.verbose = verbose
57
58
 
58
59
  # seconds
@@ -80,9 +81,9 @@ class Example:
80
81
  dim_y = 16
81
82
 
82
83
  builder.add_cloth_grid(
83
- pos=(0.0, 0.0, 0.0),
84
- vel=(0.1, 0.1, 0.0),
85
- rot=wp.quat_from_axis_angle((1.0, 0.0, 0.0), -math.pi * 0.25),
84
+ pos=wp.vec3(0.0, 0.0, 0.0),
85
+ vel=wp.vec3(0.1, 0.1, 0.0),
86
+ rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), -math.pi * 0.25),
86
87
  dim_x=dim_x,
87
88
  dim_y=dim_y,
88
89
  cell_x=1.0 / dim_x,
@@ -115,12 +116,14 @@ class Example:
115
116
  self.renderer = wp.sim.render.SimRenderer(self.model, stage, scaling=4.0)
116
117
 
117
118
  # capture forward/backward passes
118
- wp.capture_begin()
119
- self.tape = wp.Tape()
120
- with self.tape:
121
- self.compute_loss()
122
- self.tape.backward(self.loss)
123
- self.graph = wp.capture_end()
119
+ wp.capture_begin(self.device)
120
+ try:
121
+ self.tape = wp.Tape()
122
+ with self.tape:
123
+ self.compute_loss()
124
+ self.tape.backward(self.loss)
125
+ finally:
126
+ self.graph = wp.capture_end(self.device)
124
127
 
125
128
  def compute_loss(self):
126
129
  # run control loop