|
|
|
|
|
|
DemonstrationMetaProto, |
|
|
|
) |
|
|
|
|
|
|
|
from mlagents.trainers.brain import BrainParameters |
|
|
|
from mlagents.trainers.demo_loader import ( |
|
|
|
load_demonstration, |
|
|
|
demo_to_buffer, |
|
|
|
|
|
|
|
|
|
|
BRAIN_PARAMS = BrainParameters( |
|
|
|
brain_name="test_brain", |
|
|
|
vector_observation_space_size=8, |
|
|
|
camera_resolutions=[], |
|
|
|
vector_action_space_size=[2], |
|
|
|
vector_action_descriptions=[], |
|
|
|
vector_action_space_type=1, |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def test_load_demo(): |
|
|
|
path_prefix = os.path.dirname(os.path.abspath(__file__)) |
|
|
|
|
|
|
assert np.sum(behavior_spec.observation_shapes[0]) == 8 |
|
|
|
assert len(pair_infos) == total_expected |
|
|
|
|
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test.demo", 1) |
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test.demo", 1, BRAIN_PARAMS) |
|
|
|
assert len(demo_buffer["actions"]) == total_expected - 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert np.sum(behavior_spec.observation_shapes[0]) == 8 |
|
|
|
assert len(pair_infos) == total_expected |
|
|
|
|
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test_demo_dir", 1) |
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test_demo_dir", 1, BRAIN_PARAMS) |
|
|
|
|
|
|
|
|
|
|
|
def test_demo_mismatch(): |
|
|
|
path_prefix = os.path.dirname(os.path.abspath(__file__)) |
|
|
|
# observation mismatch |
|
|
|
with pytest.raises(RuntimeError): |
|
|
|
brain_params_obs = BrainParameters( |
|
|
|
brain_name="test_brain", |
|
|
|
vector_observation_space_size=9, |
|
|
|
camera_resolutions=[], |
|
|
|
vector_action_space_size=[2], |
|
|
|
vector_action_descriptions=[], |
|
|
|
vector_action_space_type=1, |
|
|
|
) |
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test.demo", 1, brain_params_obs) |
|
|
|
# action mismatch |
|
|
|
with pytest.raises(RuntimeError): |
|
|
|
brain_params_act = BrainParameters( |
|
|
|
brain_name="test_brain", |
|
|
|
vector_observation_space_size=8, |
|
|
|
camera_resolutions=[], |
|
|
|
vector_action_space_size=[3], |
|
|
|
vector_action_descriptions=[], |
|
|
|
vector_action_space_type=1, |
|
|
|
) |
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test.demo", 1, brain_params_act) |
|
|
|
# action type mismatch |
|
|
|
with pytest.raises(RuntimeError): |
|
|
|
brain_params_type = BrainParameters( |
|
|
|
brain_name="test_brain", |
|
|
|
vector_observation_space_size=8, |
|
|
|
camera_resolutions=[], |
|
|
|
vector_action_space_size=[2], |
|
|
|
vector_action_descriptions=[], |
|
|
|
vector_action_space_type=0, |
|
|
|
) |
|
|
|
_, demo_buffer = demo_to_buffer( |
|
|
|
path_prefix + "/test.demo", 1, brain_params_type |
|
|
|
) |
|
|
|
# vis obs mismatch |
|
|
|
with pytest.raises(RuntimeError): |
|
|
|
brain_params_vis = BrainParameters( |
|
|
|
brain_name="test_brain", |
|
|
|
vector_observation_space_size=8, |
|
|
|
camera_resolutions=[[30, 40]], |
|
|
|
vector_action_space_size=[2], |
|
|
|
vector_action_descriptions=[], |
|
|
|
vector_action_space_type=1, |
|
|
|
) |
|
|
|
_, demo_buffer = demo_to_buffer(path_prefix + "/test.demo", 1, brain_params_vis) |
|
|
|
|
|
|
|
|
|
|
|
def test_edge_cases(): |
|
|
|