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

[Feature]: Add CPU multiprocessing for Panda Motionplanner's Trajecto… #611

Merged
merged 4 commits into from
Oct 14, 2024

Conversation

chenyenru
Copy link
Contributor

Uses an elementary method that lets each process in num_procs to generate num_traj // num_procs trajectory.

Discussion on next steps:

  • I see that in motionplanner's solution folder, there are several solve methods defined for different tasks. For example, solve in pick_cube.py. And it seems to be using the PandaArmMotionPlanningSolver environment when solving. From my understanding, it might help if solve method is being moved to PandaArmMotionPlanningSolver and PandaArmMotionPlanningSolver is wrapped as a vectorized environment for multiprocessing. Would be greatly appreciated to know if this rationale sounds correct, thank you.

…ry Generation

This is an elementary method that lets each process in `num_procs` to generate `num_traj // num_procs` trajectory.
@StoneT2000
Copy link
Member

I understand the reasoning somewhat, but the solver is dependent on the task. The PandArmmotionPlanningSolver is meant to a general class for the panda arm for MP problems.

Copy link
Member

@StoneT2000 StoneT2000 left a comment

Choose a reason for hiding this comment

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

tried running the code. However it seems some information is missing from the jsons. Particularly "source_type" and "source_desc". Seems to occur after merging the jsons.

@StoneT2000
Copy link
Member

StoneT2000 commented Oct 10, 2024

oh I see the bug, its the merge_trajectory.py merge_h5 code, it doesn't add those in. I think a fix would be to just copy any of the keys in the first json that aren't the keys being merged in the merge_h5 code.

and if there is different data in the other parts of the json just log a warning that this key is different between the different jsons and we took the first one.

@chenyenru
Copy link
Contributor Author

Thanks for the notes! Would replay trajectory need these information too? If so, I can directly modify merge_h5 to include "source_type" and "source_desc"

Regarding PandArmmotionPlanningSolver, would it make sense if child classes are created for each task?

@StoneT2000
Copy link
Member

Child subclasses is another approach, either a function that calls the APIs of the solver or implements the solver. I personally don't see a good reason to have to use subclasses though in this case if one is only overriding one function.

@chenyenru
Copy link
Contributor Author

Thank you, I believe I misunderstood the concept of a vectorized environment. Thought since each process in the subenvironment would be parallelized, if we put the class inside, it would be parallelized.

Will work on the fix for merge_h5 according to #611 (comment)

… to merge_trajectories, and add docstring

- Fixed bug to ensure the first value of keys (except "episodes") is used.
- Renamed merge_h5 to merge_trajectories for more accurate naming.
- Added docstring for better documentation.

# Ignore commit info
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commit info is now preserved in the trajectory data because I thought it could be useful when the version of trajectory generation code is different (e.g., if someone made changes on panda motionplanner).

cnt += 1

h5_file.close()
logger.info(f"Merging{traj_path}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this logger.info from print. Is there a recommended practice on when to use logger.info and when to use print?

Copy link
Member

Choose a reason for hiding this comment

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

better to use logger, thanks for using the right tool here.

cnt += 1

h5_file.close()
logger.info(f"Merging{traj_path}")
Copy link
Member

Choose a reason for hiding this comment

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

better to use logger, thanks for using the right tool here.

@StoneT2000 StoneT2000 merged commit d01141d into haosulab:main Oct 14, 2024
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.

2 participants