-
Notifications
You must be signed in to change notification settings - Fork 2
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
Run batch simulations over set of startup params in yaml file #125
Merged
Merged
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f3270ac
proof of concept for looping over simulation parameters
andermi 7bd9088
try to fix
andermi d78e16e
set on_exit shutdown in launch files
andermi 93866dc
install script and example batch sim params; add launch file; set def…
andermi c2cf6ca
add rosbag and a log file; rename some things
andermi 326197f
Merge branch 'main' into andermi/batch_sim
andermi a2203b6
fix max scale in example yaml
andermi e393454
typo
andermi 94fce17
remove noisy prints; get tests passing
andermi 48667fd
use argparse
andermi 7001355
mbari_wec/model.sdf is now generated by empy
andermi 0ce6b71
try to debug pc commands test
andermi e0c211b
debug pc commands test
andermi b1c274c
increase timeout; remove debugging prints
andermi 78ed18a
keep debugging
andermi b800a3a
keep debugging
andermi 469aca9
keep debugging
andermi c45d4ea
remove debugging code
andermi d990b32
set z_ww for doors open/closed -- unused until #115
andermi 862308c
fix argparse
andermi b384e19
cleanup prints; remove default arg for batch launch
andermi 8ccb07d
change iterations to duration in batch params yaml
andermi 780e53a
clean up
andermi 20d3f06
clean up
andermi 9e318a1
added plumbing for random seed but not yet supported by our version o…
andermi 1fda8d9
make new directory for batch results; copy params yaml to results; ti…
andermi f387c0a
add some info prints
andermi 363c37f
flake8
andermi 4fbe16c
error checking; let --seed be optional and other params default; dura…
andermi 5ee531c
Merge branch 'main' into andermi/batch_sim
andermi da98f2c
connect batching template to viscous drag plugin
andermi 8176ac5
retest until pass
andermi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Launch Gazebo world with a buoy.""" | ||
|
||
import os | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
|
||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument, Shutdown | ||
from launch.substitutions import LaunchConfiguration | ||
|
||
from launch_ros.actions import Node | ||
|
||
|
||
def generate_launch_description(): | ||
|
||
pkg_buoy_gazebo = get_package_share_directory('buoy_gazebo') | ||
example_sim_params_yaml = os.path.join(pkg_buoy_gazebo, 'example_sim_params.yaml') | ||
|
||
sim_params_yaml_launch_arg = DeclareLaunchArgument( | ||
'sim_params_yaml', default_value=[example_sim_params_yaml], | ||
description='Input batch sim params yaml' | ||
) | ||
|
||
batch_sim = Node( | ||
package='buoy_gazebo', | ||
executable='mbari_wec_batch', | ||
arguments=[ | ||
LaunchConfiguration('sim_params_yaml'), | ||
], | ||
output='screen', | ||
on_exit=Shutdown() | ||
) | ||
|
||
return LaunchDescription([ | ||
sim_params_yaml_launch_arg, | ||
batch_sim, | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
iterations: 5000 | ||
door_state: ['closed', 'open'] | ||
scale_factor: [0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2022 Open Source Robotics Foundation, Inc. and Monterey Bay Aquarium Research Institute | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Launch batch of buoy simulations.""" | ||
|
||
from em import invoke as empy | ||
import numpy as np | ||
import yaml | ||
|
||
import os | ||
import time | ||
|
||
from ament_index_python.packages import get_package_share_directory | ||
|
||
from launch import LaunchDescription | ||
from launch import LaunchService | ||
from launch.actions import ExecuteProcess, IncludeLaunchDescription | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
|
||
|
||
def generate_simulations(sim_params_yaml): | ||
with open(sim_params_yaml, 'r') as fd: | ||
sim_params = yaml.load(fd, Loader=yaml.CLoader) | ||
|
||
iterations = sim_params['iterations'] | ||
door_state = sim_params['door_state'] | ||
scale_factor = sim_params['scale_factor'] | ||
batch_params = list(zip(*[param.ravel() for param in np.meshgrid(iterations, | ||
door_state, | ||
scale_factor)])) | ||
|
||
print(f'Generated {len(batch_params)} simulation runs:') | ||
print(f'Iterations, Door State, Scale Factor\n{np.array(batch_params)}') | ||
|
||
timestr = time.strftime("%Y%m%d%H%M%S") | ||
with open(f'batch_runs_{timestr}.log', 'w') as fd: | ||
fd.write(f'# Generated {len(batch_params)} simulation runs\n') | ||
fd.write(f'Run Index, Iterations, Door State, Scale Factor\n') | ||
|
||
pkg_buoy_gazebo = get_package_share_directory('buoy_gazebo') | ||
pkg_buoy_description = get_package_share_directory('buoy_description') | ||
|
||
model_dir = 'mbari_wec_base' | ||
empy_base_sdf_file = os.path.join(pkg_buoy_description, 'models', model_dir, 'model.sdf.em') | ||
base_sdf_file = os.path.join(pkg_buoy_description, 'models', model_dir, 'model.sdf') | ||
|
||
model_dir = 'mbari_wec' | ||
empy_sdf_file = os.path.join(pkg_buoy_description, 'models', model_dir, 'model.sdf.em') | ||
sdf_file = os.path.join(pkg_buoy_description, 'models', model_dir, 'model.sdf') | ||
|
||
for idx, (itx, ds, sf) in enumerate(batch_params): | ||
print(f'\n\nSim run [{idx}] for {itx} iterations: door state={ds}, scale factor={sf}\n\n') | ||
empy(['-D', f"door_state = '{ds}'", | ||
'-o', base_sdf_file, | ||
empy_base_sdf_file]) | ||
|
||
empy(['-D', f"scale_factor = '{sf}'", | ||
'-o', sdf_file, | ||
empy_sdf_file]) | ||
|
||
def generate_launch_description(): | ||
mbari_wec = IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource( | ||
os.path.join(pkg_buoy_gazebo, 'launch', 'mbari_wec.launch.py'), | ||
), | ||
launch_arguments={'gz_args': f'-rs --iterations {itx}'}.items(), | ||
) | ||
|
||
rosbag2_name = f'rosbag2_batch_sim_{idx}' | ||
rosbag2 = ExecuteProcess( | ||
cmd=['ros2', 'bag', 'record', '-o', rosbag2_name, '-a'], | ||
output='screen' | ||
) | ||
|
||
with open(f'batch_runs_{timestr}.log', 'a') as fd: | ||
fd.write(f'{idx, itx, ds, sf}\n') | ||
|
||
return LaunchDescription([ | ||
rosbag2, | ||
mbari_wec | ||
]) | ||
|
||
ls = LaunchService() | ||
ls.include_launch_description(generate_launch_description()) | ||
result = ls.run() | ||
if result: | ||
print(f'Simulation run [{idx}] was not successful: return code [{result}]') | ||
|
||
if __name__=='__main__': | ||
import argparse | ||
parser = argparse.ArgumentParser(description='Batch running for buoy_sim') | ||
parser.add_argument('sim_params_yaml', | ||
help='yaml file with batch parameters') | ||
args = parser.parse_args() | ||
generate_simulations(args.sim_params_yaml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FYI, I set
mu_zz
value for added mass depending on the door state, but this PR doesn't have the added mass implemented yet. Somu_zz
is currently unused but ready when #115 is merged (or I can base this PR from that one)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.
Yep, mu_zz in the .sdf.em is in the "add-addedmass-to-sdf" branch and PR, but we can't really merge that until the garden debians are available with the handling of the phantom weight of the added mass terms. Also, there is one other parameter that depends upon the doors open/closed state. That's Z_WW and changes a bit with open/closed, shown here: https://osrf.github.io/buoy_entrypoint/pr-preview/pr-17/theory/ That has not yet been parametrized in a .sdf file anywhere b/c we need the viscous drag branch/pull-request to be completed (goal of this friday...)
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.
@hamilton8415 I now set
z_ww
as well (commit d990b32) but also unused until #115. I made a TODO to update