Skip to content

Commit e5167cf

Browse files
authored
[CHANGING][MISC] Disable box-box by default. (#1982)
* Avoid memory allocation if possible. * Disable box-box by default. * Reduce max number of collision pairs by default.
1 parent ef83901 commit e5167cf

File tree

5 files changed

+55
-40
lines changed

5 files changed

+55
-40
lines changed

genesis/engine/solvers/rigid/constraint_solver_decomp.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ def constraint_solver_kernel_reset(
401401
constraint_state.qacc_ws[i_d, i_b] = 0
402402
for i_c in range(len_constraints):
403403
constraint_state.jac[i_c, i_d, i_b] = 0
404-
for i_c in range(len_constraints):
405-
constraint_state.jac_n_relevant_dofs[i_c, i_b] = 0
404+
if ti.static(static_rigid_sim_config.sparse_solve):
405+
for i_c in range(len_constraints):
406+
constraint_state.jac_n_relevant_dofs[i_c, i_b] = 0
406407

407408

408409
@ti.func
@@ -980,8 +981,9 @@ def func_equality_weld(
980981
jac_qvel[i_con - n_con] + constraint_state.jac[i_con, i_d, i_b] * dofs_state.vel[i_d, i_b]
981982
)
982983

983-
for i_con in range(n_con, n_con + 3):
984-
constraint_state.jac_n_relevant_dofs[i_con, i_b] = con_n_relevant_dofs
984+
if ti.static(static_rigid_sim_config.sparse_solve):
985+
for i_con in range(n_con, n_con + 3):
986+
constraint_state.jac_n_relevant_dofs[i_con, i_b] = con_n_relevant_dofs
985987

986988
for i_con in range(n_con, n_con + 3):
987989
imp, aref = gu.imp_aref(sol_params, -pos_imp, jac_qvel[i_con - n_con], rot_error[i_con - n_con])

genesis/options/solvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class RigidOptions(Options):
363363
enable_self_collision: bool = True
364364
enable_adjacent_collision: bool = False
365365
disable_constraint: bool = False
366-
max_collision_pairs: int = 300
366+
max_collision_pairs: int = 200
367367
multiplier_collision_broad_phase: int = 8
368368
integrator: gs.integrator = gs.integrator.approximate_implicitfast
369369
IK_max_targets: int = 6
@@ -385,7 +385,7 @@ class RigidOptions(Options):
385385
contact_resolve_time: Optional[float] = None
386386
constraint_timeconst: float = 0.01
387387
use_contact_island: bool = False
388-
box_box_detection: Optional[bool] = None
388+
box_box_detection: bool = False
389389

390390
# hibernation threshold
391391
use_hibernation: bool = False

genesis/utils/array_class.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ def get_constraint_state(constraint_solver, solver):
232232

233233
efc_AR_shape = maybe_shape((len_constraints_, len_constraints_, _B), solver._options.noslip_iterations > 0)
234234
efc_b_shape = maybe_shape((len_constraints_, _B), solver._options.noslip_iterations > 0)
235-
jac_relevant_dofs_shape = (len_constraints_, solver.n_dofs_, _B)
236-
jac_n_relevant_dofs_shape = (len_constraints_, _B)
235+
jac_relevant_dofs_shape = maybe_shape((len_constraints_, solver.n_dofs_, _B), constraint_solver.sparse_solve)
236+
jac_n_relevant_dofs_shape = maybe_shape((len_constraints_, _B), constraint_solver.sparse_solve)
237237

238238
return StructConstraintState(
239239
n_constraints=V(dtype=gs.ti_int, shape=(_B,)),
@@ -513,6 +513,19 @@ def get_collider_state(
513513
max_contact_pairs = max_collision_pairs * collider_static_config.n_contacts_per_pair
514514
requires_grad = static_rigid_sim_config.requires_grad
515515

516+
box_depth_shape = maybe_shape(
517+
(collider_static_config.n_contacts_per_pair, _B), static_rigid_sim_config.box_box_detection
518+
)
519+
box_points_shape = maybe_shape(
520+
(collider_static_config.n_contacts_per_pair, _B), static_rigid_sim_config.box_box_detection
521+
)
522+
box_pts_shape = maybe_shape((6, _B), static_rigid_sim_config.box_box_detection)
523+
box_lines_shape = maybe_shape((4, _B), static_rigid_sim_config.box_box_detection)
524+
box_linesu_shape = maybe_shape((4, _B), static_rigid_sim_config.box_box_detection)
525+
box_axi_shape = maybe_shape((3, _B), static_rigid_sim_config.box_box_detection)
526+
box_ppts2_shape = maybe_shape((4, 2, _B), static_rigid_sim_config.box_box_detection)
527+
box_pu_shape = maybe_shape((4, _B), static_rigid_sim_config.box_box_detection)
528+
516529
return StructColliderState(
517530
sort_buffer=get_sort_buffer(solver),
518531
contact_data=get_contact_data(solver, max_contact_pairs, requires_grad),
@@ -521,14 +534,14 @@ def get_collider_state(
521534
broad_collision_pairs=V_VEC(2, dtype=gs.ti_int, shape=(max(max_collision_pairs_broad, 1), _B)),
522535
active_buffer_awake=V(dtype=gs.ti_int, shape=(n_geoms, _B)),
523536
active_buffer_hib=V(dtype=gs.ti_int, shape=(n_geoms, _B)),
524-
box_depth=V(dtype=gs.ti_float, shape=(collider_static_config.n_contacts_per_pair, _B)),
525-
box_points=V_VEC(3, dtype=gs.ti_float, shape=(collider_static_config.n_contacts_per_pair, _B)),
526-
box_pts=V_VEC(3, dtype=gs.ti_float, shape=(6, _B)),
527-
box_lines=V_VEC(6, dtype=gs.ti_float, shape=(4, _B)),
528-
box_linesu=V_VEC(6, dtype=gs.ti_float, shape=(4, _B)),
529-
box_axi=V_VEC(3, dtype=gs.ti_float, shape=(3, _B)),
530-
box_ppts2=V(dtype=gs.ti_float, shape=(4, 2, _B)),
531-
box_pu=V_VEC(3, dtype=gs.ti_float, shape=(4, _B)),
537+
box_depth=V(dtype=gs.ti_float, shape=box_depth_shape),
538+
box_points=V_VEC(3, dtype=gs.ti_float, shape=box_points_shape),
539+
box_pts=V_VEC(3, dtype=gs.ti_float, shape=box_pts_shape),
540+
box_lines=V_VEC(6, dtype=gs.ti_float, shape=box_lines_shape),
541+
box_linesu=V_VEC(6, dtype=gs.ti_float, shape=box_linesu_shape),
542+
box_axi=V_VEC(3, dtype=gs.ti_float, shape=box_axi_shape),
543+
box_ppts2=V(dtype=gs.ti_float, shape=box_ppts2_shape),
544+
box_pu=V_VEC(3, dtype=gs.ti_float, shape=box_pu_shape),
532545
xyz_max_min=V(dtype=gs.ti_float, shape=(6, _B)),
533546
prism=V_VEC(3, dtype=gs.ti_float, shape=(6, _B)),
534547
n_contacts=V(dtype=gs.ti_int, shape=(_B,)),

tests/test_gstaichi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_static(
185185
env = dict(os.environ)
186186
env.update(env_changes)
187187

188-
proc = subprocess.run(cmd_line, capture_output=True, text=True, env=env, cwd=MODULE_ROOT_DIR)
188+
proc = subprocess.run(cmd_line, capture_output=True, text=True, encoding="utf-8", env=env, cwd=MODULE_ROOT_DIR)
189189
if proc.returncode == RET_SKIP:
190190
pytest.skip(proc.stderr)
191191
elif proc.returncode != RET_SUCCESS:
@@ -277,7 +277,7 @@ def test_num_envs(use_ndarray: bool, enable_pure: bool, test_backend: str, tmp_p
277277
cmd_line += ["--expected-use-src-ll-cache"]
278278
if expected_src_ll_cache_hit:
279279
cmd_line += ["--expected-src-ll-cache-hit"]
280-
proc = subprocess.run(cmd_line, capture_output=True, text=True, env=env, cwd=MODULE_ROOT_DIR)
280+
proc = subprocess.run(cmd_line, capture_output=True, text=True, encoding="utf-8", env=env, cwd=MODULE_ROOT_DIR)
281281
if proc.returncode == RET_SKIP:
282282
pytest.skip(proc.stderr)
283283
elif proc.returncode != RET_SUCCESS:
@@ -380,7 +380,7 @@ def test_ndarray_no_compile(
380380
env["GS_ENABLE_NDARRAY"] = "1"
381381
env["TI_OFFLINE_CACHE"] = "1"
382382
env["TI_OFFLINE_CACHE_FILE_PATH"] = str(tmp_path)
383-
proc = subprocess.run(cmd_line, capture_output=True, text=True, env=env, cwd=MODULE_ROOT_DIR)
383+
proc = subprocess.run(cmd_line, capture_output=True, text=True, encoding="utf-8", env=env, cwd=MODULE_ROOT_DIR)
384384

385385
# Display error message only in case of failure
386386
if proc.returncode == RET_SKIP:

tests/test_rigid_physics.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,13 +3167,15 @@ def test_mesh_primitive_COM(show_viewer, tol):
31673167

31683168
@pytest.mark.required
31693169
@pytest.mark.parametrize("scale", [0.1, 10.0])
3170+
@pytest.mark.parametrize("box_box_detection", [False, True])
31703171
@pytest.mark.parametrize("backend", [gs.cpu, gs.gpu])
3171-
def test_noslip_iterations(scale, show_viewer, tol):
3172+
def test_noslip_iterations(scale, box_box_detection, show_viewer, tol):
31723173
scene = gs.Scene(
31733174
sim_options=gs.options.SimOptions(
31743175
dt=0.01,
31753176
),
31763177
rigid_options=gs.options.RigidOptions(
3178+
box_box_detection=box_box_detection,
31773179
noslip_iterations=5,
31783180
),
31793181
viewer_options=gs.options.ViewerOptions(
@@ -3186,21 +3188,19 @@ def test_noslip_iterations(scale, show_viewer, tol):
31863188
show_viewer=show_viewer,
31873189
)
31883190

3189-
boxes = []
31903191
for i in range(3):
3191-
boxes.append(
3192-
scene.add_entity(
3193-
gs.morphs.Box(
3194-
size=(scale, scale, scale),
3195-
pos=(i * scale, 0, 0),
3196-
fixed=(i == 0),
3197-
),
3198-
surface=gs.surfaces.Default(
3199-
color=(*np.random.rand(3), 0.7),
3200-
),
3201-
visualize_contact=True,
3202-
)
3192+
scene.add_entity(
3193+
gs.morphs.Box(
3194+
size=(scale, scale, scale),
3195+
pos=(i * (1 - (not box_box_detection) * 1e-3) * scale, 0, 0),
3196+
fixed=(i == 0),
3197+
),
3198+
surface=gs.surfaces.Default(
3199+
color=(*np.random.rand(3), 1.0 if i != 1 else 0.7),
3200+
),
3201+
visualize_contact=True,
32033202
)
3203+
box_1, box_2 = scene.entities[1:]
32043204
scene.build()
32053205

32063206
rho = 200
@@ -3211,24 +3211,24 @@ def test_noslip_iterations(scale, show_viewer, tol):
32113211
safety = 2.5
32123212

32133213
# simulate for 20 seconds
3214-
for i in range(2000):
3215-
boxes[2].control_dofs_force(np.array([-safety / coeff_f * n_box * rho * scale**3 * g]), np.array([0]))
3214+
for _ in range(2000):
3215+
# push to -x direction
3216+
box_2.control_dofs_force([-safety / coeff_f * n_box * rho * scale**3 * g], [0])
32163217
scene.step()
32173218

3218-
box_1_z = tensor_to_array(boxes[1].get_qpos())[2]
32193219
# allow some small sliding due to first few frames
32203220
# scale = 0.1 is less stable than bigger scale
3221+
_, _, box_1_z = box_1.get_pos()
32213222
assert_allclose(box_1_z, 0.0, atol=4e-2 * scale)
32223223

32233224
# reduce the multiplier and it will slide
32243225
safety = 0.9
3225-
for i in range(2000):
3226-
# push to -x direction
3227-
boxes[2].control_dofs_force(np.array([-safety / coeff_f * n_box * rho * scale**3 * g]), np.array([0]))
3226+
for _ in range(300):
3227+
box_2.control_dofs_force([-safety / coeff_f * n_box * rho * scale**3 * g], [0])
32283228
scene.step()
32293229

3230-
box_1_z = tensor_to_array(boxes[1].get_qpos())[2]
32313230
# it will slip away
3231+
_, _, box_1_z = box_1.get_pos()
32323232
assert box_1_z < -scale
32333233

32343234

0 commit comments

Comments
 (0)