Skip to content

Commit 92f1d1f

Browse files
committed
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 3fe4e03 commit 92f1d1f

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

com.unity.ml-agents/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to
1111
- Upgrade to 2.0.1
1212
#### ml-agents / ml-agents-envs / gym-unity (Python)
1313
- Set gym version in gym-unity to gym release 0.20.0
14+
- Fixed the bug where curriculum learning would crash because of the incorrect run_options parsing. (#5586)
1415
- Added minimal analytics collection to LL-API (#5511)
1516

1617
## [2.0.0] - 2021-09-01

ml-agents/mlagents/trainers/subprocess_env_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
EnvironmentStats,
3838
StatsSideChannel,
3939
)
40-
from mlagents.training_analytics_side_channel import TrainingAnalyticsSideChannel
40+
from mlagents.trainers.training_analytics_side_channel import (
41+
TrainingAnalyticsSideChannel,
42+
)
4143
from mlagents_envs.side_channel.side_channel import SideChannel
4244

4345

Lines changed: 48 additions & 0 deletions
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

Lines changed: 5 additions & 2 deletions
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)