|
5 | 5 |
|
6 | 6 | """Tests for the minimal Hydra environment-configuration example.""" |
7 | 7 |
|
| 8 | +from pathlib import Path |
| 9 | + |
8 | 10 | import pytest |
9 | 11 | from hydra.errors import ConfigCompositionException |
10 | 12 |
|
11 | | -from isaaclab_arena_examples.hydra_configuration.config import ArenaRunConfiguration, compose_hydra_example_suite |
12 | | -from isaaclab_arena_examples.hydra_configuration.pick_and_place_maple_table import ( |
13 | | - PickAndPlaceMapleTableEnvironmentConfiguration, |
| 13 | +from isaaclab_arena.assets.registries import EnvironmentRegistry |
| 14 | +from isaaclab_arena.evaluation.arena_job_cfg import ArenaJobCfg |
| 15 | +from isaaclab_arena_environments.pick_and_place_maple_table_environment import ( |
| 16 | + PickAndPlaceMapleTableEnvironment, |
| 17 | + PickAndPlaceMapleTableEnvironmentCfg, |
| 18 | +) |
| 19 | +from isaaclab_arena_examples.hydra_configuration.run import ( |
| 20 | + _evaluation_runner_arguments, |
| 21 | + _job_from_configuration, |
| 22 | + compose_from_command_line, |
| 23 | + compose_hydra_example_jobs, |
14 | 24 | ) |
15 | | -from isaaclab_arena_examples.hydra_configuration.run import _job_from_configuration, compose_from_command_line |
16 | 25 |
|
| 26 | +EXAMPLE_CONFIG_PATH = ( |
| 27 | + Path(__file__).parents[2] / "isaaclab_arena_examples" / "hydra_configuration" / "hydra_example_suite.yaml" |
| 28 | +) |
17 | 29 |
|
18 | | -def test_hydra_example_suite_composes_to_concrete_environment_configuration(): |
19 | | - configuration = compose_hydra_example_suite() |
20 | 30 |
|
21 | | - assert isinstance(configuration, ArenaRunConfiguration) |
22 | | - assert isinstance(configuration.environment, PickAndPlaceMapleTableEnvironmentConfiguration) |
23 | | - assert configuration.environment.embodiment_asset_name == "droid_abs_joint_pos" |
24 | | - assert configuration.environment.pick_up_object_asset_name == "rubiks_cube_hot3d_robolab" |
25 | | - assert configuration.policy.type == "zero_action" |
26 | | - assert configuration.rollout.num_steps > 0 |
| 31 | +def test_hydra_example_jobs_port_variations_job_and_control(): |
| 32 | + jobs = compose_hydra_example_jobs(EXAMPLE_CONFIG_PATH) |
| 33 | + |
| 34 | + assert [job.name for job in jobs] == ["variations_demo", "baseline_no_variations"] |
| 35 | + assert all(isinstance(job, ArenaJobCfg) for job in jobs) |
| 36 | + assert all(isinstance(job.environment, PickAndPlaceMapleTableEnvironmentCfg) for job in jobs) |
| 37 | + assert all(job.environment.name == "pick_and_place_maple_table" for job in jobs) |
| 38 | + assert all(job.environment.enable_cameras for job in jobs) |
| 39 | + assert all(job.environment.embodiment_asset_name == "droid_rel_joint_pos" for job in jobs) |
| 40 | + assert all(job.environment.high_dynamic_range_image_name == "home_office_robolab" for job in jobs) |
| 41 | + assert all(job.environment.pick_up_object_asset_name == "rubiks_cube_hot3d_robolab" for job in jobs) |
| 42 | + assert all(job.environment.destination_location_asset_name == "bowl_ycb_robolab" for job in jobs) |
| 43 | + assert jobs[0].environment is not jobs[1].environment |
| 44 | + assert all(job.policy.type == "zero_action" for job in jobs) |
| 45 | + assert all(job.rollout.num_steps == 10 for job in jobs) |
| 46 | + assert all(job.num_rebuilds == 1 for job in jobs) |
| 47 | + assert jobs[0].variations == { |
| 48 | + "light": { |
| 49 | + "hdr_image": {"enabled": True}, |
| 50 | + "intensity": {"enabled": True}, |
| 51 | + }, |
| 52 | + "droid_rel_joint_pos": { |
| 53 | + "camera_extrinsics_wrist_camera": {"enabled": True}, |
| 54 | + }, |
| 55 | + } |
| 56 | + assert jobs[1].variations == {} |
| 57 | + |
| 58 | + |
| 59 | +def test_hydra_example_jobs_accept_typed_shared_environment_override(): |
| 60 | + jobs = compose_hydra_example_jobs(EXAMPLE_CONFIG_PATH, ["environment.light_intensity=825"]) |
| 61 | + |
| 62 | + assert [job.environment.light_intensity for job in jobs] == [825.0, 825.0] |
| 63 | + |
| 64 | + |
| 65 | +def test_hydra_example_jobs_preserve_add_operator_for_shared_override(): |
| 66 | + jobs = compose_hydra_example_jobs(EXAMPLE_CONFIG_PATH, ["+policy.parameters.checkpoint=/tmp/model"]) |
| 67 | + |
| 68 | + assert [job.policy.parameters["checkpoint"] for job in jobs] == ["/tmp/model", "/tmp/model"] |
| 69 | + |
| 70 | + |
| 71 | +def test_hydra_example_cli_keeps_dispatcher_flags_out_of_job_configuration(): |
| 72 | + jobs, launcher_arguments = compose_from_command_line([ |
| 73 | + str(EXAMPLE_CONFIG_PATH), |
| 74 | + "--device", |
| 75 | + "cuda:1", |
| 76 | + "--viz", |
| 77 | + "kit", |
| 78 | + "rollout.num_steps=1", |
| 79 | + ]) |
| 80 | + eval_arguments = _evaluation_runner_arguments( |
| 81 | + jobs, |
| 82 | + launcher_arguments.device, |
| 83 | + launcher_arguments.visualizer, |
| 84 | + ) |
| 85 | + |
| 86 | + assert launcher_arguments.device == "cuda:1" |
| 87 | + assert launcher_arguments.visualizer == "kit" |
| 88 | + assert [job.rollout.num_steps for job in jobs] == [1, 1] |
| 89 | + assert eval_arguments.device == "cuda:1" |
| 90 | + assert eval_arguments.visualizer == "kit" |
| 91 | + assert eval_arguments.enable_cameras |
27 | 92 |
|
28 | 93 |
|
29 | | -def test_hydra_example_suite_accepts_typed_environment_override(): |
30 | | - configuration = compose_hydra_example_suite(["environment.light_intensity=750"]) |
| 94 | +def test_hydra_example_cli_requires_a_yaml_path(): |
| 95 | + with pytest.raises(SystemExit): |
| 96 | + compose_from_command_line([]) |
31 | 97 |
|
32 | | - assert configuration.environment.light_intensity == 750.0 |
33 | 98 |
|
| 99 | +def test_dispatcher_aggregates_camera_requirements_without_mutating_jobs(): |
| 100 | + no_cameras = ArenaJobCfg( |
| 101 | + name="no_cameras", |
| 102 | + environment=PickAndPlaceMapleTableEnvironmentCfg(), |
| 103 | + ) |
| 104 | + with_cameras = ArenaJobCfg( |
| 105 | + name="with_cameras", |
| 106 | + environment=PickAndPlaceMapleTableEnvironmentCfg(enable_cameras=True), |
| 107 | + ) |
34 | 108 |
|
35 | | -def test_hydra_example_cli_maps_visualizer_and_forwards_hydra_overrides(): |
36 | | - configuration = compose_from_command_line(["--viz", "kit", "rollout.num_steps=1"]) |
| 109 | + eval_arguments = _evaluation_runner_arguments([no_cameras, with_cameras], "cuda:0", None) |
37 | 110 |
|
38 | | - assert configuration.simulation_app.visualizer == "kit" |
39 | | - assert configuration.rollout.num_steps == 1 |
| 111 | + assert eval_arguments.enable_cameras |
| 112 | + assert not no_cameras.environment.enable_cameras |
| 113 | + assert with_cameras.environment.enable_cameras |
40 | 114 |
|
41 | 115 |
|
42 | | -def test_hydra_example_suite_rejects_unknown_environment_option(): |
| 116 | +def test_hydra_example_jobs_reject_unknown_environment_option(): |
43 | 117 | with pytest.raises(ConfigCompositionException, match="unknown_option"): |
44 | | - compose_hydra_example_suite(["environment.unknown_option=true"]) |
| 118 | + compose_hydra_example_jobs(EXAMPLE_CONFIG_PATH, ["environment.unknown_option=true"]) |
45 | 119 |
|
46 | 120 |
|
47 | | -def test_hydra_run_maps_to_eval_job_without_environment_cli_round_trip(): |
48 | | - configuration = compose_hydra_example_suite([ |
49 | | - "name=mapped_run", |
50 | | - "environment_builder.num_envs=3", |
51 | | - "policy.type=zero_action", |
52 | | - "rollout.num_steps=7", |
53 | | - ]) |
| 121 | +def test_hydra_example_jobs_apply_python_defaults_to_minimal_yaml(tmp_path): |
| 122 | + config_path = tmp_path / "minimal_jobs.yaml" |
| 123 | + config_path.write_text("""\ |
| 124 | +jobs: |
| 125 | + - name: maple_table_job |
| 126 | + environment: |
| 127 | + name: pick_and_place_maple_table |
| 128 | +""") |
| 129 | + |
| 130 | + jobs = compose_hydra_example_jobs(config_path) |
| 131 | + |
| 132 | + assert [job.name for job in jobs] == ["maple_table_job"] |
| 133 | + assert isinstance(jobs[0].environment, PickAndPlaceMapleTableEnvironmentCfg) |
| 134 | + |
54 | 135 |
|
55 | | - job = _job_from_configuration(configuration) |
| 136 | +def test_hydra_example_jobs_resolve_environment_configuration_through_registry(): |
| 137 | + jobs = compose_hydra_example_jobs(EXAMPLE_CONFIG_PATH) |
56 | 138 |
|
57 | | - assert job.name == "mapped_run" |
58 | | - assert job.num_envs == 3 |
59 | | - assert job.num_steps == 7 |
60 | | - assert job.policy_type == "zero_action" |
61 | | - assert job.policy_config_dict == {} |
62 | | - assert job.arena_env_args == [] |
| 139 | + provider = EnvironmentRegistry().get_component_by_name(jobs[0].environment.name) |
| 140 | + |
| 141 | + assert provider is PickAndPlaceMapleTableEnvironment |
| 142 | + assert provider.cfg_type is PickAndPlaceMapleTableEnvironmentCfg |
| 143 | + |
| 144 | + |
| 145 | +def test_hydra_example_jobs_require_an_environment_name(tmp_path): |
| 146 | + config_path = tmp_path / "missing_environment_name.yaml" |
| 147 | + config_path.write_text("""\ |
| 148 | +jobs: |
| 149 | + - name: maple_table_job |
| 150 | + environment: {} |
| 151 | +""") |
| 152 | + |
| 153 | + with pytest.raises(AssertionError, match="environment.name must be a string"): |
| 154 | + compose_hydra_example_jobs(config_path) |
| 155 | + |
| 156 | + |
| 157 | +def test_hydra_example_jobs_reject_unknown_yaml_environment_option(tmp_path): |
| 158 | + config_path = tmp_path / "invalid_jobs.yaml" |
| 159 | + config_path.write_text("""\ |
| 160 | +jobs: |
| 161 | + - name: maple_table_job |
| 162 | + environment: |
| 163 | + name: pick_and_place_maple_table |
| 164 | + unknown_option: true |
| 165 | +""") |
| 166 | + |
| 167 | + with pytest.raises(ConfigCompositionException, match="unknown_option"): |
| 168 | + compose_hydra_example_jobs(config_path) |
| 169 | + |
| 170 | + |
| 171 | +def test_hydra_example_jobs_reject_duplicate_names(tmp_path): |
| 172 | + config_path = tmp_path / "duplicate_jobs.yaml" |
| 173 | + config_path.write_text("""\ |
| 174 | +jobs: |
| 175 | + - name: duplicate |
| 176 | + environment: |
| 177 | + name: pick_and_place_maple_table |
| 178 | + - name: duplicate |
| 179 | + environment: |
| 180 | + name: pick_and_place_maple_table |
| 181 | +""") |
| 182 | + |
| 183 | + with pytest.raises(AssertionError, match="job names must be unique"): |
| 184 | + compose_hydra_example_jobs(config_path) |
| 185 | + |
| 186 | + |
| 187 | +def test_hydra_jobs_map_to_eval_jobs_without_environment_cli_round_trip(): |
| 188 | + configurations = compose_hydra_example_jobs( |
| 189 | + EXAMPLE_CONFIG_PATH, |
| 190 | + [ |
| 191 | + "environment_builder.num_envs=3", |
| 192 | + "policy.type=zero_action", |
| 193 | + "rollout.num_steps=7", |
| 194 | + ], |
| 195 | + ) |
| 196 | + |
| 197 | + jobs = [_job_from_configuration(configuration) for configuration in configurations] |
| 198 | + |
| 199 | + assert [job.name for job in jobs] == ["variations_demo", "baseline_no_variations"] |
| 200 | + assert all(job.num_envs == 3 for job in jobs) |
| 201 | + assert all(job.num_steps == 7 for job in jobs) |
| 202 | + assert all(job.num_rebuilds == 1 for job in jobs) |
| 203 | + assert all(job.policy_type == "zero_action" for job in jobs) |
| 204 | + assert all(job.policy_config_dict == {} for job in jobs) |
| 205 | + assert all(job.arena_env_args == [] for job in jobs) |
| 206 | + assert set(jobs[0].variations) == { |
| 207 | + "light.hdr_image.enabled=true", |
| 208 | + "light.intensity.enabled=true", |
| 209 | + "droid_rel_joint_pos.camera_extrinsics_wrist_camera.enabled=true", |
| 210 | + } |
| 211 | + assert jobs[1].variations == [] |
0 commit comments