warp icon indicating copy to clipboard operation
warp copied to clipboard

[BUG] Potential bug in warp.sim.collide?

Open xuan-li opened this issue 7 months ago • 1 comments

Bug Description

In warp/sim/collide.py, wp.clone are used to create new arrays when requires_grad=True:

model.soft_contact_body_pos = wp.clone(model.soft_contact_body_pos)
model.soft_contact_body_vel = wp.clone(model.soft_contact_body_vel)
model.soft_contact_normal = wp.clone(model.soft_contact_normal)

...

model.rigid_contact_point0 = wp.clone(model.rigid_contact_point0)
model.rigid_contact_point1 = wp.clone(model.rigid_contact_point1)
model.rigid_contact_offset0 = wp.clone(model.rigid_contact_offset0)
model.rigid_contact_offset1 = wp.clone(model.rigid_contact_offset1)
model.rigid_contact_normal = wp.clone(model.rigid_contact_normal)
model.rigid_contact_thickness = wp.clone(model.rigid_contact_thickness)

It looks like that in the backpropagate, there will be a gradient flow between the new copy and the old one. But the two copies should be independent. I think wp.empty_like should be used here.

System Information

No response

xuan-li avatar Jul 19 '24 17:07 xuan-li