Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following petting_zoo registry API #5557

Merged
merged 14 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
ruby-version: '2.6'
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
dotnet-version: '6.0.x'
maryamhonari marked this conversation as resolved.
Show resolved Hide resolved
include-prerelease: true
- uses: pre-commit/action@v2.0.0

markdown-link-check:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ jobs:
python -m pip install --progress-bar=off -e ./ml-agents -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -r test_requirements.txt -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./gym-unity -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./pettingzoo-unity -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./ml-agents-plugin-examples -c ${{ matrix.pip_constraints }}
- name: Save python dependencies
run: |
pip freeze > pip_versions-${{ matrix.python-version }}.txt
cat pip_versions-${{ matrix.python-version }}.txt
- name: Run pytest
run: pytest --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings -v
run: pytest --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov=pettingzoo-unity --cov-report=html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings -v
- name: Upload pytest test results
uses: actions/upload-artifact@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ repos:
exclude: ".*localized.*"

- repo: https://github.com/dotnet/format
rev: "7e343070a0355c86f72bdee226b5e19ffcbac931" # TODO - update to a tagged version when one that includes the hook is ready.
rev: v5.1.225507
maryamhonari marked this conversation as resolved.
Show resolved Hide resolved
hooks:
- id: dotnet-format
entry: dotnet-format whitespace
args: [--folder, --include]

# "Local" hooks, see https://pre-commit.com/#repository-local-hooks
Expand Down
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to
terminated teammates. (#5441)
- Fixed wrong attribute name in argparser for torch device option (#5433)(#5467)
- Fixed conflicting CLI and yaml options regarding resume & initialize_from (#5495)
- Added minimal analytics collection to LL-API (#5511)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange that this PR would contain this change, are you sure you cherry picked the right commits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this commit contains the default analytics side channels for custom trainers.

## [2.1.0-exp.1] - 2021-06-09
### Minor Changes
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
Expand Down
1 change: 0 additions & 1 deletion gym-unity/gym_unity/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class UnityGymException(error.Error):


logger = logging_util.get_logger(__name__)
logging_util.set_log_level(logging_util.INFO)

GymStepResult = Tuple[np.ndarray, float, bool, Dict]

Expand Down
13 changes: 13 additions & 0 deletions ml-agents-envs/mlagents_envs/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from mlagents_envs.logging_util import get_logger
from mlagents_envs.side_channel.side_channel import SideChannel
from mlagents_envs.side_channel import DefaultTrainingAnalyticsSideChannel
from mlagents_envs.side_channel.side_channel_manager import SideChannelManager
from mlagents_envs import env_utils

Expand Down Expand Up @@ -186,6 +187,16 @@ def __init__(
self._timeout_wait: int = timeout_wait
self._communicator = self._get_communicator(worker_id, base_port, timeout_wait)
self._worker_id = worker_id
if side_channels is None:
side_channels = []
default_training_side_channel: Optional[
DefaultTrainingAnalyticsSideChannel
] = None
if DefaultTrainingAnalyticsSideChannel.CHANNEL_ID not in [
_.channel_id for _ in side_channels
]:
default_training_side_channel = DefaultTrainingAnalyticsSideChannel()
side_channels.append(default_training_side_channel)
self._side_channel_manager = SideChannelManager(side_channels)
self._log_folder = log_folder
self.academy_capabilities: UnityRLCapabilitiesProto = None # type: ignore
Expand Down Expand Up @@ -246,6 +257,8 @@ def __init__(
self._is_first_message = True
self._update_behavior_specs(aca_output)
self.academy_capabilities = aca_params.capabilities
if default_training_side_channel is not None:
default_training_side_channel.environment_initialized()

@staticmethod
def _get_communicator(worker_id, base_port, timeout_wait):
Expand Down
3 changes: 3 additions & 0 deletions ml-agents-envs/mlagents_envs/side_channel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
from mlagents_envs.side_channel.outgoing_message import OutgoingMessage # noqa

from mlagents_envs.side_channel.side_channel import SideChannel # noqa
from mlagents_envs.side_channel.default_training_analytics_side_channel import ( # noqa
DefaultTrainingAnalyticsSideChannel, # noqa
) # noqa
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sys
import uuid
import mlagents_envs

from mlagents_envs.exception import UnityCommunicationException
from mlagents_envs.side_channel import SideChannel, IncomingMessage, OutgoingMessage
from mlagents_envs.communicator_objects.training_analytics_pb2 import (
TrainingEnvironmentInitialized,
)
from google.protobuf.any_pb2 import Any


class DefaultTrainingAnalyticsSideChannel(SideChannel):
"""
Side channel that sends information about the training to the Unity environment so it can be logged.
"""

CHANNEL_ID = uuid.UUID("b664a4a9-d86f-5a5f-95cb-e8353a7e8356")

def __init__(self) -> None:
# >>> uuid.uuid5(uuid.NAMESPACE_URL, "com.unity.ml-agents/TrainingAnalyticsSideChannel")
# UUID('b664a4a9-d86f-5a5f-95cb-e8353a7e8356')
# We purposefully use the SAME side channel as the TrainingAnalyticsSideChannel

super().__init__(DefaultTrainingAnalyticsSideChannel.CHANNEL_ID)

def on_message_received(self, msg: IncomingMessage) -> None:
raise UnityCommunicationException(
"The DefaultTrainingAnalyticsSideChannel received a message from Unity, "
+ "this should not have happened."
)

def environment_initialized(self) -> None:
# Tuple of (major, minor, patch)
vi = sys.version_info

msg = TrainingEnvironmentInitialized(
python_version=f"{vi[0]}.{vi[1]}.{vi[2]}",
mlagents_version="Custom",
mlagents_envs_version=mlagents_envs.__version__,
torch_version="Unknown",
torch_device_type="Unknown",
)
any_message = Any()
any_message.Pack(msg)

env_init_msg = OutgoingMessage()
env_init_msg.set_raw_bytes(any_message.SerializeToString()) # type: ignore
super().queue_message_to_send(env_init_msg)
14 changes: 9 additions & 5 deletions ml-agents/mlagents/training_analytics_side_channel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import sys
from typing import Optional
import uuid
import mlagents_envs
import mlagents.trainers
from mlagents import torch_utils
from mlagents.trainers.settings import RewardSignalType
from mlagents_envs.exception import UnityCommunicationException
from mlagents_envs.side_channel import SideChannel, IncomingMessage, OutgoingMessage
from mlagents_envs.side_channel import (
IncomingMessage,
OutgoingMessage,
DefaultTrainingAnalyticsSideChannel,
)
from mlagents_envs.communicator_objects.training_analytics_pb2 import (
TrainingEnvironmentInitialized,
TrainingBehaviorInitialized,
Expand All @@ -16,21 +19,22 @@
from mlagents.trainers.settings import TrainerSettings, RunOptions


class TrainingAnalyticsSideChannel(SideChannel):
class TrainingAnalyticsSideChannel(DefaultTrainingAnalyticsSideChannel):
"""
Side channel that sends information about the training to the Unity environment so it can be logged.
"""

def __init__(self) -> None:
# >>> uuid.uuid5(uuid.NAMESPACE_URL, "com.unity.ml-agents/TrainingAnalyticsSideChannel")
# UUID('b664a4a9-d86f-5a5f-95cb-e8353a7e8356')
super().__init__(uuid.UUID("b664a4a9-d86f-5a5f-95cb-e8353a7e8356"))
# Use the same uuid as the parent side channel
super().__init__()
self.run_options: Optional[RunOptions] = None

def on_message_received(self, msg: IncomingMessage) -> None:
raise UnityCommunicationException(
"The TrainingAnalyticsSideChannel received a message from Unity, "
+ "this should not have happened."
"this should not have happened."
)

def environment_initialized(self, run_options: RunOptions) -> None:
Expand Down
Loading