-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[FEATURE] get_weld_constraints API #1370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
672a192
to
00f2534
Compare
00f2534
to
c176525
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you take inspiration of get_contacts
? i.e. return a dict instead of a raw tensor, and fetch all relevent taichi field values in a single kernel call.
tests/test_rigid_physics.py
Outdated
welds_single = cube1.get_weld_constraints(as_tensor=True, to_torch=False) | ||
|
||
assert_allclose( | ||
np.array([int(welds_single["obj_a"][0]), int(welds_single["obj_b"][0])]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove np.array
and int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if max_welds == 0: | ||
empty = torch.empty if to_torch else np.empty | ||
obj_a = empty((0,), dtype=np.int32) | ||
obj_b = empty((0,), dtype=np.int32) | ||
if n_envs == 1: | ||
return {"obj_a": obj_a, "obj_b": obj_b} | ||
return { | ||
"obj_a": [obj_a] * n_envs, | ||
"obj_b": [obj_b] * n_envs, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch should be useless. Just skip self._kernel_collect_welds(buf)
if max_welds == 0
"obj_b": [obj_b] * n_envs, | ||
} | ||
|
||
total = n_envs * max_welds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. See my previous comment:
Could you follow more strictly the pattern in RigidSolver.get_contacts? You should not pass a 3D tensor because it would allocate more memory than necessary but most importantly, it will break "C"-contiguity, which would be problematic if forwarded as input argument of another taichi kernel.
Adds RigidSolver.get_weld_constraints() – returns an (N, 3) NumPy array (env_id, link1_idx, link2_idx) of all active weld constraints, enabling quick inspection and test assertions without poking internal Taichi fields.
Resolves #1365