Skip to content
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

Differentiation through contact not working correctly #73

Closed
verityw opened this issue Oct 16, 2021 · 4 comments
Closed

Differentiation through contact not working correctly #73

verityw opened this issue Oct 16, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@verityw
Copy link

verityw commented Oct 16, 2021

I'm trying to do a simple example of differentiation through contact. I created a function that simulates a ball falling and bounding for 20 time steps. When I try taking the derivative of the final height with respect to the initial height, it always returns 1, even though it should not be a linear dependence. I've put together a example notebook demonstrating this, where I compute the aforementioned derivative numerically and analytically, and the two do not agree. I also plotted the numerical derivative as a function of starting height -- the derivative is only 1 when the ball is sufficiently high, but that's just because it does not hit the ground in 20 timesteps. Here's the notebook: https://colab.research.google.com/drive/1btgxkX640FTGysYmlWmmgG2BXMfPrx05?usp=sharing

Is differentiating through contacts bugged?

@EelcoHoogendoorn
Copy link

Basically, yes.

See appendix F of https://openreview.net/pdf?id=B1eB5xSFvr for some discussion on this point. Though the simulator here is a somewhat different flavor than the one used there, the same points apply. They suggest a fix for their simulator; although the simplest and most generic fix is to implement a sping-based collision handler, rather than the impulse-one used here. That will require more timesteps to resolve stiff contacts, but at least it makes it conceptually the clearest whats going on.

@cdfreeman-google
Copy link
Collaborator

Eelco is totally right--we actually had time of impact based collisions (which are another way of fixing this) in an extremely early build, but removed it because it didn't seem to effect much, but this is a pretty clear demonstration of the breakdown.

I should have some cycles in the next week or so to try a toi-based patch.

@cdfreeman-google
Copy link
Collaborator

I will add, however, that I'm not sure that this is the issue appearing here--I think this particular failure mode is arising from an insufficiently small numerical step size used when calculating the numerical derivative. Your smallest window "h" is only about .05.

Here are some numerical derivatives for smaller step sizes:

h.    [f(x+h) - f(x) / h]
0.1 -0.17048850568550655
0.01 0.9999990463256836
0.001 0.9999275207519531
0.0001 0.9989738464355469
1e-05 1.0013580322265625

@erikfrey erikfrey added the bug Something isn't working label Nov 10, 2021
@cdfreeman-google
Copy link
Collaborator

Closing, but feel free to reopen if you think this issue is not resolved by smaller h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants