Skip to content

Commit

Permalink
Fixing the analytics side-channel for curriculum learning. (#5586)
Browse files Browse the repository at this point in the history
* 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 <honari.m94@gmail.com>

Co-authored-by: Maryam Honari <honari.m94@gmail.com>
  • Loading branch information
maryamhonari and maryamhonari committed Nov 4, 2021
1 parent 3fe4e03 commit 92f1d1f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to
- Upgrade to 2.0.1
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Set gym version in gym-unity to gym release 0.20.0
- Fixed the bug where curriculum learning would crash because of the incorrect run_options parsing. (#5586)
- Added minimal analytics collection to LL-API (#5511)

## [2.0.0] - 2021-09-01
Expand Down
4 changes: 3 additions & 1 deletion ml-agents/mlagents/trainers/subprocess_env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
EnvironmentStats,
StatsSideChannel,
)
from mlagents.training_analytics_side_channel import TrainingAnalyticsSideChannel
from mlagents.trainers.training_analytics_side_channel import (
TrainingAnalyticsSideChannel,
)
from mlagents_envs.side_channel.side_channel import SideChannel


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import yaml
from mlagents.trainers.settings import RunOptions
from mlagents.trainers.training_analytics_side_channel import (
TrainingAnalyticsSideChannel,
)

test_curriculum_config_yaml = """
environment_parameters:
param_1:
curriculum:
- name: Lesson1
completion_criteria:
measure: reward
behavior: fake_behavior
threshold: 30
min_lesson_length: 100
require_reset: true
value: 1
- name: Lesson2
completion_criteria:
measure: reward
behavior: fake_behavior
threshold: 60
min_lesson_length: 100
require_reset: false
value: 2
- name: Lesson3
value:
sampler_type: uniform
sampler_parameters:
min_value: 1
max_value: 3
"""


def test_sanitize_run_options():
run_options = RunOptions.from_dict(yaml.safe_load(test_curriculum_config_yaml))
sanitized = TrainingAnalyticsSideChannel._sanitize_run_options(run_options)
assert "param_1" not in sanitized["environment_parameters"]
assert "fake_behavior" not in sanitized["environment_parameters"]
assert (
TrainingAnalyticsSideChannel._hash("param_1")
in sanitized["environment_parameters"]
)
level1 = TrainingAnalyticsSideChannel._hash("param_1")
assert sanitized["environment_parameters"][level1]["curriculum"][0][
"completion_criteria"
]["behavior"] == TrainingAnalyticsSideChannel._hash("fake_behavior")
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ def _sanitize_run_options(cls, config: RunOptions) -> Dict[str, Any]:
updated_lessons = []
for lesson in curriculum["curriculum"]:
new_lesson = copy.deepcopy(lesson)
if lesson.has_keys("name"):
if "name" in lesson:
new_lesson["name"] = cls._hash(lesson["name"])
if lesson.has_keys("completion_criteria"):
if (
"completion_criteria" in lesson
and lesson["completion_criteria"] is not None
):
new_lesson["completion_criteria"]["behavior"] = cls._hash(
new_lesson["completion_criteria"]["behavior"]
)
Expand Down

0 comments on commit 92f1d1f

Please sign in to comment.