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

Constraint samplers with seed #3112

Merged
merged 7 commits into from
May 9, 2022

Conversation

tahsinkose
Copy link
Contributor

Description

This PR adds the ability to specify a seed for constraint samplers through the parameter server, which would be useful in deterministic testing and benchmarking of these objects.

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • No API changes
  • Create tests, which fail without this PR reference
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@tahsinkose tahsinkose requested a review from v4hn as a code owner April 7, 2022 22:04
@codecov
Copy link

codecov bot commented Apr 8, 2022

Codecov Report

Merging #3112 (52d8387) into master (0f66b99) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3112      +/-   ##
==========================================
- Coverage   61.60%   61.58%   -0.02%     
==========================================
  Files         376      376              
  Lines       33309    33317       +8     
==========================================
- Hits        20518    20516       -2     
- Misses      12791    12801      +10     
Impacted Files Coverage Δ
.../constraint_samplers/default_constraint_samplers.h 79.32% <100.00%> (+1.54%) ⬆️
...raint_samplers/src/default_constraint_samplers.cpp 79.77% <100.00%> (+0.36%) ⬆️
.../ompl_interface/src/detail/constrained_sampler.cpp 43.91% <0.00%> (-17.07%) ⬇️
...meterization/work_space/pose_model_state_space.cpp 80.00% <0.00%> (-1.76%) ⬇️
...on/pick_place/src/approach_and_translate_stage.cpp 75.16% <0.00%> (-0.60%) ⬇️
...dl_kinematics_plugin/src/kdl_kinematics_plugin.cpp 77.91% <0.00%> (-0.37%) ⬇️
...g_scene_interface/src/planning_scene_interface.cpp 52.20% <0.00%> (+1.10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f66b99...52d8387. Read the comment docs.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution. Please adjust your code for a minimal changeset. The comments provided for JointConstraintSampler apply to IKConstraintSampler as well.

int rng_seed;
if (ros::param::get("~constraint_sampler_random_seed", rng_seed))
{
ROS_WARN_STREAM_NAMED("constraint_samplers",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you decided for a warning here? This is an info at most, preferably a debug message, isn't it?

Suggested change
ROS_WARN_STREAM_NAMED("constraint_samplers",
ROS_INFO_STREAM_NAMED("constraint_samplers",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I had a bias from a production view. Generally, debug messages are not enabled in normal runs, which may cause this to slip away from the eyes. Anyways a simple rosparam lookup would still give the information needed, thus reducing to debug 👍🏼

if (ros::param::get("~constraint_sampler_random_seed", rng_seed))
{
ROS_WARN_STREAM_NAMED("constraint_samplers",
"Creating random number generator with seed " << std::to_string(rng_seed));
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to convert the int to a string. The streaming operator supports int.

Suggested change
"Creating random number generator with seed " << std::to_string(rng_seed));
"Creating random number generator with seed " << rng_seed);

@@ -191,7 +203,8 @@ class JointConstraintSampler : public ConstraintSampler

void clear() override;

random_numbers::RandomNumberGenerator random_number_generator_; /**< \brief Random number generator used to sample */
std::unique_ptr<random_numbers::RandomNumberGenerator>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to change API? Please revert this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, random_number_generator_ gets default constructed and the assignment operator of random_numbers::RandomNumberGenerator is deleted, hence I can't do the following:

random_number_generator_ =random_numbers::RandomNumberGenerator(rng_seed);

This way it enables us to construct it once. This API change is thus necessary.

Copy link
Contributor Author

@tahsinkose tahsinkose Apr 13, 2022

Choose a reason for hiding this comment

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

It would be nicer if you explain why you disagree @v4hn. I'm genuinely curious about how this can be done without API* change.

*random_number_generator_ is fully internal, so it is not an API. This change will have zero effects from the users' perspective. (unless they are using a compute-board that has very limited heap access)

@tahsinkose
Copy link
Contributor Author

@rhaschke I wanted this capability for both constraint samplers as IKConstraintSampler might need that too. Addressed your review, PTAL 🙏🏼

@tahsinkose tahsinkose force-pushed the constraint-samplers-with-seed branch from 29a2c4f to 9cb0edc Compare April 8, 2022 09:07
@tahsinkose
Copy link
Contributor Author

Added IKConstraintSampler test.

@tahsinkose tahsinkose force-pushed the constraint-samplers-with-seed branch from 9cb0edc to 2d4a092 Compare April 8, 2022 09:10
@tahsinkose
Copy link
Contributor Author

@rhaschke PTAL 🙏🏼

@tahsinkose
Copy link
Contributor Author

@v4hn Please have a look. As time passes, it becomes much more difficult to contribute.

Copy link
Contributor

@v4hn v4hn left a comment

Choose a reason for hiding this comment

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

looks good after addressing the open issues.
Determinism is sure important! (and sadly by design MoveIt cannot give a lot of that)

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

@tahsinkose, looks like your new tests are never finishing.
Could you please have another look and fix them?

@tahsinkose
Copy link
Contributor Author

tahsinkose commented Apr 18, 2022

@rhaschke I just checked. The parameter server manipulation inevitably led to the existence of ROS master, hence the test needed to be updated to be a rostest. PTAL 🙏🏼

@tahsinkose tahsinkose force-pushed the constraint-samplers-with-seed branch from 3c2ab31 to ea5fc24 Compare April 18, 2022 18:35
Comment on lines +34 to +35
add_rostest_gtest(test_constraint_samplers
test/constraint_samplers.test
Copy link
Contributor Author

@tahsinkose tahsinkose Apr 18, 2022

Choose a reason for hiding this comment

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

@rhaschke This seems like an unorthodox addition to moveit_core as I didn't see any instances of rostest in the package. I guess all rostest tests are categorized strictly differently than unit tests according to MoveIt conventions, but that's just a hunch regarding the status quo.

If you think this is a serious violation, then I need to move the newly added tests to a convenient place in moveit_ros.

Copy link
Contributor

Choose a reason for hiding this comment

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

@v4hn, could you review as well and comment on this point? IMO, moveit_core isn't ROS-agnostic for a while already, e.g. using ROS logging in a few places. However, ROS parameters are actually not yet used in moveit_core.

Copy link
Contributor

Choose a reason for hiding this comment

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

I fully agree. If we allow ros parameters here (and we seem to agree we want to do so) then we also need to allow tests for them, so both reading the param as well as adding the ros test are fine by me.

Maybe the ros2 sync will split it out into a separate framework structure, but for this repo I will just merge this as is now.

@tahsinkose
Copy link
Contributor Author

The failing checks seem to be related with https://github.blog/2022-04-12-git-security-vulnerability-announced/. Also see actions/checkout#760

@rhaschke
Copy link
Contributor

Hi @tylerjw,
did you run into git issues like these for MoveIt2 as well? If so, how did you solve them?

setup_upstream_workspace
$ sudo apt-get -qq install -y --no-upgrade --no-install-recommends python3-vcstool | grep -E 'Setting up' 
Setting up python3-vcstool (0.3.0-1) ...
EEE
=== /home/runner/work/moveit/moveit/.work/upstream_ws/src/geometric_shapes (git) ===
Could not determine remotes: fatal: unsafe repository ('/home/runner/work/moveit/moveit/.work/upstream_ws/src/geometric_shapes' is owned by someone else)

The problem only arises if the (upstream) cache was restored.

@tahsinkose
Copy link
Contributor Author

Any update on this @rhaschke @tylerjw? I think this issue should be affecting all PRs right now..

@tahsinkose tahsinkose requested a review from v4hn April 22, 2022 06:41
@v4hn
Copy link
Contributor

v4hn commented Apr 28, 2022

@JafarAbdi

@rhaschke
Copy link
Contributor

Closing and reopening to trigger CI.

@rhaschke rhaschke closed this Apr 29, 2022
@rhaschke rhaschke reopened this Apr 29, 2022
@rhaschke
Copy link
Contributor

rhaschke commented May 5, 2022

@tahsinkose, could you please rebase this onto the latest master (which has fixed CI).
@v4hn, I believe I have seen you rebasing and force-pushing other user's PRs in the past. However, I cannot find a corresponding github interface. How did you achieve that?

@v4hn
Copy link
Contributor

v4hn commented May 5, 2022

if the user allowed edits by maintainers I believe you can simply force-push to their PR branch. I wouldn't know how else I would have done that.

@rhaschke
Copy link
Contributor

rhaschke commented May 5, 2022

If the user allowed edits by maintainers I believe you can simply force-push to their PR branch.

No, that doesn't work. So, @tahsinkose, please rebase yourself. Thanks.

@tahsinkose tahsinkose force-pushed the constraint-samplers-with-seed branch from 42b6a2e to 52d8387 Compare May 5, 2022 19:32
@tahsinkose
Copy link
Contributor Author

If the user allowed edits by maintainers I believe you can simply force-push to their PR branch.

No, that doesn't work. So, @tahsinkose, please rebase yourself. Thanks.

Rebased @rhaschke 👍🏼

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

The tests pass now. Thanks.

@v4hn v4hn merged commit dd0fb2a into moveit:master May 9, 2022
@v4hn
Copy link
Contributor

v4hn commented May 9, 2022

Thanks for your patience with this @tahsinkose 👍

@tahsinkose
Copy link
Contributor Author

No worries @v4hn I got used to the elaborate review process of MoveIt maintainers 😝

@v4hn
Copy link
Contributor

v4hn commented May 9, 2022

I'm not sure that's a good thing. ;) But we are volunteers after all 😛
Do you have any idea why your new tests now fails upstream right away?

@tahsinkose
Copy link
Contributor Author

I'm not sure that's a good thing. ;) But we are volunteers after all stuck_out_tongue Do you have any idea why your new tests now fails upstream right away?

Maybe just bad luck. The tests passed in this PR, not sure why they would fail in upstream 🤔

@rhaschke
Copy link
Contributor

rhaschke commented May 10, 2022

Looks like the test is flaky (a manually triggered second run succeeded). @tahsinkose, could you please have another look and make the test more robust?

@tahsinkose
Copy link
Contributor Author

It seems, when the true randomness is restored with rosparam deletion, it starts to be flaky 😄 Adding a different seed for the 3rd sampler should solve this issue @rhaschke.

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.

None yet

3 participants