-
Notifications
You must be signed in to change notification settings - Fork 120
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
Allow constant inputs to cost functions to be passed as floats #150
Conversation
@luisenp @mhmukadam I have added some changes to |
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 looking good! Some tweaks needed but mostly easy fixes and unit tests. The only other variable I've seen so far where this applies is eff_radius
in EffectorObjectContactPlanar
. Poses and sdf variables (origin, cell size, data) are multidimensional, so no need to change those.
dt = torch.tensor(dt) | ||
self.dt = Variable(dt) | ||
else: | ||
self.dt = dt |
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.
After the ndim
check below, we can add dt.data = self.dt.data.view(-1, 1)
, to make sure we have a batch dimension as well, as discussed above.
name: Optional[str] = None, | ||
): | ||
super().__init__(name=name) | ||
if not isinstance(dt, Variable): | ||
if not isinstance(dt, torch.Tensor): | ||
dt = torch.tensor(dt) |
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.
I have added a fix for this class in #157, make sure you merge those changes as well.
dt = torch.tensor(dt) | ||
self.dt = Variable(dt) | ||
else: | ||
self.dt = dt | ||
super().__init__(pose1, vel1, pose2, vel2, dt, cost_weight, name=name) |
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.
Similar comment about maintaining a batch shape here.
@luisenp Added the changes. Please review.Also do you have any suggestions for unit test ? |
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.
LGTM! For unit tests, just constructing all of these classes with the different types of inputs, and checking that the corresponding member is a variable of the expected type and shape should be sufficient. Thanks!!
@luisenp Added unit test. Can you please take a look ? |
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.
Looks good, almost there! Once the code is finished, I'll also run some tests on my side before confirming that we can merge. Thanks!
obj, eff, cost_weight, origin, sdf_data, cell_size, eff_radius | ||
) | ||
|
||
assert isinstance(cost_function.eff_radius, Variable) |
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.
Here we can check that cost_function.eff_radius is eff_radius
.
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.
You can delete the line above that has the isinstance
check now.
) | ||
|
||
assert isinstance(cost_function.eff_radius, Variable) | ||
|
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.
Here we can add another check that cost_function.eff_radius.data is eff_radius_t
.
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.
@luisenp While assert cost_function.eff_radius.data is eff_radius_t
gives error as one is tensor
and other is th.Variable
.Is it better to use assert torch.allclose(cost_function.eff_radius.data,eff_radius_t)
?
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.
I'm a bit confused. Shouldn't both cost_function.eff_radius.data
(notice, .data
) and eff_radius_t
be both torch tensors?
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.
@luisenp when i try to do assert cost_function.eff_radius.data is eff_radius_t
i get this error which expained above
> assert cost_function.eff_radius.data is eff_radius_t
E assert tensor([[0.4160]], dtype=torch.float64) is tensor([[0.4160]], dtype=torch.float64)
E + where tensor([[0.4160]], dtype=torch.float64) = Variable(data=tensor([[0.4160]], dtype=torch.float64), name=Variable__680).data
E + where Variable(data=tensor([[0.4160]], dtype=torch.float64), name=Variable__680) = <theseus.embodied.collision.eff_obj_contact.EffectorObjectContactPlanar object at 0x7f813704edd0>.eff_radius
theseus/embodied/collision/tests/test_eff_obj_contact.py:180: AssertionError
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.
Ah, right, it's because of the view(-1, 1)
we added. In this case, let's stick to compare that they are close in value as you had initially.
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.
@luisenp Then can you take a look at PR. I've already committed the changes
obj, eff, cost_weight, origin, sdf_data, cell_size, eff_radius_f | ||
) | ||
|
||
assert isinstance(cost_function.eff_radius, Variable) |
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.
Here we can first set up some random value for eff_radius_f
and then add an additional check that np.isclose(cost_function.eff_radius.data.item(), eff_radius_f)
.
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.
@luisenp
we're already giving a random value to eff_radius_f=1.0
So is this enough assert np.isclose(cost_function.eff_radius.data.item(), eff_radius_f)
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.
By random I mean sampling a new value every iteration rather than hardcoding to 1.0.
@@ -60,6 +61,30 @@ def test_gp_motion_model_cost_weight_copy(): | |||
) | |||
|
|||
|
|||
def test_gp_motion_model_variable_type(): |
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.
Add similar modifications to the test here, as mentioned above.
assert isinstance(cost_weight.Qc_inv, Variable) | ||
assert isinstance(cost_weight.dt, Variable) | ||
|
||
q_inv_v = Variable(q_inv) |
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.
We don't need the second check for q_inv_v
.
@luisenp Added changes please review |
@luisenp @mhmukadam I'm unable to run tests after fetching latest changes from
This keeps repating for every file |
We merged a new component that has an additional requirement. Can you try pip installing this? |
cost_weight = th.eb.GPCostWeight(q_inv_v, dt_f) | ||
assert isinstance(cost_weight.Qc_inv, Variable) | ||
assert isinstance(cost_weight.dt, Variable) |
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.
Sorry, didn't think of this before, but we should also check that cost_weight.dt
has a batch dimension. And similar for eff_radius_t
in the other cost function. We are also missing the check np.isclose(cost_function.eff_radius.data.item(), eff_radius_f)
(and similar for dt
).
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.
@jeffin07 Missing the np.allclose()
check for eff_radius_f
and also checking that the batch dimension is present.
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.
Left two more comments.
@luisenp Updated unit tests |
@luisenp Updated the changes.Please review |
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.
Sorry for the delay, got busy with other PRs and forgot this was waiting for review. LGTM!
Thanks a lot for another great contribution, @jeffin07 :) |
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.
Looks good! Thanks.
@luisenp @mhmukadam Updated the changes. Please review |
…ookresearch#150) * collision and double_integrator variable change * unit test
Motivation and Context
To close #38
How Has This Been Tested
Types of changes
Checklist