Skip to content

[Feature] Warn when kwargs passed to a Scenario are not used #117

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tests/test_scenarios/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def setup_env(

@pytest.mark.parametrize("n_agents", [1, 4])
def test_heuristic(self, n_agents, n_steps=50, n_envs=4):
self.setup_env(
n_agents=n_agents, random_package_pos_on_line=False, n_envs=n_envs
)
self.setup_env(n_agents=n_agents, n_envs=n_envs)
policy = discovery.HeuristicPolicy(True)

obs = self.env.reset()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_scenarios/test_flocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def setup_env(

@pytest.mark.parametrize("n_agents", [1, 5])
def test_heuristic(self, n_agents, n_steps=50, n_envs=4):
self.setup_env(
n_agents=n_agents, random_package_pos_on_line=False, n_envs=n_envs
)
self.setup_env(n_agents=n_agents, n_envs=n_envs)
policy = flocking.HeuristicPolicy(True)

obs = self.env.reset()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_scenarios/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def test_not_passing_through_packages(self, n_agents=1, n_envs=4):

@pytest.mark.parametrize("n_agents", [6])
def test_heuristic(self, n_agents, n_envs=4):
self.setup_env(
n_agents=n_agents, random_package_pos_on_line=False, n_envs=n_envs
)
self.setup_env(n_agents=n_agents, n_envs=n_envs)
policy = transport.HeuristicPolicy(self.continuous_actions)

obs = self.env.reset()
Expand Down
14 changes: 8 additions & 6 deletions vmas/examples/use_vmas_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def use_vmas_env(
random_action: bool = False,
device: str = "cpu",
scenario_name: str = "waterfall",
n_agents: int = 4,
continuous_actions: bool = True,
visualize_render: bool = True,
dict_spaces: bool = True,
**kwargs,
):
"""Example function to use a vmas environment

Args:
continuous_actions (bool): Whether the agents have continuous or discrete actions
n_agents (int): Number of agents
scenario_name (str): Name of scenario
device (str): Torch device to use
render (bool): Whether to render the scenario
Expand All @@ -48,15 +48,15 @@ def use_vmas_env(
n_steps (int): Number of steps before returning done
random_action (bool): Use random actions or have all agents perform the down action
visualize_render (bool, optional): Whether to visualize the render. Defaults to ``True``.
dict_spaces (bool, optional): Weather to return obs, rewards, and infos as dictionaries with agent names.
By default, they are lists of len # of agents
kwargs (dict, optional): Keyword arguments to pass to the scenario

Returns:

"""
assert not (save_render and not render), "To save the video you have to render it"

dict_spaces = True # Weather to return obs, rewards, and infos as dictionaries with agent names
# (by default they are lists of len # of agents)

env = make_env(
scenario=scenario_name,
num_envs=num_envs,
Expand All @@ -66,7 +66,7 @@ def use_vmas_env(
wrapper=None,
seed=None,
# Environment specific variables
n_agents=n_agents,
**kwargs,
)

frame_list = [] # For creating a gif
Expand Down Expand Up @@ -121,4 +121,6 @@ def use_vmas_env(
save_render=False,
random_action=False,
continuous_actions=False,
# Environment specific
n_agents=4,
)
9 changes: 5 additions & 4 deletions vmas/scenarios/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from vmas.simulator.core import Agent, Box, Landmark, Line, Sphere, World
from vmas.simulator.heuristic_policy import BaseHeuristicPolicy
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, Y
from vmas.simulator.utils import Color, ScenarioUtils, Y


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.n_agents = kwargs.get("n_agents", 3)
self.package_mass = kwargs.get("package_mass", 5)
self.random_package_pos_on_line = kwargs.get("random_package_pos_on_line", True)
self.n_agents = kwargs.pop("n_agents", 3)
self.package_mass = kwargs.pop("package_mass", 5)
self.random_package_pos_on_line = kwargs.pop("random_package_pos_on_line", True)
ScenarioUtils.check_kwargs_consumed(kwargs)

assert self.n_agents > 1

Expand Down
9 changes: 5 additions & 4 deletions vmas/scenarios/ball_passage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
from vmas import render_interactively
from vmas.simulator.core import Agent, Box, Landmark, Line, Sphere, World
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, X, Y
from vmas.simulator.utils import Color, ScenarioUtils, X, Y


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.n_passages = kwargs.get("n_passages", 1)
self.fixed_passage = kwargs.get("fixed_passage", False)
self.random_start_angle = kwargs.get("random_start_angle", True)
self.n_passages = kwargs.pop("n_passages", 1)
self.fixed_passage = kwargs.pop("fixed_passage", False)
self.random_start_angle = kwargs.pop("random_start_angle", True)
ScenarioUtils.check_kwargs_consumed(kwargs)

assert 1 <= self.n_passages <= 20

Expand Down
11 changes: 6 additions & 5 deletions vmas/scenarios/ball_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
from vmas.simulator.core import Agent, Landmark, Sphere, World
from vmas.simulator.joints import Joint
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, JOINT_FORCE, X
from vmas.simulator.utils import Color, JOINT_FORCE, ScenarioUtils, X


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.pos_shaping_factor = kwargs.get("pos_shaping_factor", 0)
self.speed_shaping_factor = kwargs.get("speed_shaping_factor", 1)
self.dist_shaping_factor = kwargs.get("dist_shaping_factor", 0)
self.joints = kwargs.get("joints", True)
self.pos_shaping_factor = kwargs.pop("pos_shaping_factor", 0)
self.speed_shaping_factor = kwargs.pop("speed_shaping_factor", 1)
self.dist_shaping_factor = kwargs.pop("dist_shaping_factor", 0)
self.joints = kwargs.pop("joints", True)
ScenarioUtils.check_kwargs_consumed(kwargs)

self.n_agents = 2

Expand Down
11 changes: 6 additions & 5 deletions vmas/scenarios/buzz_wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
from vmas.simulator.core import Agent, Landmark, Line, Sphere, World
from vmas.simulator.joints import Joint
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color
from vmas.simulator.utils import Color, ScenarioUtils


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.random_start_angle = kwargs.get("random_start_angle", True)
self.pos_shaping_factor = kwargs.get("pos_shaping_factor", 1)
self.collision_reward = kwargs.get("collision_reward", -10)
self.max_speed_1 = kwargs.get("max_speed_1", None) # 0.05
self.random_start_angle = kwargs.pop("random_start_angle", True)
self.pos_shaping_factor = kwargs.pop("pos_shaping_factor", 1)
self.collision_reward = kwargs.pop("collision_reward", -10)
self.max_speed_1 = kwargs.pop("max_speed_1", None) # 0.05
ScenarioUtils.check_kwargs_consumed(kwargs)

self.pos_shaping_factor = 1

Expand Down
26 changes: 14 additions & 12 deletions vmas/scenarios/debug/asym_joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from vmas.simulator.core import Agent, Landmark, Sphere, World
from vmas.simulator.joints import Joint
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color
from vmas.simulator.utils import Color, ScenarioUtils

if typing.TYPE_CHECKING:
from vmas.simulator.rendering import Geom
Expand Down Expand Up @@ -47,19 +47,21 @@ def angle_to_vector(angle):

class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.joint_length = kwargs.get("joint_length", 0.5)
self.random_start_angle = kwargs.get("random_start_angle", False)
self.observe_joint_angle = kwargs.get("observe_joint_angle", False)
self.joint_angle_obs_noise = kwargs.get("joint_angle_obs_noise", 0.0)
self.asym_package = kwargs.get("asym_package", True)
self.mass_ratio = kwargs.get("mass_ratio", 5)
self.mass_position = kwargs.get("mass_position", 0.75)
self.max_speed_1 = kwargs.get("max_speed_1", None) # 0.1
self.obs_noise = kwargs.get("obs_noise", 0.2)
self.joint_length = kwargs.pop("joint_length", 0.5)
self.random_start_angle = kwargs.pop("random_start_angle", False)
self.observe_joint_angle = kwargs.pop("observe_joint_angle", False)
self.joint_angle_obs_noise = kwargs.pop("joint_angle_obs_noise", 0.0)
self.asym_package = kwargs.pop("asym_package", True)
self.mass_ratio = kwargs.pop("mass_ratio", 5)
self.mass_position = kwargs.pop("mass_position", 0.75)
self.max_speed_1 = kwargs.pop("max_speed_1", None) # 0.1
self.obs_noise = kwargs.pop("obs_noise", 0.2)

# Reward
self.rot_shaping_factor = kwargs.get("rot_shaping_factor", 1)
self.energy_reward_coeff = kwargs.get("energy_reward_coeff", 0.08)
self.rot_shaping_factor = kwargs.pop("rot_shaping_factor", 1)
self.energy_reward_coeff = kwargs.pop("energy_reward_coeff", 0.08)

ScenarioUtils.check_kwargs_consumed(kwargs)

# Make world
world = World(
Expand Down
15 changes: 8 additions & 7 deletions vmas/scenarios/debug/circle_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
from vmas.simulator.controllers.velocity_controller import VelocityController
from vmas.simulator.core import Agent, Sphere, World
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, TorchUtils, X, Y
from vmas.simulator.utils import Color, ScenarioUtils, TorchUtils, X, Y


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.u_range = kwargs.get("u_range", 1)
self.a_range = kwargs.get("a_range", 1)
self.obs_noise = kwargs.get("obs_noise", 0.0)
self.dt_delay = kwargs.get("dt_delay", 0)
self.min_input_norm = kwargs.get("min_input_norm", 0.08)
self.linear_friction = kwargs.get("linear_friction", 0.1)
self.u_range = kwargs.pop("u_range", 1)
self.a_range = kwargs.pop("a_range", 1)
self.obs_noise = kwargs.pop("obs_noise", 0.0)
self.dt_delay = kwargs.pop("dt_delay", 0)
self.min_input_norm = kwargs.pop("min_input_norm", 0.08)
self.linear_friction = kwargs.pop("linear_friction", 0.1)
ScenarioUtils.check_kwargs_consumed(kwargs)

self.agent_radius = 0.16
self.desired_radius = 1.5
Expand Down
3 changes: 2 additions & 1 deletion vmas/scenarios/debug/diff_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
"""
# T
self.plot_grid = True
self.n_agents = kwargs.get("n_agents", 2)
self.n_agents = kwargs.pop("n_agents", 2)
ScenarioUtils.check_kwargs_consumed(kwargs)

# Make world
world = World(batch_dim, device, substeps=10)
Expand Down
3 changes: 2 additions & 1 deletion vmas/scenarios/debug/drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
You can control the three input torques using left/right arrows, up/down arrows, and m/n.
"""
self.plot_grid = True
self.n_agents = kwargs.get("n_agents", 2)
self.n_agents = kwargs.pop("n_agents", 2)
ScenarioUtils.check_kwargs_consumed(kwargs)

# Make world
world = World(batch_dim, device, substeps=10)
Expand Down
23 changes: 12 additions & 11 deletions vmas/scenarios/debug/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
from vmas.simulator.controllers.velocity_controller import VelocityController
from vmas.simulator.core import Agent, Landmark, Sphere, World
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, TorchUtils
from vmas.simulator.utils import Color, ScenarioUtils, TorchUtils


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.u_range = kwargs.get("u_range", 1)
self.a_range = kwargs.get("a_range", 1)
self.obs_noise = kwargs.get("obs_noise", 0.0)
self.dt_delay = kwargs.get("dt_delay", 0)
self.min_input_norm = kwargs.get("min_input_norm", 0.08)
self.linear_friction = kwargs.get("linear_friction", 0.1)

self.pos_shaping_factor = kwargs.get("pos_shaping_factor", 1.0)
self.time_rew_coeff = kwargs.get("time_rew_coeff", -0.01)
self.energy_reward_coeff = kwargs.get("energy_rew_coeff", 0.0)
self.u_range = kwargs.pop("u_range", 1)
self.a_range = kwargs.pop("a_range", 1)
self.obs_noise = kwargs.pop("obs_noise", 0.0)
self.dt_delay = kwargs.pop("dt_delay", 0)
self.min_input_norm = kwargs.pop("min_input_norm", 0.08)
self.linear_friction = kwargs.pop("linear_friction", 0.1)

self.pos_shaping_factor = kwargs.pop("pos_shaping_factor", 1.0)
self.time_rew_coeff = kwargs.pop("time_rew_coeff", -0.01)
self.energy_reward_coeff = kwargs.pop("energy_rew_coeff", 0.0)
ScenarioUtils.check_kwargs_consumed(kwargs)

self.viewer_size = (1600, 700)
self.viewer_zoom = 2
Expand Down
9 changes: 5 additions & 4 deletions vmas/scenarios/debug/het_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from vmas import render_interactively
from vmas.simulator.core import Agent, World
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, Y
from vmas.simulator.utils import Color, ScenarioUtils, Y


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.green_mass = kwargs.get("green_mass", 4)
self.blue_mass = kwargs.get("blue_mass", 2)
self.mass_noise = kwargs.get("mass_noise", 1)
self.green_mass = kwargs.pop("green_mass", 4)
self.blue_mass = kwargs.pop("blue_mass", 2)
self.mass_noise = kwargs.pop("mass_noise", 1)
ScenarioUtils.check_kwargs_consumed(kwargs)
self.plot_grid = True

# Make world
Expand Down
13 changes: 7 additions & 6 deletions vmas/scenarios/debug/kinematic_bicycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
"""
Kinematic bicycle model example scenario
"""
self.n_agents = kwargs.get("n_agents", 2)
width = kwargs.get("width", 0.1) # Agent width
l_f = kwargs.get(
self.n_agents = kwargs.pop("n_agents", 2)
width = kwargs.pop("width", 0.1) # Agent width
l_f = kwargs.pop(
"l_f", 0.1
) # Distance between the front axle and the center of gravity
l_r = kwargs.get(
l_r = kwargs.pop(
"l_r", 0.1
) # Distance between the rear axle and the center of gravity
max_steering_angle = kwargs.get(
max_steering_angle = kwargs.pop(
"max_steering_angle", torch.deg2rad(torch.tensor(30.0))
)
max_speed = kwargs.get("max_speed", 1.0)
max_speed = kwargs.pop("max_speed", 1.0)
ScenarioUtils.check_kwargs_consumed(kwargs)

# Make world
world = World(batch_dim, device, substeps=10, collision_force=500)
Expand Down
5 changes: 3 additions & 2 deletions vmas/scenarios/debug/line_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
from vmas.simulator.controllers.velocity_controller import VelocityController
from vmas.simulator.core import Agent, Sphere, World
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, X, Y
from vmas.simulator.utils import Color, ScenarioUtils, X, Y


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.obs_noise = kwargs.get("obs_noise", 0)
self.obs_noise = kwargs.pop("obs_noise", 0)
ScenarioUtils.check_kwargs_consumed(kwargs)

self.agent_radius = 0.03
self.line_length = 3
Expand Down
7 changes: 4 additions & 3 deletions vmas/scenarios/debug/pollock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.n_agents = kwargs.get("n_agents", 15)
self.n_lines = kwargs.get("n_lines", 15)
self.n_boxes = kwargs.get("n_boxes", 15)
self.n_agents = kwargs.pop("n_agents", 15)
self.n_lines = kwargs.pop("n_lines", 15)
self.n_boxes = kwargs.pop("n_boxes", 15)
ScenarioUtils.check_kwargs_consumed(kwargs)

self.agent_radius = 0.05
self.line_length = 0.3
Expand Down
5 changes: 3 additions & 2 deletions vmas/scenarios/debug/vel_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
from vmas.simulator.controllers.velocity_controller import VelocityController
from vmas.simulator.core import Agent, Landmark, World
from vmas.simulator.scenario import BaseScenario
from vmas.simulator.utils import Color, TorchUtils, X
from vmas.simulator.utils import Color, ScenarioUtils, TorchUtils, X


class Scenario(BaseScenario):
def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.green_mass = kwargs.get("green_mass", 1)
self.green_mass = kwargs.pop("green_mass", 1)
ScenarioUtils.check_kwargs_consumed(kwargs)
self.plot_grid = True

self.agent_radius = 0.16
Expand Down
Loading
Loading