Skip to content

Commit 4547b8c

Browse files
authored
[BUG FIX] Fix support of Hybrid entity with non-fixed base link. (#2040)
* Fix support of Hybrid entity with non-fixed base link. * Increase tolerance of flaky unit test.
1 parent 26680da commit 4547b8c

File tree

6 files changed

+15
-39
lines changed

6 files changed

+15
-39
lines changed

genesis/engine/entities/hybrid_entity.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def __init__(
6666

6767
if isinstance(morph, gs.morphs.URDF):
6868
# set up rigid part
69-
morph.fixed = material.fixed # NOTE: use hybrid material to determine this
7069
if material.use_default_coupling:
7170
gs.logger.info("Use default coupling in hybrid. Overwrite `needs_coup` in rigid material to True")
7271
material_rigid._needs_coup = True
@@ -84,10 +83,9 @@ def __init__(
8483
augment_link_world_coords(part_rigid)
8584

8685
# set soft parts based on rigid links
87-
if material._func_instantiate_soft_from_rigid is None:
88-
func_instantiate_soft_from_rigid = default_func_instantiate_soft_from_rigid
89-
else:
90-
func_instantiate_soft_from_rigid = material._func_instantiate_soft_from_rigid
86+
func_instantiate_soft_from_rigid = (
87+
material._func_instantiate_soft_from_rigid or default_func_instantiate_soft_from_rigid
88+
)
9189
part_soft = func_instantiate_soft_from_rigid(
9290
scene=scene,
9391
part_rigid=part_rigid,

genesis/engine/materials/hybrid.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class Hybrid(Material):
1414
The material of the rigid body.
1515
material_soft: gs.materials.base.Material
1616
The material of the soft body.
17-
fixed: bool, optional
18-
Whether the rigid entity is with a fixed base link. Default is False.
1917
use_default_coupling: bool, optional
2018
Whether to use default solver coupling. Default is False
2119
damping: float, optional
@@ -36,7 +34,6 @@ def __init__(
3634
self,
3735
material_rigid,
3836
material_soft,
39-
fixed=True,
4037
use_default_coupling=False,
4138
damping=0.0,
4239
thickness=0.05,
@@ -50,7 +47,6 @@ def __init__(
5047
self._material_rigid = material_rigid
5148
self._material_soft = material_soft
5249
self._thickness = thickness
53-
self._fixed = fixed
5450
self._use_default_coupling = use_default_coupling
5551
self._damping = damping
5652
self._soft_dv_coef = soft_dv_coef
@@ -73,11 +69,6 @@ def thickness(self):
7369
"""The thickness to instantiate soft skin."""
7470
return self._thickness
7571

76-
@property
77-
def fixed(self):
78-
"""Whether the rigid entity is with a fixed base link."""
79-
return self._fixed
80-
8172
@property
8273
def use_default_coupling(self):
8374
"""Whether to use default solver coupling."""

genesis/engine/scene.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ def add_entity(
398398
f"Unsupported `surface.vis_mode` for material {material}: '{surface.vis_mode}'. Expected one of: ['particle', 'recon']."
399399
)
400400

401-
elif isinstance(material, (gs.materials.SF.Smoke)):
401+
elif isinstance(material, gs.materials.SF.Smoke):
402402
if surface.vis_mode is None:
403403
surface.vis_mode = "particle"
404404

405-
if surface.vis_mode not in ["particle"]:
405+
if surface.vis_mode not in ("particle",):
406406
gs.raise_exception(
407407
f"Unsupported `surface.vis_mode` for material {material}: '{surface.vis_mode}'. Expected one of: ['particle', 'recon']."
408408
)
@@ -416,20 +416,20 @@ def add_entity(
416416
f"Unsupported `surface.vis_mode` for material {material}: '{surface.vis_mode}'. Expected one of: ['visual', 'particle', 'recon']."
417417
)
418418

419-
elif isinstance(material, (gs.materials.FEM.Base)):
419+
elif isinstance(material, gs.materials.FEM.Base):
420420
if surface.vis_mode is None:
421421
surface.vis_mode = "visual"
422422

423-
if surface.vis_mode not in ["visual"]:
423+
if surface.vis_mode not in ("visual",):
424424
gs.raise_exception(
425425
f"Unsupported `surface.vis_mode` for material {material}: '{surface.vis_mode}'. Expected one of: ['visual']."
426426
)
427427

428-
elif isinstance(material, (gs.materials.Hybrid)): # determine the visual of the outer soft part
428+
elif isinstance(material, gs.materials.Hybrid): # determine the visual of the outer soft part
429429
if surface.vis_mode is None:
430430
surface.vis_mode = "particle"
431431

432-
if surface.vis_mode not in ["particle", "visual"]:
432+
if surface.vis_mode not in ("particle", "visual"):
433433
gs.raise_exception(
434434
f"Unsupported `surface.vis_mode` for material {material}: '{surface.vis_mode}'. Expected one of: ['particle', 'visual']."
435435
)

genesis/engine/simulator.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,30 +165,21 @@ def __init__(
165165
def _add_entity(self, morph: Morph, material, surface, visualize_contact=False):
166166
if isinstance(material, gs.materials.Tool):
167167
entity = self.tool_solver.add_entity(self.n_entities, material, morph, surface)
168-
169168
elif isinstance(material, gs.materials.Avatar):
170169
entity = self.avatar_solver.add_entity(self.n_entities, material, morph, surface, visualize_contact)
171-
172170
elif isinstance(material, gs.materials.Rigid):
173171
entity = self.rigid_solver.add_entity(self.n_entities, material, morph, surface, visualize_contact)
174-
175172
elif isinstance(material, gs.materials.MPM.Base):
176173
entity = self.mpm_solver.add_entity(self.n_entities, material, morph, surface)
177-
178174
elif isinstance(material, gs.materials.SPH.Base):
179175
entity = self.sph_solver.add_entity(self.n_entities, material, morph, surface)
180-
181176
elif isinstance(material, gs.materials.PBD.Base):
182177
entity = self.pbd_solver.add_entity(self.n_entities, material, morph, surface)
183-
184178
elif isinstance(material, gs.materials.FEM.Base):
185179
entity = self.fem_solver.add_entity(self.n_entities, material, morph, surface)
186-
187180
elif isinstance(material, gs.materials.Hybrid):
188-
entity = HybridEntity(
189-
self.n_entities, self.scene, material, morph, surface
190-
) # adding to solver is handled in the hybrid entity
191-
181+
# Note that adding to solver is handled in the hybrid entity
182+
entity = HybridEntity(self.n_entities, self.scene, material, morph, surface)
192183
else:
193184
gs.raise_exception(f"Material not supported.: {material}")
194185

genesis/engine/solvers/mpm_solver.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,10 @@ def build(self):
182182
self._coupler = self.sim._coupler
183183

184184
if self.is_active:
185-
if self._enable_CPIC:
186-
gs.logger.warning(
187-
"Kernel compilation takes longer when running MPM solver in CPIC mode. Please be patient."
185+
if self._enable_CPIC and self._sim.requires_grad:
186+
gs.raise_exception(
187+
"CPIC is not supported in differentiable mode yet. Submit a feature request if you need it."
188188
)
189-
if self._sim.requires_grad:
190-
gs.raise_exception(
191-
"CPIC is not supported in differentiable mode yet. Submit a feature request if you need it."
192-
)
193189

194190
self.init_particle_fields()
195191
self.init_grid_fields()

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,4 @@ def test_franka_panda_grasp_fem_entity(primitive_type, show_viewer):
318318
franka.control_dofs_force(np.array([-1.0, -1.0]), fingers_dof)
319319
scene.step()
320320
box_pos_post = obj.get_state().pos.mean(dim=-2)
321-
assert_allclose(box_pos_f, box_pos_post, atol=5e-4)
321+
assert_allclose(box_pos_f, box_pos_post, atol=1e-3)

0 commit comments

Comments
 (0)