Repository navigation
Make EPA Polytope Expansion Deterministic - #670
SeanCurtis-TRI merged 4 commits into
Conversation
expandPolytope() connected the new support vertex to the silhouette by iterating border_edges, an std::unordered_set<ccd_pt_edge_t*>. Its iteration order follows the pointer hashes, i.e. where the heap happened to place the edges, and the new edges and faces are appended to the polytope's lists in that order. libccd's nearest-feature search breaks near-ties (ccdEq) by list order, so the face EPA expands next, and the reported witness points and normal, could differ from one process to the next for identical inputs (ASLR, or any change in earlier allocations). Visit the border edges in the polytope's own edge-list order instead, which is deterministic. The set is still used for membership. On a pair of convex meshes where the original code returned two different normals across 20,000 calls with the heap perturbed between calls, it now always returns one of them; the penetration depth was identical in both. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MVCAGt56vQmZCx1g6RjUZ
… list The previous commit made expandPolytope() deterministic by walking the polytope's whole edge list to put border_edges in a stable order, which costs a pass over every edge per expansion. ComputeVisiblePatch() already finds the border edges in a deterministic order (it follows the faces' edge arrays, never iterating the sets), so record that order as they are classified and iterate it directly. The extra cost is one push_back per border edge. The new output parameter defaults to null, so existing callers are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MVCAGt56vQmZCx1g6RjUZ
The EPA tests call ComputeVisiblePatchRecursive() directly, so give its new border_edge_order parameter the same null default as ComputeVisiblePatch(). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MVCAGt56vQmZCx1g6RjUZ
cohnt
left a comment
There was a problem hiding this comment.
@cohnt reviewed 1 file and all commit messages.
Reviewable status: 0 of 1 files reviewed, all discussions resolved.
|
I ran CI and assigned @SeanCurtis-TRI for review next week. LMK if you need it reviewed sooner. |
SeanCurtis-TRI
left a comment
There was a problem hiding this comment.
We shouldn't provide a meaningless nullptr default value for the new parameter; the correctness (at least so far as determinancy goes) of the algorithm depends on it.
Instead, update the tests to respect the required argument.
@SeanCurtis-TRI reviewed 1 file and all commit messages, and made 4 comments.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on cohnt).
include/fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h line 1272 at r1 (raw file):
std::unordered_set<ccd_pt_edge_t*>* internal_edges, std::vector<ccd_pt_edge_t*>* border_edge_order) { if (border_edges->insert(edge).second && border_edge_order != nullptr) {
nit: This should not allow for the possibility of a null border_edge_order (in the same way it implicitly doesn't allow for null border_edges or internal_edges.
include/fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h line 1322 at r1 (raw file):
std::unordered_set<ccd_pt_face_t*>* hidden_faces, std::unordered_set<ccd_pt_edge_t*>* internal_edges, std::vector<ccd_pt_edge_t*>* border_edge_order = nullptr) {
nit: remove the default nullptr value. There is no valid invocation in which border_edge_order can/should be null.
include/fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h line 1427 at r1 (raw file):
std::unordered_set<ccd_pt_face_t*>* visible_faces, std::unordered_set<ccd_pt_edge_t*>* internal_edges, std::vector<ccd_pt_edge_t*>* border_edge_order = nullptr) {
nit: Remove the default value.
There is no valid call to ComputeVisiblePatch() or ComputeVisiblePatchRecursive() without it, so drop the nullptr default and the null check, and have the tests pass (and check) the vector. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
cohnt
left a comment
There was a problem hiding this comment.
Gotcha
@cohnt made 4 comments and resolved 3 discussions.
Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on SeanCurtis-TRI).
include/fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h line 1272 at r1 (raw file):
Previously, SeanCurtis-TRI (Sean Curtis) wrote…
nit: This should not allow for the possibility of a
nullborder_edge_order(in the same way it implicitly doesn't allow fornullborder_edgesorinternal_edges.
Done.
include/fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h line 1322 at r1 (raw file):
Previously, SeanCurtis-TRI (Sean Curtis) wrote…
nit: remove the default
nullptrvalue. There is no valid invocation in whichborder_edge_ordercan/should be null.
Done.
include/fcl/narrowphase/detail/convexity_based_algorithm/gjk_libccd-inl.h line 1427 at r1 (raw file):
Previously, SeanCurtis-TRI (Sean Curtis) wrote…
nit: Remove the default value.
Done.
SeanCurtis-TRI
left a comment
There was a problem hiding this comment.
@SeanCurtis-TRI reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on cohnt).
ae86ecd
into
flexible-collision-library:master
expandPolytope()iteratesborder_edges, anunordered_setof pointers, when adding the new edges and faces, so they are appended to the polytope in an order that depends on where the heap placed them. libccd breaks near-ties in its nearest-feature search by list order, so for identical inputs the witness points and normal of a penetrating convex-convex query can differ between processes (we hit this through Drake, as run-to-run differences in signed-distance gradients, leading to different solver outcomes).This records the border edges in the order
ComputeVisiblePatch()finds them, which is deterministic, and iterates that instead. On the mesh pair where we saw it, repeated queries with the heap perturbed went from two distinct results to one, and that one was already among the original's results. Runtime is unchanged (a first version that rescanned the polytope's edge list instead cost ~9%).This change is