Skip to content

Commit 4e7f970

Browse files
authored
[CHANGING][MISC] Enable specialized convex-convex SDF fallback when using MPR. (#1983)
* Fix URDF loading for mesh file symlinks. * Fix 'func_collision_clear' not being called if collision physics disabled. * Fix fastcache support for MPR. * Do not allocate GJK if not used. * Enable specialized convex-convex SDF.
1 parent e5167cf commit 4e7f970

File tree

14 files changed

+227
-203
lines changed

14 files changed

+227
-203
lines changed

.github/workflows/production.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
pip install --no-input --extra-index-url https://pypi.nvidia.com/ omniverse-kit
7979
pip install --no-input ".[dev,render,usd]"
8080
81-
pytest -v -rs --backend gpu --dev --forked ./tests
81+
pytest -v -ra --backend gpu --dev --forked ./tests
8282
EOF
8383
- name: Kill srun job systematically
8484
if: always()

examples/speed_benchmark/franka.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# with the following control: 43M FPS
3939
# without the following control (arm in collision with the floor): 32M FPS
4040
franka.control_dofs_position(
41-
torch.tile(torch.tensor([0, 0, 0, -1.0, 0, 0, 0, 0.02, 0.02], device=gs.device), (B, 1)),
41+
torch.tile(torch.tensor([0, 0, 0, -1.0, 0, 1.0, 0, 0.02, 0.02], device=gs.device), (B, 1)),
4242
)
4343

4444
for i in range(1000):

examples/tutorials/parallel_simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# control all the robots
3737
franka.control_dofs_position(
38-
torch.tile(torch.tensor([0, 0, 0, -1.0, 0, 0, 0, 0.02, 0.02], device=gs.device), (B, 1)),
38+
torch.tile(torch.tensor([0, 0, 0, -1.0, 0, 1.0, 0, 0.02, 0.02], device=gs.device), (B, 1)),
3939
)
4040

4141
# control only 3 environments: 1, 5, and 7. (You also need to comment out the function call above)

genesis/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ def init(
229229
with redirect_stdout(_ti_outputs):
230230
ti.init(
231231
arch=TI_ARCH[platform][backend],
232-
# Add a (hidden) mechanism to forceable disable taichi debug mode as it is still a bit experimental
233-
debug=ti_debug and backend == gs.cpu,
234-
check_out_of_bound=debug,
232+
# Add a (hidden) mechanism to forcible disable taichi debug mode as it is still a bit experimental
233+
debug=ti_debug and backend == gs_backend.cpu,
234+
check_out_of_bound=debug and backend != gs_backend.metal,
235235
# force_scalarize_matrix=True for speeding up kernel compilation
236236
# Turning off 'force_scalarize_matrix' is causing numerical instabilities ('nan') on MacOS
237237
force_scalarize_matrix=True,

genesis/engine/solvers/rigid/collider_decomp.py

Lines changed: 76 additions & 79 deletions
Large diffs are not rendered by default.

genesis/engine/solvers/rigid/constraint_noslip.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def kernel_noslip(
6262
rigid_global_info: array_class.RigidGlobalInfo,
6363
static_rigid_sim_config: ti.template(),
6464
):
65+
EPS = rigid_global_info.EPS[None]
6566
_B = constraint_state.jac.shape[2]
6667
n_dofs = constraint_state.jac.shape[1]
6768

@@ -133,7 +134,7 @@ def kernel_noslip(
133134
y = 0.5 * (constraint_state.efc_force[j_efc, i_b] - constraint_state.efc_force[j_efc + 1, i_b])
134135
K1 = Ac[0] + Ac[3] - Ac[1] - Ac[2]
135136
K0 = mid * (Ac[0] - Ac[3]) + bc[0] - bc[1]
136-
if K1 < gs.EPS:
137+
if K1 < EPS:
137138
constraint_state.efc_force[j_efc, i_b] = constraint_state.efc_force[j_efc + 1, i_b] = mid
138139
else:
139140
y = -K0 / K1
@@ -154,6 +155,7 @@ def kernel_noslip(
154155
old_force=old_force,
155156
res=res,
156157
dim=2,
158+
eps=EPS,
157159
)
158160

159161
improvement -= cost_change
@@ -241,6 +243,7 @@ def func_cost_change(
241243
old_force,
242244
res,
243245
dim: int,
246+
eps,
244247
):
245248
change = gs.ti_float(0.0)
246249
if dim == 1:
@@ -254,7 +257,7 @@ def func_cost_change(
254257
for j in range(dim):
255258
change += 0.5 * Ac[i * dim + j] * delta[i] * delta[j]
256259
change += delta[i] * res[i]
257-
if change > gs.EPS:
260+
if change > eps:
258261
for i in range(dim):
259262
force[force_start + i, i_b] = old_force[i]
260263
change = 0.0

genesis/engine/solvers/rigid/gjk_decomp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class EPA_POLY_INIT_RETURN_CODE(IntEnum):
4646

4747

4848
class GJK:
49-
def __init__(self, rigid_solver):
49+
def __init__(self, rigid_solver, is_active: bool = True):
5050
# Initialize static configuration.
5151
# MuJoCo's multi-contact detection algorithm is disabled by default, because it is often less stable than the
5252
# other multi-contact detection algorithm. However, we keep the code here for compatibility with MuJoCo and for
@@ -112,8 +112,11 @@ def __init__(self, rigid_solver):
112112
diff_contact_min_penetration=gs.EPS * 100.0,
113113
)
114114

115-
# Initialize GJK state.
116-
self._gjk_state = array_class.get_gjk_state(rigid_solver, rigid_solver._static_rigid_sim_config, self._gjk_info)
115+
# Initialize GJK state
116+
self._gjk_state = array_class.get_gjk_state(
117+
rigid_solver, rigid_solver._static_rigid_sim_config, self._gjk_info, is_active
118+
)
119+
self._is_active = is_active
117120

118121
def reset(self):
119122
pass

genesis/engine/solvers/rigid/mpr_decomp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def guess_geoms_center(
621621
geoms_state: array_class.GeomsState,
622622
geoms_info: array_class.GeomsInfo,
623623
geoms_init_AABB: array_class.GeomsInitAABB,
624+
rigid_global_info: array_class.RigidGlobalInfo,
624625
static_rigid_sim_config: ti.template(),
625626
mpr_info: array_class.MPRInfo,
626627
i_ga,
@@ -654,6 +655,7 @@ def guess_geoms_center(
654655
# is a real issue, one way to address it is to evaluate the exact signed distance of each center wrt their
655656
# respective geometry. If one of the center is off, its offset from the original center is divided by 2 and the
656657
# signed distance is computed once again until to find a valid point. This procedure should be cheap.
658+
EPS = rigid_global_info.EPS[None]
657659

658660
g_pos_a = geoms_state.pos[i_ga, i_b]
659661
g_pos_b = geoms_state.pos[i_gb, i_b]
@@ -681,7 +683,7 @@ def guess_geoms_center(
681683
offset = delta.dot(normal_ws) * normal_ws - delta
682684
offset_norm = offset.norm()
683685

684-
if offset_norm > gs.EPS:
686+
if offset_norm > EPS:
685687
# Compute the size of the bounding boxes along the target offset direction.
686688
# First, move the direction in local box frame
687689
dir_offset = offset / offset_norm
@@ -779,6 +781,7 @@ def func_mpr_contact(
779781
geoms_state: array_class.GeomsState,
780782
geoms_info: array_class.GeomsInfo,
781783
geoms_init_AABB: array_class.GeomsInitAABB,
784+
rigid_global_info: array_class.RigidGlobalInfo,
782785
static_rigid_sim_config: ti.template(),
783786
collider_state: array_class.ColliderState,
784787
collider_info: array_class.ColliderInfo,
@@ -795,6 +798,7 @@ def func_mpr_contact(
795798
geoms_state,
796799
geoms_info,
797800
geoms_init_AABB,
801+
rigid_global_info,
798802
static_rigid_sim_config,
799803
mpr_info,
800804
i_ga,

0 commit comments

Comments
 (0)