Develop side channels: migrate reset parameters#2990
Conversation
* 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
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
…ologies/ml-agents into develop-side-channel
…the UnityEnvironment
| SubprocessEnvManager.create_worker = MagicMock() | ||
| env = SubprocessEnvManager(mock_env_factory, 2) | ||
| env = SubprocessEnvManager( | ||
| mock_env_factory, EngineConfig(80, 80, 1, 20.0, -1), 2 |
There was a problem hiding this comment.
How about adding a .default_config() staticmethod to EngineConfig? (yes, you can do that to NamedTuples)
chriselion
left a comment
There was a problem hiding this comment.
Looks good! Can you make sure you update the docs:
- --slow removed and new command line args added
- Add note about CustomResetParameters removed in the Migration Guide
- anywhere else we mention the engine configuration? (maybe just https://github.com/Unity-Technologies/ml-agents/blob/develop/docs/Learning-Environment-Design-Academy.md#academy-properties ?)
But those can be in a subsequent PR.
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
properties
There are quite a few changes to the docs. I will make a PR to this branch with the docs edits and merge this afterwards. |
* Docs changes for the Side Channels feature * replace deprecated with removed on the CustomResetPratmeters` * Update docs/Python-API.md Co-Authored-By: Chris Elion <chris.elion@unity3d.com> * Update docs/Training-Generalized-Reinforcement-Learning-Agents.md Co-Authored-By: Chris Elion <chris.elion@unity3d.com> * Removing the console outputs in the docs * Update docs/Training-ML-Agents.md Co-Authored-By: Chris Elion <chris.elion@unity3d.com> * replace does not work with ignored * adding a note on side channels * adding some steps to migrate * addressing comments * adding more docs to the LL-API * added a blob on how to access the properties in C# * adding space between ResetParameters * fix typo
| public void SetLaserLengths() | ||
| { | ||
| m_LaserLength = m_MyAcademy.resetParameters.TryGetValue("laser_length", out m_LaserLength) ? m_LaserLength : 1.0f; | ||
| m_LaserLength = m_MyAcademy.FloatProperties.GetPropertyWithDefault("laser_length", 1.0f) * m_LaserLength; |
There was a problem hiding this comment.
I don't think you want * m_LaserLength here.
|
|
||
| if (Communicator != null) | ||
| { | ||
| Communicator.RegisterSideChannel(new EngineConfigurationChannel()); |
There was a problem hiding this comment.
Doesn't have to be in this PR, but we should think some more about how we expect users to register their own side channels. Might need a virtual call here that they can override.
There was a problem hiding this comment.
We could also go the route of having a side channel component (a little bit like what you did with the sensors)
There was a problem hiding this comment.
I like that idea, though if the academy won't be in the scene in the future, maybe that doesn't make sense. I'm not sure though.
| if (m_IsInference) | ||
| { | ||
| ConfigureEnvironmentHelper(m_InferenceConfiguration); | ||
| Monitor.SetActive(true); |
There was a problem hiding this comment.
I've never used the Monitor so I don't know much about it, but these were the only places we're calling SetActive on it. Do these calls need to be moved somewhere?
There was a problem hiding this comment.
The monitor is on by default now, regardless of wether we are training or not.
|
|
||
| parameters = self.data["parameters"] | ||
| for key in parameters: | ||
| if key not in default_reset_parameters: |
There was a problem hiding this comment.
Do we have a corresponding check (or at least warning) for this now?
There was a problem hiding this comment.
(at reset time, not init time)
There was a problem hiding this comment.
Unfortunately, the call on curriculum to get a configuration get_config(self, lesson=None) does not have the environment, or the reset_parameters as input. The curriculum does not have a way to check. I would put the check in FloatPropertiesSideChannel, but then I do not have a way to know if reset has been called on the environment yet.
There was a problem hiding this comment.
OK. Doesn't have to be in this PR, but I think we should consider the Academy declaring the properties it knows about, and complain (either on python or C#) if it gets a property it doesn't recognize.
| * `CustomResetParameters` are now removed. | ||
| * `reset()` on the Low-Level Python API no longer takes a `train_mode` argument. To modify the performance/speed of the engine, you must use an `EngineConfigurationChannel` | ||
| * `reset()` on the Low-Level Python API no longer takes a `config` argument. `UnityEnvironment` no longer has a `reset_parameters` field. To modify float properties in the environment, you must use a `FloatPropertiesChannel`. For more information, refer to the [Low Level Python API documentation](Python-API.md) | ||
| * The Academy no longer has a `Training Configuration` nor `Inference Configuration` field in the inspector. To modify the configuration form the Low-Level Python API, use an `EngineConfigurationChannel`. To modify it during training, use the new command line arguments `--width`, `--height`, `--quality-level`, `--time-scale` and `--target-frame-rate` in `mlagents-learn`. |
There was a problem hiding this comment.
nit: "To modify the configuration form from the Low-Level Python API"
|
|
||
| #### EngineConfigurationChannel | ||
| An `EngineConfigurationChannel` will allow you to modify how | ||
| fast and how accurate the Unity engine is. For example, modifying the |
There was a problem hiding this comment.
nit: Not sure accurate is the correct word here. Maybe
An EngineConfiguration will allow you to modify the time scale and graphics quality of the Unity engine.
Perhaps the second sentence is redundant.
TODO before merging
Documentation (Will do in another PR)
Feature changes :
One on the main breaking changes is that curriculum no longer checks if the reset parameters are in the environment (since parameters can now be added during the simulation)