Skip to content

[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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

LeonLiu4
Copy link
Contributor

@LeonLiu4 LeonLiu4 commented Jul 7, 2025

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

@LeonLiu4 LeonLiu4 force-pushed the feature/get-weld branch from 00f2534 to c176525 Compare July 7, 2025 22:39
Copy link
Collaborator

@duburcqa duburcqa left a 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.

@LeonLiu4 LeonLiu4 requested a review from duburcqa July 8, 2025 19:16
@LeonLiu4 LeonLiu4 requested a review from duburcqa July 10, 2025 19:05
@LeonLiu4 LeonLiu4 requested a review from duburcqa July 14, 2025 19:35
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])]),
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@LeonLiu4 LeonLiu4 requested a review from duburcqa July 16, 2025 22:19
Comment on lines +6013 to +6022
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,
}
Copy link
Collaborator

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Create an API to get weld constraints
3 participants