Skip to content

Commit 05c0275

Browse files
cmardmaryamhonari
andauthored
Fixing the analytics side-channel for curriculum learning. (#5586)
* Fixing the analytics side-channel for curriculum learning. * Made a more robust test. * Update the changelog. * Update com.unity.ml-agents/CHANGELOG.md Co-authored-by: Maryam Honari <[email protected]> Co-authored-by: Maryam Honari <[email protected]>
1 parent 003e8ae commit 05c0275

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

com.unity.ml-agents/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to
2929
2. env_params.restarts_rate_limit_n (--restarts-rate-limit-n) [default=1]
3030
3. env_params.restarts_rate_limit_period_s (--restarts-rate-limit-period-s) [default=60]
3131
### Bug Fixes
32+
- Fixed the bug where curriculum learning would crash because of the incorrect run_options parsing. (#5586)
3233

3334
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
3435

ml-agents/mlagents/trainers/subprocess_env_manager.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
EnvironmentStats,
3939
StatsSideChannel,
4040
)
41-
from mlagents.training_analytics_side_channel import TrainingAnalyticsSideChannel
41+
from mlagents.trainers.training_analytics_side_channel import (
42+
TrainingAnalyticsSideChannel,
43+
)
4244
from mlagents_envs.side_channel.side_channel import SideChannel
4345

4446

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import yaml
2+
from mlagents.trainers.settings import RunOptions
3+
from mlagents.trainers.training_analytics_side_channel import (
4+
TrainingAnalyticsSideChannel,
5+
)
6+
7+
test_curriculum_config_yaml = """
8+
environment_parameters:
9+
param_1:
10+
curriculum:
11+
- name: Lesson1
12+
completion_criteria:
13+
measure: reward
14+
behavior: fake_behavior
15+
threshold: 30
16+
min_lesson_length: 100
17+
require_reset: true
18+
value: 1
19+
- name: Lesson2
20+
completion_criteria:
21+
measure: reward
22+
behavior: fake_behavior
23+
threshold: 60
24+
min_lesson_length: 100
25+
require_reset: false
26+
value: 2
27+
- name: Lesson3
28+
value:
29+
sampler_type: uniform
30+
sampler_parameters:
31+
min_value: 1
32+
max_value: 3
33+
"""
34+
35+
36+
def test_sanitize_run_options():
37+
run_options = RunOptions.from_dict(yaml.safe_load(test_curriculum_config_yaml))
38+
sanitized = TrainingAnalyticsSideChannel._sanitize_run_options(run_options)
39+
assert "param_1" not in sanitized["environment_parameters"]
40+
assert "fake_behavior" not in sanitized["environment_parameters"]
41+
assert (
42+
TrainingAnalyticsSideChannel._hash("param_1")
43+
in sanitized["environment_parameters"]
44+
)
45+
level1 = TrainingAnalyticsSideChannel._hash("param_1")
46+
assert sanitized["environment_parameters"][level1]["curriculum"][0][
47+
"completion_criteria"
48+
]["behavior"] == TrainingAnalyticsSideChannel._hash("fake_behavior")

ml-agents/mlagents/training_analytics_side_channel.py renamed to ml-agents/mlagents/trainers/training_analytics_side_channel.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ def _sanitize_run_options(cls, config: RunOptions) -> Dict[str, Any]:
7474
updated_lessons = []
7575
for lesson in curriculum["curriculum"]:
7676
new_lesson = copy.deepcopy(lesson)
77-
if lesson.has_keys("name"):
77+
if "name" in lesson:
7878
new_lesson["name"] = cls._hash(lesson["name"])
79-
if lesson.has_keys("completion_criteria"):
79+
if (
80+
"completion_criteria" in lesson
81+
and lesson["completion_criteria"] is not None
82+
):
8083
new_lesson["completion_criteria"]["behavior"] = cls._hash(
8184
new_lesson["completion_criteria"]["behavior"]
8285
)

0 commit comments

Comments
 (0)