Skip to content

Develop side channel #2956

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

Merged
merged 26 commits into from
Nov 26, 2019
Merged

Develop side channel #2956

merged 26 commits into from
Nov 26, 2019

Conversation

vincentpierre
Copy link
Contributor

@vincentpierre vincentpierre commented Nov 22, 2019

This is the first draft for what is in this document

This PR contains code additions for side channels, tests and code comments but does not have documentation and are not being used by training (the old system is still working)
I would like to get this PR in and then make another with deprecation of the current way to do reset parameters and engine config and the documentation changes.

@vincentpierre vincentpierre self-assigned this Nov 22, 2019
@chriselion chriselion requested a review from surfnerd November 22, 2019 23:52
* Added the side channel for the Engine Configuration.

Note that this change does not require modifying a lot of files :
 - Adding a sender in Python
 - Adding a receiver in C#
 - subscribe the receiver to the communicator (here is a one liner in the Academy)
 - Add the side channel to the Python UnityEnvironment (not represented here)

Adding the side channel to the environment would look like such :

```python
from mlagents.envs.environment import UnityEnvironment
from mlagents.envs.side_channel.raw_bytes_channel import RawBytesChannel
from mlagents.envs.side_channel.engine_configuration_channel import EngineConfigurationChannel

channel0 = RawBytesChannel()
channel1 = EngineConfigurationChannel()

env = UnityEnvironment(base_port = 5004, side_channels = [channel0, channel1])
```

* renamings

* addressing comments
var message = binaryReader.ReadBytes(messageLength);
if (sideChannels.ContainsKey(channelType))
{
sideChannels[channelType].OnMessageReceived(message);
Copy link
Contributor

@chriselion chriselion Nov 25, 2019

Choose a reason for hiding this comment

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

I still think a separate try/catch around here is a good idea; it will help distinguish between errors in the message stream (which we're handling below) and errors in the OnMessageReceived() implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not want to mask an error a user has in its own implementation of a side channel.

+ "compatible with the Python version."
)
if channel_type in self.side_channels_dict:
self.side_channels_dict[channel_type].on_message_received(message_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as C# side, wrap this in a try/except.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment, I think we need to raise these errors as they are for the user that made its own side channels.

@chriselion
Copy link
Contributor

Overall looks good, could just use some python unit tests.

@vincentpierre vincentpierre marked this pull request as ready for review November 26, 2019 20:11
@vincentpierre vincentpierre changed the title [WIP] Develop side channel Develop side channel Nov 26, 2019
@vincentpierre
Copy link
Contributor Author

This PR contains code additions for side channels, tests and code comments but does not have documentation and are not being used by training (the old system is still working)
I would like to get this PR in and then make another with deprecation of the current way to do reset parameters and engine config and the documentation changes.

Comment on lines 80 to 81
QueueMessageToSend(SerializeMessage(key, defaultValue));
m_FloatProperties[key] = defaultValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

This would surprise me as a user - Get* shouldn't generally have a side effect. I think you should have a SetProperty that calls QueueMessageToSend and sets the Dict value

Copy link
Contributor

Choose a reason for hiding this comment

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

(sorry if I missed that in the other PR)

public enum SideChannelType
{
// Reserved for the FloatPropertiesChannel.
FloatProperties = 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a 0 value for "invalid"?

Comment on lines 48 to 51
if key in self._float_properties:
return self._float_properties[key]
else:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just do self._float_properties.get(key) - that returns None if the key isn't in the dict.

@chriselion
Copy link
Contributor

Looks great. Definitely OK to merge this, and hook it in later.

@vincentpierre vincentpierre merged commit bc1acaf into develop Nov 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the develop-side-channel branch November 26, 2019 23:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants