-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[π π¨ ] set_action_for_agent expects a ActionTuple with batch size 1. (#β¦
β¦5208) * [Bug Fix] set_action_for_agent expects a ActionTuple with batch size 1. * moving a line around (cherry picked from commit aac2ee6)
- Loading branch information
1 parent
7fae873
commit 2aaf326
Showing
3 changed files
with
60 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from mlagents_envs.registry import default_registry | ||
from mlagents_envs.side_channel.engine_configuration_channel import ( | ||
EngineConfigurationChannel, | ||
) | ||
from mlagents_envs.base_env import ActionTuple | ||
import numpy as np | ||
|
||
BALL_ID = "3DBall" | ||
|
||
|
||
def test_set_action_single_agent(): | ||
engine_config_channel = EngineConfigurationChannel() | ||
env = default_registry[BALL_ID].make( | ||
base_port=6000, | ||
worker_id=0, | ||
no_graphics=True, | ||
side_channels=[engine_config_channel], | ||
) | ||
engine_config_channel.set_configuration_parameters(time_scale=100) | ||
for _ in range(3): | ||
env.reset() | ||
behavior_name = list(env.behavior_specs.keys())[0] | ||
d, t = env.get_steps(behavior_name) | ||
for _ in range(50): | ||
for agent_id in d.agent_id: | ||
action = np.ones((1, 2)) | ||
action_tuple = ActionTuple() | ||
action_tuple.add_continuous(action) | ||
env.set_action_for_agent(behavior_name, agent_id, action_tuple) | ||
env.step() | ||
d, t = env.get_steps(behavior_name) | ||
env.close() | ||
|
||
|
||
def test_set_action_multi_agent(): | ||
engine_config_channel = EngineConfigurationChannel() | ||
env = default_registry[BALL_ID].make( | ||
base_port=6001, | ||
worker_id=0, | ||
no_graphics=True, | ||
side_channels=[engine_config_channel], | ||
) | ||
engine_config_channel.set_configuration_parameters(time_scale=100) | ||
for _ in range(3): | ||
env.reset() | ||
behavior_name = list(env.behavior_specs.keys())[0] | ||
d, t = env.get_steps(behavior_name) | ||
for _ in range(50): | ||
action = np.ones((len(d), 2)) | ||
action_tuple = ActionTuple() | ||
action_tuple.add_continuous(action) | ||
env.set_actions(behavior_name, action_tuple) | ||
env.step() | ||
d, t = env.get_steps(behavior_name) | ||
env.close() |