warp-lang 1.7.2rc1__py3-none-macosx_10_13_universal2.whl → 1.8.1__py3-none-macosx_10_13_universal2.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.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

Files changed (192) hide show
  1. warp/__init__.py +3 -1
  2. warp/__init__.pyi +3489 -1
  3. warp/autograd.py +45 -122
  4. warp/bin/libwarp.dylib +0 -0
  5. warp/build.py +241 -252
  6. warp/build_dll.py +130 -26
  7. warp/builtins.py +1907 -384
  8. warp/codegen.py +272 -104
  9. warp/config.py +12 -1
  10. warp/constants.py +1 -1
  11. warp/context.py +770 -238
  12. warp/dlpack.py +1 -1
  13. warp/examples/benchmarks/benchmark_cloth.py +2 -2
  14. warp/examples/benchmarks/benchmark_tile_sort.py +155 -0
  15. warp/examples/core/example_sample_mesh.py +1 -1
  16. warp/examples/core/example_spin_lock.py +93 -0
  17. warp/examples/core/example_work_queue.py +118 -0
  18. warp/examples/fem/example_adaptive_grid.py +5 -5
  19. warp/examples/fem/example_apic_fluid.py +1 -1
  20. warp/examples/fem/example_burgers.py +1 -1
  21. warp/examples/fem/example_convection_diffusion.py +9 -6
  22. warp/examples/fem/example_darcy_ls_optimization.py +489 -0
  23. warp/examples/fem/example_deformed_geometry.py +1 -1
  24. warp/examples/fem/example_diffusion.py +2 -2
  25. warp/examples/fem/example_diffusion_3d.py +1 -1
  26. warp/examples/fem/example_distortion_energy.py +1 -1
  27. warp/examples/fem/example_elastic_shape_optimization.py +387 -0
  28. warp/examples/fem/example_magnetostatics.py +5 -3
  29. warp/examples/fem/example_mixed_elasticity.py +5 -3
  30. warp/examples/fem/example_navier_stokes.py +11 -9
  31. warp/examples/fem/example_nonconforming_contact.py +5 -3
  32. warp/examples/fem/example_streamlines.py +8 -3
  33. warp/examples/fem/utils.py +9 -8
  34. warp/examples/interop/example_jax_callable.py +34 -4
  35. warp/examples/interop/example_jax_ffi_callback.py +2 -2
  36. warp/examples/interop/example_jax_kernel.py +27 -1
  37. warp/examples/optim/example_drone.py +1 -1
  38. warp/examples/sim/example_cloth.py +1 -1
  39. warp/examples/sim/example_cloth_self_contact.py +48 -54
  40. warp/examples/tile/example_tile_block_cholesky.py +502 -0
  41. warp/examples/tile/example_tile_cholesky.py +2 -1
  42. warp/examples/tile/example_tile_convolution.py +1 -1
  43. warp/examples/tile/example_tile_filtering.py +1 -1
  44. warp/examples/tile/example_tile_matmul.py +1 -1
  45. warp/examples/tile/example_tile_mlp.py +2 -0
  46. warp/fabric.py +7 -7
  47. warp/fem/__init__.py +5 -0
  48. warp/fem/adaptivity.py +1 -1
  49. warp/fem/cache.py +152 -63
  50. warp/fem/dirichlet.py +2 -2
  51. warp/fem/domain.py +136 -6
  52. warp/fem/field/field.py +141 -99
  53. warp/fem/field/nodal_field.py +85 -39
  54. warp/fem/field/virtual.py +99 -52
  55. warp/fem/geometry/adaptive_nanogrid.py +91 -86
  56. warp/fem/geometry/closest_point.py +13 -0
  57. warp/fem/geometry/deformed_geometry.py +102 -40
  58. warp/fem/geometry/element.py +56 -2
  59. warp/fem/geometry/geometry.py +323 -22
  60. warp/fem/geometry/grid_2d.py +157 -62
  61. warp/fem/geometry/grid_3d.py +116 -20
  62. warp/fem/geometry/hexmesh.py +86 -20
  63. warp/fem/geometry/nanogrid.py +166 -86
  64. warp/fem/geometry/partition.py +59 -25
  65. warp/fem/geometry/quadmesh.py +86 -135
  66. warp/fem/geometry/tetmesh.py +47 -119
  67. warp/fem/geometry/trimesh.py +77 -270
  68. warp/fem/integrate.py +181 -95
  69. warp/fem/linalg.py +25 -58
  70. warp/fem/operator.py +124 -27
  71. warp/fem/quadrature/pic_quadrature.py +36 -14
  72. warp/fem/quadrature/quadrature.py +40 -16
  73. warp/fem/space/__init__.py +1 -1
  74. warp/fem/space/basis_function_space.py +66 -46
  75. warp/fem/space/basis_space.py +17 -4
  76. warp/fem/space/dof_mapper.py +1 -1
  77. warp/fem/space/function_space.py +2 -2
  78. warp/fem/space/grid_2d_function_space.py +4 -1
  79. warp/fem/space/hexmesh_function_space.py +4 -2
  80. warp/fem/space/nanogrid_function_space.py +3 -1
  81. warp/fem/space/partition.py +11 -2
  82. warp/fem/space/quadmesh_function_space.py +4 -1
  83. warp/fem/space/restriction.py +5 -2
  84. warp/fem/space/shape/__init__.py +10 -8
  85. warp/fem/space/tetmesh_function_space.py +4 -1
  86. warp/fem/space/topology.py +52 -21
  87. warp/fem/space/trimesh_function_space.py +4 -1
  88. warp/fem/utils.py +53 -8
  89. warp/jax.py +1 -2
  90. warp/jax_experimental/ffi.py +210 -67
  91. warp/jax_experimental/xla_ffi.py +37 -24
  92. warp/math.py +171 -1
  93. warp/native/array.h +103 -4
  94. warp/native/builtin.h +182 -35
  95. warp/native/coloring.cpp +6 -2
  96. warp/native/cuda_util.cpp +1 -1
  97. warp/native/exports.h +118 -63
  98. warp/native/intersect.h +5 -5
  99. warp/native/mat.h +8 -13
  100. warp/native/mathdx.cpp +11 -5
  101. warp/native/matnn.h +1 -123
  102. warp/native/mesh.h +1 -1
  103. warp/native/quat.h +34 -6
  104. warp/native/rand.h +7 -7
  105. warp/native/sparse.cpp +121 -258
  106. warp/native/sparse.cu +181 -274
  107. warp/native/spatial.h +305 -17
  108. warp/native/svd.h +23 -8
  109. warp/native/tile.h +603 -73
  110. warp/native/tile_radix_sort.h +1112 -0
  111. warp/native/tile_reduce.h +239 -13
  112. warp/native/tile_scan.h +240 -0
  113. warp/native/tuple.h +189 -0
  114. warp/native/vec.h +10 -20
  115. warp/native/warp.cpp +36 -4
  116. warp/native/warp.cu +588 -52
  117. warp/native/warp.h +47 -74
  118. warp/optim/linear.py +5 -1
  119. warp/paddle.py +7 -8
  120. warp/py.typed +0 -0
  121. warp/render/render_opengl.py +110 -80
  122. warp/render/render_usd.py +124 -62
  123. warp/sim/__init__.py +9 -0
  124. warp/sim/collide.py +253 -80
  125. warp/sim/graph_coloring.py +8 -1
  126. warp/sim/import_mjcf.py +4 -3
  127. warp/sim/import_usd.py +11 -7
  128. warp/sim/integrator.py +5 -2
  129. warp/sim/integrator_euler.py +1 -1
  130. warp/sim/integrator_featherstone.py +1 -1
  131. warp/sim/integrator_vbd.py +761 -322
  132. warp/sim/integrator_xpbd.py +1 -1
  133. warp/sim/model.py +265 -260
  134. warp/sim/utils.py +10 -7
  135. warp/sparse.py +303 -166
  136. warp/tape.py +54 -51
  137. warp/tests/cuda/test_conditional_captures.py +1046 -0
  138. warp/tests/cuda/test_streams.py +1 -1
  139. warp/tests/geometry/test_volume.py +2 -2
  140. warp/tests/interop/test_dlpack.py +9 -9
  141. warp/tests/interop/test_jax.py +0 -1
  142. warp/tests/run_coverage_serial.py +1 -1
  143. warp/tests/sim/disabled_kinematics.py +2 -2
  144. warp/tests/sim/{test_vbd.py → test_cloth.py} +378 -112
  145. warp/tests/sim/test_collision.py +159 -51
  146. warp/tests/sim/test_coloring.py +91 -2
  147. warp/tests/test_array.py +254 -2
  148. warp/tests/test_array_reduce.py +2 -2
  149. warp/tests/test_assert.py +53 -0
  150. warp/tests/test_atomic_cas.py +312 -0
  151. warp/tests/test_codegen.py +142 -19
  152. warp/tests/test_conditional.py +47 -1
  153. warp/tests/test_ctypes.py +0 -20
  154. warp/tests/test_devices.py +8 -0
  155. warp/tests/test_fabricarray.py +4 -2
  156. warp/tests/test_fem.py +58 -25
  157. warp/tests/test_func.py +42 -1
  158. warp/tests/test_grad.py +1 -1
  159. warp/tests/test_lerp.py +1 -3
  160. warp/tests/test_map.py +481 -0
  161. warp/tests/test_mat.py +23 -24
  162. warp/tests/test_quat.py +28 -15
  163. warp/tests/test_rounding.py +10 -38
  164. warp/tests/test_runlength_encode.py +7 -7
  165. warp/tests/test_smoothstep.py +1 -1
  166. warp/tests/test_sparse.py +83 -2
  167. warp/tests/test_spatial.py +507 -1
  168. warp/tests/test_static.py +48 -0
  169. warp/tests/test_struct.py +2 -2
  170. warp/tests/test_tape.py +38 -0
  171. warp/tests/test_tuple.py +265 -0
  172. warp/tests/test_types.py +2 -2
  173. warp/tests/test_utils.py +24 -18
  174. warp/tests/test_vec.py +38 -408
  175. warp/tests/test_vec_constructors.py +325 -0
  176. warp/tests/tile/test_tile.py +438 -131
  177. warp/tests/tile/test_tile_mathdx.py +518 -14
  178. warp/tests/tile/test_tile_matmul.py +179 -0
  179. warp/tests/tile/test_tile_reduce.py +307 -5
  180. warp/tests/tile/test_tile_shared_memory.py +136 -7
  181. warp/tests/tile/test_tile_sort.py +121 -0
  182. warp/tests/unittest_suites.py +14 -6
  183. warp/types.py +462 -308
  184. warp/utils.py +647 -86
  185. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/METADATA +20 -6
  186. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/RECORD +189 -175
  187. warp/stubs.py +0 -3381
  188. warp/tests/sim/test_xpbd.py +0 -399
  189. warp/tests/test_mlp.py +0 -282
  190. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/WHEEL +0 -0
  191. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/licenses/LICENSE.md +0 -0
  192. {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/top_level.txt +0 -0
warp/native/warp.h CHANGED
@@ -19,6 +19,7 @@
19
19
 
20
20
  // defines all crt + builtin types
21
21
  #include "builtin.h"
22
+ #include <cstdint>
22
23
 
23
24
  #define WP_CURRENT_STREAM ((void*)0xffffffffffffffff)
24
25
 
@@ -177,95 +178,56 @@ extern "C"
177
178
  WP_API void runlength_encode_int_host(uint64_t values, uint64_t run_values, uint64_t run_lengths, uint64_t run_count, int n);
178
179
  WP_API void runlength_encode_int_device(uint64_t values, uint64_t run_values, uint64_t run_lengths, uint64_t run_count, int n);
179
180
 
180
- WP_API void bsr_matrix_from_triplets_float_host(
181
- int rows_per_block,
182
- int cols_per_block,
181
+ WP_API void bsr_matrix_from_triplets_host(
182
+ int block_size,
183
+ int scalar_size_in_bytes,
183
184
  int row_count,
184
- int tpl_nnz,
185
- int* tpl_rows,
186
- int* tpl_columns,
187
- void* tpl_values,
188
- bool prune_numerical_zeros,
189
- bool masked,
185
+ int col_count,
186
+ int tpl_nnz_upper_bound,
187
+ const int* tpl_nnz,
188
+ const int* tpl_rows,
189
+ const int* tpl_columns,
190
+ const void* tpl_values,
191
+ const uint64_t scalar_zero_mask,
192
+ bool masked_topology,
193
+ int* summed_block_offsets,
194
+ int* summed_block_indices,
190
195
  int* bsr_offsets,
191
196
  int* bsr_columns,
192
- void* bsr_values,
193
197
  int* bsr_nnz,
194
198
  void* bsr_nnz_event);
195
- WP_API void bsr_matrix_from_triplets_double_host(
196
- int rows_per_block,
197
- int cols_per_block,
199
+ WP_API void bsr_matrix_from_triplets_device(
200
+ int block_size,
201
+ int scalar_size_in_bytes,
198
202
  int row_count,
199
- int tpl_nnz,
200
- int* tpl_rows,
201
- int* tpl_columns,
202
- void* tpl_values,
203
- bool prune_numerical_zeros,
204
- bool masked,
203
+ int col_count,
204
+ int tpl_nnz_upper_bound,
205
+ const int* tpl_nnz,
206
+ const int* tpl_rows,
207
+ const int* tpl_columns,
208
+ const void* tpl_values,
209
+ const uint64_t scalar_zero_mask,
210
+ bool masked_topology,
211
+ int* summed_block_offsets,
212
+ int* summed_block_indices,
205
213
  int* bsr_offsets,
206
214
  int* bsr_columns,
207
- void* bsr_values,
208
- int* bsr_nnz,
209
- void* bsr_nnz_event);
210
- WP_API void bsr_matrix_from_triplets_float_device(
211
- int rows_per_block,
212
- int cols_per_block,
213
- int row_count,
214
- int tpl_nnz,
215
- int* tpl_rows,
216
- int* tpl_columns,
217
- void* tpl_values,
218
- bool prune_numerical_zeros,
219
- bool masked,
220
- int* bsr_offsets,
221
- int* bsr_columns,
222
- void* bsr_values,
223
- int* bsr_nnz,
224
- void* bsr_nnz_event);
225
- WP_API void bsr_matrix_from_triplets_double_device(
226
- int rows_per_block,
227
- int cols_per_block,
228
- int row_count,
229
- int tpl_nnz,
230
- int* tpl_rows,
231
- int* tpl_columns,
232
- void* tpl_values,
233
- bool prune_numerical_zeros,
234
- bool masked,
235
- int* bsr_offsets,
236
- int* bsr_columns,
237
- void* bsr_values,
238
215
  int* bsr_nnz,
239
216
  void* bsr_nnz_event);
240
217
 
241
- WP_API void bsr_transpose_float_host(int rows_per_block, int cols_per_block,
242
- int row_count, int col_count, int nnz,
243
- int* bsr_offsets, int* bsr_columns,
244
- void* bsr_values,
245
- int* transposed_bsr_offsets,
246
- int* transposed_bsr_columns,
247
- void* transposed_bsr_values);
248
- WP_API void bsr_transpose_double_host(int rows_per_block, int cols_per_block,
218
+ WP_API void bsr_transpose_host(
249
219
  int row_count, int col_count, int nnz,
250
- int* bsr_offsets, int* bsr_columns,
251
- void* bsr_values,
220
+ const int* bsr_offsets, const int* bsr_columns,
252
221
  int* transposed_bsr_offsets,
253
222
  int* transposed_bsr_columns,
254
- void* transposed_bsr_values);
255
- WP_API void bsr_transpose_float_device(int rows_per_block, int cols_per_block,
223
+ int* src_block_indices
224
+ );
225
+ WP_API void bsr_transpose_device(
256
226
  int row_count, int col_count, int nnz,
257
- int* bsr_offsets, int* bsr_columns,
258
- void* bsr_values,
227
+ const int* bsr_offsets, const int* bsr_columns,
259
228
  int* transposed_bsr_offsets,
260
229
  int* transposed_bsr_columns,
261
- void* transposed_bsr_values);
262
- WP_API void bsr_transpose_double_device(int rows_per_block, int cols_per_block,
263
- int row_count, int col_count, int nnz,
264
- int* bsr_offsets, int* bsr_columns,
265
- void* bsr_values,
266
- int* transposed_bsr_offsets,
267
- int* transposed_bsr_columns,
268
- void* transposed_bsr_values);
230
+ int* src_block_indices);
269
231
 
270
232
 
271
233
  WP_API int cuda_driver_version(); // CUDA driver version
@@ -279,6 +241,7 @@ extern "C"
279
241
  WP_API void* cuda_device_get_primary_context(int ordinal);
280
242
  WP_API const char* cuda_device_get_name(int ordinal);
281
243
  WP_API int cuda_device_get_arch(int ordinal);
244
+ WP_API int cuda_device_get_sm_count(int ordinal);
282
245
  WP_API void cuda_device_get_uuid(int ordinal, char uuid[16]);
283
246
  WP_API int cuda_device_get_pci_domain_id(int ordinal);
284
247
  WP_API int cuda_device_get_pci_bus_id(int ordinal);
@@ -345,13 +308,23 @@ extern "C"
345
308
 
346
309
  WP_API bool cuda_graph_begin_capture(void* context, void* stream, int external);
347
310
  WP_API bool cuda_graph_end_capture(void* context, void* stream, void** graph_ret);
311
+ WP_API bool cuda_graph_create_exec(void* context, void* stream, void* graph, void** graph_exec_ret);
348
312
  WP_API bool cuda_graph_launch(void* graph, void* stream);
349
313
  WP_API bool cuda_graph_destroy(void* context, void* graph);
314
+ WP_API bool cuda_graph_exec_destroy(void* context, void* graph_exec);
315
+ WP_API bool capture_debug_dot_print(void* graph, const char *path, uint32_t flags);
316
+
317
+ WP_API bool cuda_graph_insert_if_else(void* context, void* stream, int* condition, void** if_graph_ret, void** else_graph_ret);
318
+ WP_API bool cuda_graph_insert_while(void* context, void* stream, int* condition, void** body_graph_ret, uint64_t* handle_ret);
319
+ WP_API bool cuda_graph_set_condition(void* context, void* stream, int* condition, uint64_t handle);
320
+ WP_API bool cuda_graph_pause_capture(void* context, void* stream, void** graph_ret);
321
+ WP_API bool cuda_graph_resume_capture(void* context, void* stream, void* graph);
322
+ WP_API bool cuda_graph_insert_child_graph(void* context, void* stream, void* child_graph);
350
323
 
351
- WP_API size_t cuda_compile_program(const char* cuda_src, const char* program_name, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, bool lineinfo, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes, int* ltoir_input_types);
324
+ WP_API size_t cuda_compile_program(const char* cuda_src, const char* program_name, int arch, const char* include_dir, int num_cuda_include_dirs, const char** cuda_include_dirs, bool debug, bool verbose, bool verify_fp, bool fast_math, bool fuse_fp, bool lineinfo, bool compile_time_trace, const char* output_path, size_t num_ltoirs, char** ltoirs, size_t* ltoir_sizes, int* ltoir_input_types);
352
325
  WP_API bool cuda_compile_fft(const char* ltoir_output_path, const char* symbol_name, int num_include_dirs, const char** include_dirs, const char* mathdx_include_dir, int arch, int size, int elements_per_thread, int direction, int precision, int* shared_memory_size);
353
326
  WP_API bool cuda_compile_dot(const char* ltoir_output_path, const char* symbol_name, int num_include_dirs, const char** include_dirs, const char* mathdx_include_dir, int arch, int M, int N, int K, int precision_A, int precision_B, int precision_C, int type, int arrangement_A, int arrangement_B, int arrangement_C, int num_threads);
354
- WP_API bool cuda_compile_solver(const char* fatbin_output_path, const char* ltoir_output_path, const char* symbol_name, int num_include_dirs, const char** include_dirs, const char* mathdx_include_dir, int arch, int M, int N, int function, int precision, int fill_mode, int num_threads);
327
+ WP_API bool cuda_compile_solver(const char* fatbin_output_path, const char* ltoir_output_path, const char* symbol_name, int num_include_dirs, const char** include_dirs, const char* mathdx_include_dir, int arch, int M, int N, int NRHS, int function, int side, int diag, int precision, int arrangement_A, int arrangement_B, int fill_mode, int num_threads);
355
328
 
356
329
  WP_API void* cuda_load_module(void* context, const char* ptx);
357
330
  WP_API void cuda_unload_module(void* context, void* module);
warp/optim/linear.py CHANGED
@@ -39,7 +39,11 @@ class LinearOperator:
39
39
  .. code-block:: python
40
40
 
41
41
  def matvec(x: wp.array, y: wp.array, z: wp.array, alpha: Scalar, beta: Scalar):
42
- '''Performs the operation z = alpha * x + beta * y'''
42
+ '''Perform a generalized matrix-vector product.
43
+
44
+ This function computes the operation z = alpha * (A @ x) + beta * y, where 'A'
45
+ is the linear operator represented by this class.
46
+ '''
43
47
  ...
44
48
 
45
49
  For performance reasons, by default the iterative linear solvers in this module will try to capture the calls
warp/paddle.py CHANGED
@@ -16,7 +16,7 @@
16
16
  from __future__ import annotations
17
17
 
18
18
  import ctypes
19
- from typing import TYPE_CHECKING, Optional, Union
19
+ from typing import TYPE_CHECKING
20
20
 
21
21
  import numpy
22
22
 
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
29
29
 
30
30
 
31
31
  # return the warp device corresponding to a paddle device
32
- def device_from_paddle(paddle_device: Union[Place, CPUPlace, CUDAPinnedPlace, CUDAPlace, str]) -> warp.context.Device:
32
+ def device_from_paddle(paddle_device: Place | CPUPlace | CUDAPinnedPlace | CUDAPlace | str) -> warp.context.Device:
33
33
  """Return the Warp device corresponding to a Paddle device.
34
34
 
35
35
  Args:
@@ -218,9 +218,9 @@ dtype_is_compatible.compatible_sets = None
218
218
  # wrap a paddle tensor to a wp array, data is not copied
219
219
  def from_paddle(
220
220
  t: paddle.Tensor,
221
- dtype: Optional[paddle.dtype] = None,
222
- requires_grad: Optional[bool] = None,
223
- grad: Optional[paddle.Tensor] = None,
221
+ dtype: paddle.dtype | None = None,
222
+ requires_grad: bool | None = None,
223
+ grad: paddle.Tensor | None = None,
224
224
  return_ctype: bool = False,
225
225
  ) -> warp.array:
226
226
  """Convert a Paddle tensor to a Warp array without copying the data.
@@ -339,9 +339,8 @@ def from_paddle(
339
339
  return a
340
340
 
341
341
 
342
- def to_paddle(a: warp.array, requires_grad: bool = None) -> paddle.Tensor:
343
- """
344
- Convert a Warp array to a Paddle tensor without copying the data.
342
+ def to_paddle(a: warp.array, requires_grad: bool | None = None) -> paddle.Tensor:
343
+ """Convert a Warp array to a Paddle tensor without copying the data.
345
344
 
346
345
  Args:
347
346
  a (warp.array): The Warp array to convert.
warp/py.typed ADDED
File without changes
@@ -320,15 +320,14 @@ def update_vbo_transforms(
320
320
  @wp.kernel
321
321
  def update_vbo_vertices(
322
322
  points: wp.array(dtype=wp.vec3),
323
- scale: wp.vec3,
324
323
  # outputs
325
324
  vbo_vertices: wp.array(dtype=float, ndim=2),
326
325
  ):
327
326
  tid = wp.tid()
328
327
  p = points[tid]
329
- vbo_vertices[tid, 0] = p[0] * scale[0]
330
- vbo_vertices[tid, 1] = p[1] * scale[1]
331
- vbo_vertices[tid, 2] = p[2] * scale[2]
328
+ vbo_vertices[tid, 0] = p[0]
329
+ vbo_vertices[tid, 1] = p[1]
330
+ vbo_vertices[tid, 2] = p[2]
332
331
 
333
332
 
334
333
  @wp.kernel
@@ -422,7 +421,6 @@ def compute_gfx_vertices(
422
421
  def compute_average_normals(
423
422
  indices: wp.array(dtype=int, ndim=2),
424
423
  vertices: wp.array(dtype=wp.vec3),
425
- scale: wp.vec3,
426
424
  # outputs
427
425
  normals: wp.array(dtype=wp.vec3),
428
426
  faces_per_vertex: wp.array(dtype=int),
@@ -431,9 +429,9 @@ def compute_average_normals(
431
429
  i = indices[tid, 0]
432
430
  j = indices[tid, 1]
433
431
  k = indices[tid, 2]
434
- v0 = vertices[i] * scale[0]
435
- v1 = vertices[j] * scale[1]
436
- v2 = vertices[k] * scale[2]
432
+ v0 = vertices[i]
433
+ v1 = vertices[j]
434
+ v2 = vertices[k]
437
435
  n = wp.normalize(wp.cross(v1 - v0, v2 - v0))
438
436
  wp.atomic_add(normals, i, n)
439
437
  wp.atomic_add(faces_per_vertex, i, 1)
@@ -448,16 +446,15 @@ def assemble_gfx_vertices(
448
446
  vertices: wp.array(dtype=wp.vec3, ndim=1),
449
447
  normals: wp.array(dtype=wp.vec3),
450
448
  faces_per_vertex: wp.array(dtype=int),
451
- scale: wp.vec3,
452
449
  # outputs
453
450
  gfx_vertices: wp.array(dtype=float, ndim=2),
454
451
  ):
455
452
  tid = wp.tid()
456
453
  v = vertices[tid]
457
454
  n = normals[tid] / float(faces_per_vertex[tid])
458
- gfx_vertices[tid, 0] = v[0] * scale[0]
459
- gfx_vertices[tid, 1] = v[1] * scale[1]
460
- gfx_vertices[tid, 2] = v[2] * scale[2]
455
+ gfx_vertices[tid, 0] = v[0]
456
+ gfx_vertices[tid, 1] = v[1]
457
+ gfx_vertices[tid, 2] = v[2]
461
458
  gfx_vertices[tid, 3] = n[0]
462
459
  gfx_vertices[tid, 4] = n[1]
463
460
  gfx_vertices[tid, 5] = n[2]
@@ -691,7 +688,7 @@ class ShapeInstancer:
691
688
  cls.gl = gl
692
689
 
693
690
  def __new__(cls, *args, **kwargs):
694
- instance = super(ShapeInstancer, cls).__new__(cls)
691
+ instance = super().__new__(cls)
695
692
  instance.instance_transform_gl_buffer = None
696
693
  instance.vao = None
697
694
  return instance
@@ -1858,7 +1855,7 @@ class OpenGLRenderer:
1858
1855
  self._scaling = scaling
1859
1856
  self.update_model_matrix()
1860
1857
 
1861
- def begin_frame(self, t: float = None):
1858
+ def begin_frame(self, t: float | None = None):
1862
1859
  self._last_begin_frame_time = time.time()
1863
1860
  self.time = t or self.clock_time
1864
1861
 
@@ -2295,9 +2292,9 @@ Instances: {len(self._instances)}"""
2295
2292
  name: str,
2296
2293
  shape: int,
2297
2294
  body,
2298
- pos,
2299
- rot,
2300
- scale=(1.0, 1.0, 1.0),
2295
+ pos: tuple,
2296
+ rot: tuple,
2297
+ scale: tuple = (1.0, 1.0, 1.0),
2301
2298
  color1=None,
2302
2299
  color2=None,
2303
2300
  custom_index: int = -1,
@@ -2445,7 +2442,7 @@ Instances: {len(self._instances)}"""
2445
2442
 
2446
2443
  gl.glBindVertexArray(0)
2447
2444
 
2448
- def update_shape_instance(self, name, pos=None, rot=None, color1=None, color2=None, visible=None):
2445
+ def update_shape_instance(self, name, pos=None, rot=None, color1=None, color2=None, scale=None, visible=None):
2449
2446
  """Update the instance properties of the shape
2450
2447
 
2451
2448
  Args:
@@ -2461,7 +2458,7 @@ Instances: {len(self._instances)}"""
2461
2458
  self._switch_context()
2462
2459
 
2463
2460
  if name in self._instances:
2464
- i, body, shape, tf, scale, old_color1, old_color2, v = self._instances[name]
2461
+ i, body, shape, tf, old_scale, old_color1, old_color2, v = self._instances[name]
2465
2462
  if visible is None:
2466
2463
  visible = v
2467
2464
  new_tf = np.copy(tf)
@@ -2474,7 +2471,7 @@ Instances: {len(self._instances)}"""
2474
2471
  body,
2475
2472
  shape,
2476
2473
  new_tf,
2477
- scale,
2474
+ old_scale if scale is None else scale,
2478
2475
  old_color1 if color1 is None else color1,
2479
2476
  old_color2 if color2 is None else color2,
2480
2477
  visible,
@@ -2720,10 +2717,11 @@ Instances: {len(self._instances)}"""
2720
2717
  length: float,
2721
2718
  color: tuple = (1.0, 1.0, 1.0),
2722
2719
  color2=None,
2723
- parent_body: str = None,
2720
+ parent_body: str | None = None,
2724
2721
  is_template: bool = False,
2725
2722
  u_scaling=1.0,
2726
2723
  v_scaling=1.0,
2724
+ visible: bool = True,
2727
2725
  ):
2728
2726
  """Add a plane for visualization
2729
2727
 
@@ -2811,9 +2809,10 @@ Instances: {len(self._instances)}"""
2811
2809
  pos: tuple,
2812
2810
  rot: tuple,
2813
2811
  radius: float,
2814
- parent_body: str = None,
2812
+ parent_body: str | None = None,
2815
2813
  is_template: bool = False,
2816
- color=None,
2814
+ color: tuple[float, float, float] | None = None,
2815
+ visible: bool = True,
2817
2816
  ):
2818
2817
  """Add a sphere for visualization
2819
2818
 
@@ -2843,10 +2842,11 @@ Instances: {len(self._instances)}"""
2843
2842
  rot: tuple,
2844
2843
  radius: float,
2845
2844
  half_height: float,
2846
- parent_body: str = None,
2845
+ parent_body: str | None = None,
2847
2846
  is_template: bool = False,
2848
2847
  up_axis: int = 1,
2849
- color: tuple = None,
2848
+ color: tuple[float, float, float] | None = None,
2849
+ visible: bool = True,
2850
2850
  ):
2851
2851
  """Add a capsule for visualization
2852
2852
 
@@ -2878,10 +2878,11 @@ Instances: {len(self._instances)}"""
2878
2878
  rot: tuple,
2879
2879
  radius: float,
2880
2880
  half_height: float,
2881
- parent_body: str = None,
2881
+ parent_body: str | None = None,
2882
2882
  is_template: bool = False,
2883
2883
  up_axis: int = 1,
2884
- color: tuple = None,
2884
+ color: tuple[float, float, float] | None = None,
2885
+ visible: bool = True,
2885
2886
  ):
2886
2887
  """Add a cylinder for visualization
2887
2888
 
@@ -2913,10 +2914,11 @@ Instances: {len(self._instances)}"""
2913
2914
  rot: tuple,
2914
2915
  radius: float,
2915
2916
  half_height: float,
2916
- parent_body: str = None,
2917
+ parent_body: str | None = None,
2917
2918
  is_template: bool = False,
2918
2919
  up_axis: int = 1,
2919
- color: tuple = None,
2920
+ color: tuple[float, float, float] | None = None,
2921
+ visible: bool = True,
2920
2922
  ):
2921
2923
  """Add a cone for visualization
2922
2924
 
@@ -2947,9 +2949,10 @@ Instances: {len(self._instances)}"""
2947
2949
  pos: tuple,
2948
2950
  rot: tuple,
2949
2951
  extents: tuple,
2950
- parent_body: str = None,
2952
+ parent_body: str | None = None,
2951
2953
  is_template: bool = False,
2952
- color: tuple = None,
2954
+ color: tuple[float, float, float] | None = None,
2955
+ visible: bool = True,
2953
2956
  ):
2954
2957
  """Add a box for visualization
2955
2958
 
@@ -2962,7 +2965,7 @@ Instances: {len(self._instances)}"""
2962
2965
  geo_hash = hash(("box", tuple(extents)))
2963
2966
  if geo_hash in self._shape_geo_hash:
2964
2967
  shape = self._shape_geo_hash[geo_hash]
2965
- if self.update_shape_instance(name, pos, rot):
2968
+ if self.update_shape_instance(name, pos, rot, color1=color, color2=color):
2966
2969
  return shape
2967
2970
  else:
2968
2971
  vertices, indices = self._create_box_mesh(extents)
@@ -2982,9 +2985,10 @@ Instances: {len(self._instances)}"""
2982
2985
  rot=(0.0, 0.0, 0.0, 1.0),
2983
2986
  scale=(1.0, 1.0, 1.0),
2984
2987
  update_topology=False,
2985
- parent_body: str = None,
2988
+ parent_body: str | None = None,
2986
2989
  is_template: bool = False,
2987
2990
  smooth_shading: bool = True,
2991
+ visible: bool = True,
2988
2992
  ):
2989
2993
  """Add a mesh for visualization
2990
2994
 
@@ -3024,50 +3028,54 @@ Instances: {len(self._instances)}"""
3024
3028
  if not update_topology:
3025
3029
  if name in self._instances:
3026
3030
  # Update the instance's transform.
3027
- self.update_shape_instance(name, pos, rot, color1=colors)
3031
+ self.update_shape_instance(name, pos, rot, color1=colors, color2=colors, scale=scale, visible=visible)
3028
3032
 
3029
3033
  if shape is not None:
3030
3034
  # Update the shape's point positions.
3031
- self.update_shape_vertices(shape, points, scale)
3035
+ self.update_shape_vertices(shape, points)
3032
3036
 
3033
3037
  if not is_template and name not in self._instances:
3034
3038
  # Create a new instance.
3035
3039
  body = self._resolve_body_id(parent_body)
3036
- self.add_shape_instance(name, shape, body, pos, rot, color1=colors)
3040
+ self.add_shape_instance(name, shape, body, pos, rot, color1=colors, scale=scale)
3037
3041
 
3038
3042
  return shape
3039
3043
 
3040
3044
  # No existing shape for the given mesh was found, or its topology may have changed,
3041
3045
  # so we need to define a new one either way.
3042
- if smooth_shading:
3043
- normals = wp.zeros(point_count, dtype=wp.vec3)
3044
- vertices = wp.array(points, dtype=wp.vec3)
3045
- faces_per_vertex = wp.zeros(point_count, dtype=int)
3046
- wp.launch(
3047
- compute_average_normals,
3048
- dim=idx_count,
3049
- inputs=[wp.array(indices, dtype=int), vertices, scale],
3050
- outputs=[normals, faces_per_vertex],
3051
- )
3052
- gfx_vertices = wp.zeros((point_count, 8), dtype=float)
3053
- wp.launch(
3054
- assemble_gfx_vertices,
3055
- dim=point_count,
3056
- inputs=[vertices, normals, faces_per_vertex, scale],
3057
- outputs=[gfx_vertices],
3058
- )
3059
- gfx_vertices = gfx_vertices.numpy()
3060
- gfx_indices = indices.flatten()
3061
- else:
3062
- gfx_vertices = wp.zeros((idx_count * 3, 8), dtype=float)
3063
- wp.launch(
3064
- compute_gfx_vertices,
3065
- dim=idx_count,
3066
- inputs=[wp.array(indices, dtype=int), wp.array(points, dtype=wp.vec3), scale],
3067
- outputs=[gfx_vertices],
3068
- )
3069
- gfx_vertices = gfx_vertices.numpy()
3070
- gfx_indices = np.arange(idx_count * 3)
3046
+ with wp.ScopedDevice(self._device):
3047
+ if smooth_shading:
3048
+ normals = wp.zeros(point_count, dtype=wp.vec3)
3049
+ vertices = wp.array(points, dtype=wp.vec3)
3050
+ faces_per_vertex = wp.zeros(point_count, dtype=int)
3051
+ wp.launch(
3052
+ compute_average_normals,
3053
+ dim=idx_count,
3054
+ inputs=[wp.array(indices, dtype=int), vertices],
3055
+ outputs=[normals, faces_per_vertex],
3056
+ record_tape=False,
3057
+ )
3058
+ gfx_vertices = wp.zeros((point_count, 8), dtype=float)
3059
+ wp.launch(
3060
+ assemble_gfx_vertices,
3061
+ dim=point_count,
3062
+ inputs=[vertices, normals, faces_per_vertex],
3063
+ outputs=[gfx_vertices],
3064
+ record_tape=False,
3065
+ )
3066
+ gfx_vertices = gfx_vertices.numpy()
3067
+ gfx_indices = indices.flatten()
3068
+ else:
3069
+ gfx_vertices = wp.zeros((idx_count * 3, 8), dtype=float)
3070
+ wp.launch(
3071
+ compute_gfx_vertices,
3072
+ dim=idx_count,
3073
+ inputs=[wp.array(indices, dtype=int), wp.array(points, dtype=wp.vec3)],
3074
+ outputs=[gfx_vertices],
3075
+ record_tape=False,
3076
+ )
3077
+ gfx_vertices = gfx_vertices.numpy()
3078
+ gfx_indices = np.arange(idx_count * 3)
3071
3079
 
3072
3080
  # If there was a shape for the given mesh, clean it up.
3073
3081
  if shape is not None:
@@ -3083,7 +3091,7 @@ Instances: {len(self._instances)}"""
3083
3091
  if not is_template:
3084
3092
  # Create a new instance if necessary.
3085
3093
  body = self._resolve_body_id(parent_body)
3086
- self.add_shape_instance(name, shape, body, pos, rot, color1=colors)
3094
+ self.add_shape_instance(name, shape, body, pos, rot, color1=colors, scale=scale)
3087
3095
 
3088
3096
  return shape
3089
3097
 
@@ -3094,12 +3102,13 @@ Instances: {len(self._instances)}"""
3094
3102
  rot: tuple,
3095
3103
  base_radius: float,
3096
3104
  base_height: float,
3097
- cap_radius: float = None,
3098
- cap_height: float = None,
3099
- parent_body: str = None,
3105
+ cap_radius: float | None = None,
3106
+ cap_height: float | None = None,
3107
+ parent_body: str | None = None,
3100
3108
  is_template: bool = False,
3101
3109
  up_axis: int = 1,
3102
- color: tuple[float, float, float] = None,
3110
+ color: tuple[float, float, float] | None = None,
3111
+ visible: bool = True,
3103
3112
  ):
3104
3113
  """Add a arrow for visualization
3105
3114
 
@@ -3127,10 +3136,16 @@ Instances: {len(self._instances)}"""
3127
3136
  self.add_shape_instance(name, shape, body, pos, rot, color1=color, color2=color)
3128
3137
  return shape
3129
3138
 
3130
- def render_ref(self, name: str, path: str, pos: tuple, rot: tuple, scale: tuple, color: tuple = None):
3131
- """
3132
- Create a reference (instance) with the given name to the given path.
3133
- """
3139
+ def render_ref(
3140
+ self,
3141
+ name: str,
3142
+ path: str,
3143
+ pos: tuple,
3144
+ rot: tuple,
3145
+ scale: tuple,
3146
+ color: tuple[float, float, float] | None = None,
3147
+ ):
3148
+ """Create a reference (instance) with the given name to the given path."""
3134
3149
 
3135
3150
  if path in self._instances:
3136
3151
  _, body, shape, _, original_scale, color1, color2 = self._instances[path]
@@ -3141,7 +3156,7 @@ Instances: {len(self._instances)}"""
3141
3156
 
3142
3157
  raise Exception("Cannot create reference to path: " + path)
3143
3158
 
3144
- def render_points(self, name: str, points, radius, colors=None):
3159
+ def render_points(self, name: str, points, radius, colors=None, as_spheres: bool = True, visible: bool = True):
3145
3160
  """Add a set of points
3146
3161
 
3147
3162
  Args:
@@ -3199,7 +3214,7 @@ Instances: {len(self._instances)}"""
3199
3214
  if name not in self._shape_instancers:
3200
3215
  instancer = ShapeInstancer(self._shape_shader, self._device)
3201
3216
  vertices, indices = self._create_capsule_mesh(radius, 0.5)
3202
- if color is None or isinstance(color, list) and len(color) > 0 and isinstance(color[0], list):
3217
+ if color is None or (isinstance(color, list) and len(color) > 0 and isinstance(color[0], list)):
3203
3218
  color = tab10_color_map(len(self._shape_geo_hash))
3204
3219
  instancer.register_shape(vertices, indices, color, color)
3205
3220
  instancer.allocate_instances(np.zeros((len(lines), 3)))
@@ -3220,7 +3235,15 @@ Instances: {len(self._instances)}"""
3220
3235
  device=self._device,
3221
3236
  )
3222
3237
 
3223
- def render_line_list(self, name: str, vertices, indices, color: tuple = None, radius: float = 0.01):
3238
+ def render_line_list(
3239
+ self,
3240
+ name: str,
3241
+ vertices,
3242
+ indices,
3243
+ color: tuple[float, float, float] | None = None,
3244
+ radius: float = 0.01,
3245
+ visible: bool = True,
3246
+ ):
3224
3247
  """Add a line list as a set of capsules
3225
3248
 
3226
3249
  Args:
@@ -3235,7 +3258,14 @@ Instances: {len(self._instances)}"""
3235
3258
  lines = np.array(lines)
3236
3259
  self._render_lines(name, lines, color, radius)
3237
3260
 
3238
- def render_line_strip(self, name: str, vertices, color: tuple = None, radius: float = 0.01):
3261
+ def render_line_strip(
3262
+ self,
3263
+ name: str,
3264
+ vertices,
3265
+ color: tuple[float, float, float] | None = None,
3266
+ radius: float = 0.01,
3267
+ visible: bool = True,
3268
+ ):
3239
3269
  """Add a line strip as a set of capsules
3240
3270
 
3241
3271
  Args:
@@ -3249,7 +3279,7 @@ Instances: {len(self._instances)}"""
3249
3279
  lines = np.array(lines)
3250
3280
  self._render_lines(name, lines, color, radius)
3251
3281
 
3252
- def update_shape_vertices(self, shape, points, scale):
3282
+ def update_shape_vertices(self, shape, points):
3253
3283
  if isinstance(points, wp.array):
3254
3284
  wp_points = points.to(self._device)
3255
3285
  else:
@@ -3262,7 +3292,7 @@ Instances: {len(self._instances)}"""
3262
3292
  wp.launch(
3263
3293
  update_vbo_vertices,
3264
3294
  dim=vertices_shape[0],
3265
- inputs=[wp_points, scale],
3295
+ inputs=[wp_points],
3266
3296
  outputs=[vbo_vertices],
3267
3297
  device=self._device,
3268
3298
  )