|
|
|
|
|
|
steps_from_proto, |
|
|
|
) |
|
|
|
from PIL import Image |
|
|
|
from mlagents.trainers.tests.dummy_config import create_sensor_specs_with_shapes |
|
|
|
from mlagents.trainers.tests.dummy_config import create_observation_specs_with_shapes |
|
|
|
|
|
|
|
|
|
|
|
def generate_list_agent_proto( |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_continuous(3) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_continuous(3) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes) |
|
|
|
decision_steps, terminal_steps = steps_from_proto(ap_list, spec) |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
behavior_spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_discrete((7, 3)) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_discrete((7, 3)) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes) |
|
|
|
decision_steps, terminal_steps = steps_from_proto(ap_list, behavior_spec) |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
behavior_spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_discrete((10,)) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_discrete((10,)) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes) |
|
|
|
decision_steps, terminal_steps = steps_from_proto(ap_list, behavior_spec) |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
behavior_spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_discrete((2, 2, 6)) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_discrete((2, 2, 6)) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes) |
|
|
|
decision_steps, terminal_steps = steps_from_proto(ap_list, behavior_spec) |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
behavior_spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_continuous(10) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_continuous(10) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes) |
|
|
|
decision_steps, terminal_steps = steps_from_proto(ap_list, behavior_spec) |
|
|
|
|
|
|
behavior_spec = behavior_spec_from_proto(bp, agent_proto) |
|
|
|
assert behavior_spec.action_spec.is_discrete() |
|
|
|
assert not behavior_spec.action_spec.is_continuous() |
|
|
|
assert [spec.shape for spec in behavior_spec.sensor_specs] == [(3,), (4,)] |
|
|
|
assert [spec.shape for spec in behavior_spec.observation_specs] == [(3,), (4,)] |
|
|
|
assert behavior_spec.action_spec.discrete_branches == (5, 4) |
|
|
|
assert behavior_spec.action_spec.discrete_size == 2 |
|
|
|
bp = BrainParametersProto() |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
behavior_spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_continuous(3) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_continuous(3) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes, infinite_rewards=True) |
|
|
|
with pytest.raises(RuntimeError): |
|
|
|
|
|
|
n_agents = 10 |
|
|
|
shapes = [(3,), (4,)] |
|
|
|
behavior_spec = BehaviorSpec( |
|
|
|
create_sensor_specs_with_shapes(shapes), ActionSpec.create_continuous(3) |
|
|
|
create_observation_specs_with_shapes(shapes), ActionSpec.create_continuous(3) |
|
|
|
) |
|
|
|
ap_list = generate_list_agent_proto(n_agents, shapes, nan_observations=True) |
|
|
|
with pytest.raises(RuntimeError): |