- Python 3.8 is now the minimum version of python supported due to python3.6 EOL. Please update your python installation to 3.8.13 or higher.
- The
gym-unity
package has been refactored into theml-agents-envs
package. Please update your imports accordingly. - Example:
- Before
from gym_unity.unity_gym_env import UnityToGymWrapper
- After:
from mlagents_envs.envs.unity_gym_env import UnityToGymWrapper
- The official version of Unity ML-Agents supports is now 2021.3 LTS. If you run into issues, please consider deleting your project's Library folder and reponening your project.
- If you used any of the APIs that were deprecated before version 2.0, you need to use their replacement. These deprecated APIs have been removed. See the migration steps bellow for specific API replacements.
Deprecated API | Suggested Replacement |
---|---|
IActuator ActuatorComponent.CreateActuator() |
IActuator[] ActuatorComponent.CreateActuators() |
IActionReceiver.PackActions(in float[] destination) |
none |
Agent.CollectDiscreteActionMasks(DiscreteActionMasker actionMasker) |
Agent.WriteDiscreteActionMask(IDiscreteActionMask actionMask) |
Agent.Heuristic(float[] actionsOut) |
Agent.Heuristic(in ActionBuffers actionsOut) |
Agent.OnActionReceived(float[] vectorAction) |
Agent.OnActionReceived(ActionBuffers actions) |
Agent.GetAction() |
Agent.GetStoredActionBuffers() |
BrainParameters.SpaceType , VectorActionSize , VectorActionSpaceType , and NumActions |
BrainParameters.ActionSpec |
ObservationWriter.AddRange(IEnumerable<float> data, int writeOffset = 0) |
ObservationWriter. AddList(IList<float> data, int writeOffset = 0 |
SensorComponent.IsVisual() and IsVector() |
none |
VectorSensor.AddObservation(IEnumerable<float> observation) |
VectorSensor.AddObservation(IList<float> observation) |
SideChannelsManager |
SideChannelManager |
- The interface for disabling specific discrete actions has changed.
IDiscreteActionMask.WriteMask()
was removed, and replaced withSetActionEnabled()
. Instead of returning an IEnumerable with indices to disable, you can now callSetActionEnabled
for each index to disable (or enable). As an example, if you overrodeAgent.WriteDiscreteActionMask()
with something that looked like:
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
{
var branch = 2;
var actionsToDisable = new[] {1, 3};
actionMask.WriteMask(branch, actionsToDisable);
}
the equivalent code would now be
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
{
var branch = 2;
actionMask.SetActionEnabled(branch, 1, false);
actionMask.SetActionEnabled(branch, 3, false);
}
- The
IActuator
interface now implementsIHeuristicProvider
. Please add the correspondingHeuristic(in ActionBuffers)
method to your custom Actuator classes.
- The
ISensor.GetObservationShape()
method andITypedSensor
andIDimensionPropertiesSensor
interfaces were removed, andGetObservationSpec()
was added. You can useObservationSpec.Vector()
orObservationSpec.Visual()
to generateObservationSpec
s that are equivalent to the previous shape. For example, if your old ISensor looked like:
public override int[] GetObservationShape()
{
return new[] { m_Height, m_Width, m_NumChannels };
}
the equivalent code would now be
public override ObservationSpec GetObservationSpec()
{
return ObservationSpec.Visual(m_Height, m_Width, m_NumChannels);
}
- The
ISensor.GetCompressionType()
method andISparseChannelSensor
interface was removed, andGetCompressionSpec()
was added. You can useCompressionSpec.Default()
orCompressionSpec.Compressed()
to generateCompressionSpec
s that are equivalent to the previous values. For example, if your old ISensor looked like:
public virtual SensorCompressionType GetCompressionType()
{
return SensorCompressionType.None;
}
the equivalent code would now be
public CompressionSpec GetCompressionSpec()
{
return CompressionSpec.Default();
}
- The abstract method
SensorComponent.GetObservationShape()
was removed. - The abstract method
SensorComponent.CreateSensor()
was replaced withCreateSensors()
, which returns anISensor[]
.
The Match-3 integration utilities were moved from com.unity.ml-agents.extensions
to com.unity.ml-agents
.
The AbstractBoard
interface was changed:
AbstractBoard
no longer containsRows
,Columns
,NumCellTypes
, andNumSpecialTypes
fields.public abstract BoardSize GetMaxBoardSize()
was added as an abstract method.BoardSize
is a new struct that containsRows
,Columns
,NumCellTypes
, andNumSpecialTypes
fields, with the same meanings as the oldAbstractBoard
fields.public virtual BoardSize GetCurrentBoardSize()
is an optional method; by default it returnsGetMaxBoardSize()
. If you wish to use a single behavior to work with multiple board sizes, overrideGetCurrentBoardSize()
to return the currentBoardSize
. The values returned byGetCurrentBoardSize()
must be less than or equal to the corresponding values fromGetMaxBoardSize()
.
The sensor configuration has changed:
- The sensor implementation has been refactored and exsisting GridSensor created from extension package will not work in newer version. Some errors might show up when loading the old sensor in the scene. You'll need to remove the old sensor and create a new GridSensor.
- These parameters names have changed but still refer to the same concept in the sensor:
GridNumSide
->GridSize
,RotateToAgent
->RotateWithAgent
,ObserveMask
->ColliderMask
,DetectableObjects
->DetectableTags
DepthType
(ChanelBase
/ChannelHot
) option andChannelDepth
are removed. Now the default is one-hot encoding for detected tag. If you were using original GridSensor without overriding any method, switching to new GridSensor will produce similar effect for training although the actual observations will be slightly different.
For creating your GridSensor implementation with custom data:
- To create custom GridSensor, derive from
GridSensorBase
instead ofGridSensor
. Besides overridingGetObjectData()
, you will also need to consider overrideGetCellObservationSize()
,IsDataNormalized()
andGetProcessCollidersMethod()
according to the data you collect. Also you'll need to overrideGridSensorComponent.GetGridSensors()
and return your custom GridSensor. - The input argument
tagIndex
inGetObjectData()
has changed from 1-indexed to 0-indexed and the data type changed fromfloat
toint
. The index of first detectable tag will be 0 instead of 1.normalizedDistance
was removed from input. - The observation data should be written to the input
dataBuffer
instead of creating and returning a new array. - Removed the constraint of all data required to be normalized. You should specify it in
IsDataNormalized()
. Sensors with non-normalized data cannot use PNG compression type. - The sensor will not further encode the data recieved from
GetObjectData()
anymore. The values recieved fromGetObjectData()
will be the observation sent to the trainer.
The way the Unity Inference Engine processes LSTM (recurrent neural networks) has changed. As a result, models
trained with previous versions of ML-Agents will not be usable at inference if they were trained with a memory
setting in the .yaml
config file.
If you want to use a model that has a recurrent neural network in this release of ML-Agents, you need to train
the model using the python trainer from this release.
- If you have any custom actuators, you can now implement the
IHeuristicProvider
interface to have your actuator handle the generation of actions when an Agent is running in heuristic mode. VectorSensor.AddObservation(IEnumerable<float>)
is deprecated. UseVectorSensor.AddObservation(IList<float>)
instead.ObservationWriter.AddRange()
is deprecated. UseObservationWriter.AddList()
instead.ActuatorComponent.CreateAcuator()
is deprecated. Please use overrideActuatorComponent.CreateActuators
instead. SinceActuatorComponent.CreateActuator()
is abstract, you will still need to override it in your class until it is removed. It is only ever called if you don't overrideActuatorComponent.CreateActuators
. You can suppress the warnings by surrounding the method with the following pragma:#pragma warning disable 672 public IActuator CreateActuator() { ... } #pragma warning restore 672
Agent.CollectDiscreteActionMasks()
was deprecated and should be replaced withAgent.WriteDiscreteActionMask()
Agent.Heuristic(float[])
was deprecated and should be replaced withAgent.Heuristic(ActionBuffers)
.Agent.OnActionReceived(float[])
was deprecated and should be replaced withAgent.OnActionReceived(ActionBuffers)
.Agent.GetAction()
was deprecated and should be replaced withAgent.GetStoredActionBuffers()
.
The default implementation of these will continue to call the deprecated versions where appropriate. However, the deprecated versions may not be compatible with continuous and discrete actions on the same Agent.
BrainParameters.VectorActionSize
was deprecated; you can now setBrainParameters.ActionSpec.NumContinuousActions
orBrainParameters.ActionSpec.BranchSizes
instead.BrainParameters.VectorActionSpaceType
was deprecated, since both continuous and discrete actions can now be used.BrainParameters.NumActions()
was deprecated. UseBrainParameters.ActionSpec.NumContinuousActions
andBrainParameters.ActionSpec.NumDiscreteActions
instead.
- Some trainer files were moved. If you were using the
TrainerFactory
class, it was moved to thetrainers/trainer
folder. - The
components
folder containingbc
andreward_signals
code was moved to thetrainers/tf
folder
- Replace calls to
from mlagents.trainers.trainer_util import TrainerFactory
tofrom mlagents.trainers.trainer import TrainerFactory
- Replace calls to
from mlagents.trainers.trainer_util import handle_existing_directories
tofrom mlagents.trainers.directory_utils import validate_existing_directories
- Replace
mlagents.trainers.components
withmlagents.trainers.tf.components
in your import statements.
- The Parameter Randomization feature has been merged with the Curriculum feature. It is now possible to specify a sampler in the lesson of a Curriculum. Curriculum has been refactored and is now specified at the level of the parameter, not the behavior. More information here.(#4160)
- The configuration format for curriculum and parameter randomization has changed. To upgrade your configuration files,
an upgrade script has been provided. Run
python -m mlagents.trainers.upgrade_config -h
to see the script usage. Note that you will have had to upgrade to/install the current version of ML-Agents before running the script. To update manually:- If your config file used a
parameter_randomization
section, rename that section toenvironment_parameters
- If your config file used a
curriculum
section, you will need to rewrite your curriculum with this format.
- If your config file used a
- Training artifacts (trained models, summaries) are now found under
results/
instead ofsummaries/
andmodels/
. - Trainer configuration, curriculum configuration, and parameter randomization configuration have all been moved to a single YAML file. (#3791)
- Trainer configuration format has changed, and using a "default" behavior name has been deprecated. (#3936)
max_step
in theTerminalStep
andTerminalSteps
objects was renamedinterrupted
.- On the UnityEnvironment API,
get_behavior_names()
andget_behavior_specs()
methods were combined into the propertybehavior_specs
that contains a mapping from behavior names to behavior spec. use_visual
andallow_multiple_visual_obs
in theUnityToGymWrapper
constructor were replaced byallow_multiple_obs
which allows one or more visual observations and vector observations to be used simultaneously.--save-freq
has been removed from the CLI and is now configurable in the trainer configuration file.--lesson
has been removed from the CLI. Lessons will resume when using--resume
. To start at a different lesson, modify your Curriculum configuration.
-
To upgrade your configuration files, an upgrade script has been provided. Run
python -m mlagents.trainers.upgrade_config -h
to see the script usage. Note that you will have had to upgrade to/install the current version of ML-Agents before running the script.To do it manually, copy your
<BehaviorName>
sections fromtrainer_config.yaml
into a separate trainer configuration file, under abehaviors
section. Thedefault
section is no longer needed. This new file should be specific to your environment, and not contain configurations for multiple environments (unless they have the same Behavior Names).- You will need to reformat your trainer settings as per the example.
- If your training uses curriculum, move those configurations under a
curriculum
section. - If your training uses parameter randomization, move
the contents of the sampler config to
parameter_randomization
in the main trainer configuration.
-
If you are using
UnityEnvironment
directly, replacemax_step
withinterrupted
in theTerminalStep
andTerminalSteps
objects. -
Replace usage of
get_behavior_names()
andget_behavior_specs()
in UnityEnvironment withbehavior_specs
. -
If you use the
UnityToGymWrapper
, removeuse_visual
andallow_multiple_visual_obs
from the constructor and addallow_multiple_obs = True
if the environment contains either both visual and vector observations or multiple visual observations. -
If you were setting
--save-freq
in the CLI, add acheckpoint_interval
value in your trainer configuration, and set it equal tosave-freq * n_agents_in_scene
.
- The
MLAgents
C# namespace was renamed toUnity.MLAgents
, and other nested namespaces were similarly renamed (#3843). - The
--load
and--train
command-line flags have been deprecated and replaced with--resume
and--inference
. - Running with the same
--run-id
twice will now throw an error. - The
play_against_current_self_ratio
self-play trainer hyperparameter has been renamed toplay_against_latest_model_ratio
- Removed the multi-agent gym option from the gym wrapper. For multi-agent scenarios, use the Low Level Python API.
- The low level Python API has changed. You can look at the document
Low Level Python API documentation for more information. If
you use
mlagents-learn
for training, this should be a transparent change. - The obsolete
Agent
methodsGiveModel
,Done
,InitializeAgent
,AgentAction
andAgentReset
have been removed. - The signature of
Agent.Heuristic()
was changed to take afloat[]
as a parameter, instead of returning the array. This was done to prevent a common source of error where users would return arrays of the wrong size. - The SideChannel API has changed (#3833, #3660) :
- Introduced the
SideChannelManager
to register, unregister and access side channels. EnvironmentParameters
replaces the defaultFloatProperties
. You can access theEnvironmentParameters
withAcademy.Instance.EnvironmentParameters
on C#. If you were previously creating aUnityEnvironment
in python and passing it aFloatPropertiesChannel
, create anEnvironmentParametersChannel
instead.SideChannel.OnMessageReceived
is now a protected method (was public)- SideChannel IncomingMessages methods now take an optional default argument, which is used when trying to read more data than the message contains.
- Added a feature to allow sending stats from C# environments to TensorBoard
(and other python StatsWriters). To do this from your code, use
Academy.Instance.StatsRecorder.Add(key, value)
(#3660)
- Introduced the
num_updates
andtrain_interval
for SAC have been replaced withsteps_per_update
.- The
UnityEnv
class from thegym-unity
package was renamedUnityToGymWrapper
and no longer creates theUnityEnvironment
. Instead, theUnityEnvironment
must be passed as input to the constructor ofUnityToGymWrapper
- Public fields and properties on several classes were renamed to follow Unity's
C# style conventions. All public fields and properties now use "PascalCase"
instead of "camelCase"; for example,
Agent.maxStep
was renamed toAgent.MaxStep
. For a full list of changes, see the pull request. (#3828) WriteAdapter
was renamed toObservationWriter
. (#3834)
- In C# code, replace
using MLAgents
withusing Unity.MLAgents
. Replace other nested namespaces such asusing MLAgents.Sensors
withusing Unity.MLAgents.Sensors
- Replace the
--load
flag with--resume
when callingmlagents-learn
, and don't use the--train
flag as training will happen by default. To run without training, use--inference
. - To force-overwrite files from a pre-existing run, add the
--force
command-line flag. - The Jupyter notebooks have been removed from the repository.
- If your Agent class overrides
Heuristic()
, change the signature topublic override void Heuristic(float[] actionsOut)
and assign values toactionsOut
instead of returning an array. - If you used
SideChannels
you must:- Replace
Academy.FloatProperties
withAcademy.Instance.EnvironmentParameters
. Academy.RegisterSideChannel
andAcademy.UnregisterSideChannel
were removed. UseSideChannelManager.RegisterSideChannel
andSideChannelManager.UnregisterSideChannel
instead.
- Replace
- Set
steps_per_update
to be around equal to the number of agents in your environment, timesnum_updates
and divided bytrain_interval
. - Replace
UnityEnv
withUnityToGymWrapper
in your code. The constructor no longer takes a file name as input but a fully constructedUnityEnvironment
instead. - Update uses of "camelCase" fields and properties to "PascalCase".
- The
Agent.CollectObservations()
virtual method now takes as input aVectorSensor
sensor as argument. TheAgent.AddVectorObs()
methods were removed. - The
SetMask
was renamed toSetMask
method must now be called on theDiscreteActionMasker
argument of theCollectDiscreteActionMasks
virtual method. - We consolidated our API for
DiscreteActionMasker
.SetMask
takes two arguments : the branch index and the list of masked actions for that branch. - The
Monitor
class has been moved to the Examples Project. (It was prone to errors during testing) - The
MLAgents.Sensors
namespace has been introduced. All sensors classes are part of theMLAgents.Sensors
namespace. - The
MLAgents.SideChannels
namespace has been introduced. All side channel classes are part of theMLAgents.SideChannels
namespace. - The interface for
RayPerceptionSensor.PerceiveStatic()
was changed to take an input class and write to an output class, and the method was renamed toPerceive()
. - The
SetMask
method must now be called on theDiscreteActionMasker
argument of theCollectDiscreteActionMasks
method. - The method
GetStepCount()
on the Agent class has been replaced with the property getterStepCount
- The
--multi-gpu
option has been removed temporarily. AgentInfo.actionMasks
has been renamed toAgentInfo.discreteActionMasks
.BrainParameters
andSpaceType
have been removed from the public APIBehaviorParameters
have been removed from the public API.DecisionRequester
has been made internal (you can still use the DecisionRequesterComponent from the inspector).RepeatAction
was renamedTakeActionsBetweenDecisions
for clarity.- The following methods in the
Agent
class have been renamed. The original method names will be removed in a later release:InitializeAgent()
was renamed toInitialize()
AgentAction()
was renamed toOnActionReceived()
AgentReset()
was renamed toOnEpsiodeBegin()
Done()
was renamed toEndEpisode()
GiveModel()
was renamed toSetModel()
- The
IFloatProperties
interface has been removed. - The interface for SideChannels was changed:
- In C#,
OnMessageReceived
now takes aIncomingMessage
argument, andQueueMessageToSend
takes anOutgoingMessage
argument. - In python,
on_message_received
now takes aIncomingMessage
argument, andqueue_message_to_send
takes anOutgoingMessage
argument. - Automatic stepping for Academy is now controlled from the AutomaticSteppingEnabled property.
- In C#,
- Add the
using MLAgents.Sensors;
in addition tousing MLAgents;
on top of your Agent's script. - Replace your Agent's implementation of
CollectObservations()
withCollectObservations(VectorSensor sensor)
. In addition, replace all calls toAddVectorObs()
withsensor.AddObservation()
orsensor.AddOneHotObservation()
on theVectorSensor
passed as argument. - Replace your calls to
SetActionMask
on your Agent toDiscreteActionMasker.SetActionMask
inCollectDiscreteActionMasks
. - If you call
RayPerceptionSensor.PerceiveStatic()
manually, add your inputs to aRayPerceptionInput
. To get the previous float array output, iterate throughRayPerceptionOutput.rayOutputs
and callRayPerceptionOutput.RayOutput.ToFloatArray()
. - Replace all calls to
Agent.GetStepCount()
withAgent.StepCount
- We strongly recommend replacing the following methods with their new
equivalent as they will be removed in a later release:
InitializeAgent()
toInitialize()
AgentAction()
toOnActionReceived()
AgentReset()
toOnEpisodeBegin()
Done()
toEndEpisode()
GiveModel()
toSetModel()
- Replace
IFloatProperties
variables withFloatPropertiesChannel
variables. - If you implemented custom
SideChannels
, update the signatures of your methods, and add your data to theOutgoingMessage
or read it from theIncomingMessage
. - Replace calls to Academy.EnableAutomaticStepping()/DisableAutomaticStepping() with Academy.AutomaticSteppingEnabled = true/false.
- The
UnitySDK
folder has been split into a Unity Package (com.unity.ml-agents
) and an examples project (Project
). Please follow the Installation Guide to get up and running with this new repo structure. - Several changes were made to how agents are reset and marked as done:
- Calling
Done()
on the Agent will now reset it immediately and call theAgentReset
virtual method. (This is to simplify the previous logic in which the Agent had to wait for the nextEnvironmentStep
to reset) - The "Reset on Done" setting in AgentParameters was removed; this is now
effectively always true.
AgentOnDone
virtual method on the Agent has been removed.
- Calling
- The
Decision Period
andOn Demand decision
checkbox have been removed from the Agent. On demand decision is now the default (callingRequestDecision
on the Agent manually.) - The Academy class was changed to a singleton, and its virtual methods were removed.
- Trainer steps are now counted per-Agent, not per-environment as in previous versions. For instance, if you have 10 Agents in the scene, 20 environment steps now corresponds to 200 steps as printed in the terminal and in Tensorboard.
- Curriculum config files are now YAML formatted and all curricula for a training run are combined into a single file.
- The
--num-runs
command-line option has been removed frommlagents-learn
. - Several fields on the Agent were removed or made private in order to simplify
the interface.
- The
agentParameters
field of the Agent has been removed. (Contained onlymaxStep
information) maxStep
is now a public field on the Agent. (Was moved fromagentParameters
)- The
Info
field of the Agent has been made private. (Was only used internally and not meant to be modified outside of the Agent) - The
GetReward()
method on the Agent has been removed. (It was being confused withGetCumulativeReward()
) - The
AgentAction
struct no longer contains avalue
field. (Value estimates were not set during inference) - The
GetValueEstimate()
method on the Agent has been removed. - The
UpdateValueAction()
method on the Agent has been removed.
- The
- The deprecated
RayPerception3D
andRayPerception2D
classes were removed, and thelegacyHitFractionBehavior
argument was removed fromRayPerceptionSensor.PerceiveStatic()
. - RayPerceptionSensor was inconsistent in how it handle scale on the Agent's transform. It now scales the ray length and sphere size for casting as the transform's scale changes.
- Follow the instructions on how to install the
com.unity.ml-agents
package into your project in the Installation Guide. - If your Agent implemented
AgentOnDone
and did not have the checkboxReset On Done
checked in the inspector, you must call the code that was inAgentOnDone
manually. - If you give your Agent a reward or penalty at the end of an episode (e.g. for
reaching a goal or falling off of a platform), make sure you call
AddReward()
orSetReward()
before callingDone()
. Previously, the order didn't matter. - If you were not using
On Demand Decision
for your Agent, you must add aDecisionRequester
component to your Agent GameObject and set itsDecision Period
field to the oldDecision Period
of the Agent. - If you have a class that inherits from Academy:
- If the class didn't override any of the virtual methods and didn't store any additional data, you can just remove the old script from the scene.
- If the class had additional data, create a new MonoBehaviour and store the data in the new MonoBehaviour instead.
- If the class overrode the virtual methods, create a new MonoBehaviour and
move the logic to it:
- Move the InitializeAcademy code to MonoBehaviour.Awake
- Move the AcademyStep code to MonoBehaviour.FixedUpdate
- Move the OnDestroy code to MonoBehaviour.OnDestroy.
- Move the AcademyReset code to a new method and add it to the Academy.OnEnvironmentReset action.
- Multiply
max_steps
andsummary_freq
in yourtrainer_config.yaml
by the number of Agents in the scene. - Combine curriculum configs into a single file. See the WallJump curricula for an example of the new curriculum config format. A tool like https://www.json2yaml.com may be useful to help with the conversion.
- If you have a model trained which uses RayPerceptionSensor and has non-1.0 scale in the Agent's transform, it must be retrained.
- The low level Python API has changed. You can look at the document
Low Level Python API documentation for more information. This
should only affect you if you're writing a custom trainer; if you use
mlagents-learn
for training, this should be a transparent change.reset()
on the Low-Level Python API no longer takes atrain_mode
argument. To modify the performance/speed of the engine, you must use anEngineConfigurationChannel
reset()
on the Low-Level Python API no longer takes aconfig
argument.UnityEnvironment
no longer has areset_parameters
field. To modify float properties in the environment, you must use aFloatPropertiesChannel
. For more information, refer to the Low Level Python API documentation
CustomResetParameters
are now removed.- The Academy no longer has a
Training Configuration
norInference Configuration
field in the inspector. To modify the configuration from the Low-Level Python API, use anEngineConfigurationChannel
. To modify it during training, use the new command line arguments--width
,--height
,--quality-level
,--time-scale
and--target-frame-rate
inmlagents-learn
. - The Academy no longer has a
Default Reset Parameters
field in the inspector. The Academy class no longer has aResetParameters
. To access shared float properties with Python, use the newFloatProperties
field on the Academy. - Offline Behavioral Cloning has been removed. To learn from demonstrations, use the GAIL and Behavioral Cloning features with either PPO or SAC.
mlagents.envs
was renamed tomlagents_envs
. The previous repo layout depended on PEP420, which caused problems with some of our tooling such as mypy and pylint.- The official version of Unity ML-Agents supports is now 2018.4 LTS. If you run into issues, please consider deleting your library folder and reponening your projects. You will need to install the Barracuda package into your project in order to ML-Agents to compile correctly.
- If you had a custom
Training Configuration
in the Academy inspector, you will need to pass your custom configuration at every training run using the new command line arguments--width
,--height
,--quality-level
,--time-scale
and--target-frame-rate
. - If you were using
--slow
inmlagents-learn
, you will need to pass your oldInference Configuration
of the Academy inspector with the new command line arguments--width
,--height
,--quality-level
,--time-scale
and--target-frame-rate
instead. - Any imports from
mlagents.envs
should be replaced withmlagents_envs
.
- Text actions and observations, and custom action and observation protos have been removed.
- RayPerception3D and RayPerception2D are marked deprecated, and will be removed in a future release. They can be replaced by RayPerceptionSensorComponent3D and RayPerceptionSensorComponent2D.
- The
Use Heuristic
checkbox in Behavior Parameters has been replaced with aBehavior Type
dropdown menu. This has the following options:Default
corresponds to the previous unchecked behavior, meaning that Agents will train if they connect to a python trainer, otherwise they will perform inference.Heuristic Only
means the Agent will always use theHeuristic()
method. This corresponds to having "Use Heuristic" selected in 0.11.0.Inference Only
means the Agent will always perform inference.
- Barracuda was upgraded to 0.3.2, and it is now installed via the Unity Package Manager.
- We fixed a bug in
RayPerception3d.Perceive()
that was causing theendOffset
to be used incorrectly. However this may produce different behavior from previous versions if you use a non-zerostartOffset
. To reproduce the old behavior, you should increase the value ofendOffset
bystartOffset
. You can verify your raycasts are performing as expected in scene view using the debug rays. - If you use RayPerception3D, replace it with RayPerceptionSensorComponent3D
(and similarly for 2D). The settings, such as ray angles and detectable tags,
are configured on the component now. RayPerception3D would contribute
(# of rays) * (# of tags + 2)
to the State Size in Behavior Parameters, but this is no longer necessary, so you should reduce the State Size by this amount. Making this change will require retraining your model, since the observations that RayPerceptionSensorComponent3D produces are different from the old behavior. - If you see messages such as
The type or namespace 'Barracuda' could not be found
orThe type or namespace 'Google' could not be found
, you will need to install the Barracuda preview package.
- The definition of the gRPC service has changed.
- The online BC training feature has been removed.
- The BroadcastHub has been deprecated. If there is a training Python process, all LearningBrains in the scene will automatically be trained. If there is no Python process, inference will be used.
- The Brain ScriptableObjects have been deprecated. The Brain Parameters are now on the Agent and are referred to as Behavior Parameters. Make sure the Behavior Parameters is attached to the Agent GameObject.
- To use a heuristic behavior, implement the
Heuristic()
method in the Agent class and check theuse heuristic
checkbox in the Behavior Parameters. - Several changes were made to the setup for visual observations (i.e. using
Cameras or RenderTextures):
- Camera resolutions are no longer stored in the Brain Parameters.
- AgentParameters no longer stores lists of Cameras and RenderTextures
- To add visual observations to an Agent, you must now attach a CameraSensorComponent or RenderTextureComponent to the agent. The corresponding Camera or RenderTexture can be added to these in the editor, and the resolution and color/grayscale is configured on the component itself.
- In order to be able to train, make sure both your ML-Agents Python package and UnitySDK code come from the v0.11 release. Training will not work, for example, if you update the ML-Agents Python package, and only update the API Version in UnitySDK.
- If your Agents used visual observations, you must add a CameraSensorComponent corresponding to each old Camera in the Agent's camera list (and similarly for RenderTextures).
- Since Brain ScriptableObjects have been removed, you will need to delete all
the Brain ScriptableObjects from your
Assets
folder. Then, add aBehavior Parameters
component to eachAgent
GameObject. You will then need to complete the fields on the newBehavior Parameters
component with the BrainParameters of the old Brain.
- We have updated the C# code in our repository to be in line with Unity Coding Conventions. This has changed the name of some public facing classes and enums.
- The example environments have been updated. If you were using these environments to benchmark your training, please note that the resulting rewards may be slightly different in v0.10.
UnitySDK/Assets/ML-Agents/Scripts/Communicator.cs
and its classCommunicator
have been renamed toUnitySDK/Assets/ML-Agents/Scripts/ICommunicator.cs
andICommunicator
respectively.- The
SpaceType
Enumsdiscrete
, andcontinuous
have been renamed toDiscrete
andContinuous
. - We have removed the
Done
call as well as the capacity to setMax Steps
on the Academy. Therefore an AcademyReset will never be triggered from C# (only from Python). If you want to reset the simulation after a fixed number of steps, or when an event in the simulation occurs, we recommend looking at our multi-agent example environments (such as FoodCollector). In our examples, groups of Agents can be reset through an "Area" that can reset groups of Agents. - The import for
mlagents.envs.UnityEnvironment
was removed. If you are using the Python API, changefrom mlagents_envs import UnityEnvironment
tofrom mlagents_envs.environment import UnityEnvironment
.
- We have changed the way reward signals (including Curiosity) are defined in
the
trainer_config.yaml
. - When using multiple environments, every "step" is recorded in TensorBoard.
- The steps in the command line console corresponds to a single step of a single
environment. Previously, each step corresponded to one step for all
environments (i.e.,
num_envs
steps).
- If you were overriding any of these following parameters in your config file,
remove them from the top-level config and follow the steps below:
gamma
: Define a newextrinsic
reward signal and set it'sgamma
to your new gamma.use_curiosity
,curiosity_strength
,curiosity_enc_size
: Define acuriosity
reward signal and set itsstrength
tocuriosity_strength
, andencoding_size
tocuriosity_enc_size
. Give it the samegamma
as yourextrinsic
signal to mimic previous behavior.
- TensorBoards generated when running multiple environments in v0.8 are not
comparable to those generated in v0.9 in terms of step count. Multiply your
v0.8 step count by
num_envs
for an approximate comparison. You may need to changemax_steps
in your config as appropriate as well.
- We have split the Python packages into two separate packages
ml-agents
andml-agents-envs
. --worker-id
option oflearn.py
has been removed, use--base-port
instead if you'd like to run multiple instances oflearn.py
.
- If you are installing via PyPI, there is no change.
- If you intend to make modifications to
ml-agents
orml-agents-envs
please check the Installing for Development in the Installation documentation.
- We no longer support TFS and are now using the Unity Inference Engine
- Make sure to remove the
ENABLE_TENSORFLOW
flag in your Unity Project settings
-
Brains are now Scriptable Objects instead of MonoBehaviors.
-
You can no longer modify the type of a Brain. If you want to switch between
PlayerBrain
andLearningBrain
for multiple agents, you will need to assign a new Brain to each agent separately. Note: You can pass the same Brain to multiple agents in a scene by leveraging Unity's prefab system or look for all the agents in a scene using the search bar of theHierarchy
window with the wordAgent
. -
We replaced the Internal and External Brain with Learning Brain. When you need to train a model, you need to drag it into the
Broadcast Hub
inside theAcademy
and check theControl
checkbox. -
We removed the
Broadcast
checkbox of the Brain, to use the broadcast functionality, you need to drag the Brain into theBroadcast Hub
. -
When training multiple Brains at the same time, each model is now stored into a separate model file rather than in the same file under different graph scopes.
-
The Learning Brain graph scope, placeholder names, output names and custom placeholders can no longer be modified.
- To update a scene from v0.5 to v0.6, you must:
- Remove the
Brain
GameObjects in the scene. (Delete all of the Brain GameObjects under Academy in the scene.) - Create new
Brain
Scriptable Objects usingAssets -> Create -> ML-Agents
for each type of the Brain you plan to use, and put the created files under a folder called Brains within your project. - Edit their
Brain Parameters
to be the same as the parameters used in theBrain
GameObjects. - Agents have a
Brain
field in the Inspector, you need to drag the appropriate Brain ScriptableObject in it. - The Academy has a
Broadcast Hub
field in the inspector, which is list of brains used in the scene. To train or control your Brain from themlagents-learn
Python script, you need to drag the relevantLearningBrain
ScriptableObjects used in your scene into entries into this list.
- Remove the
- The Unity project
unity-environment
has been renamedUnitySDK
. - The
python
folder has been renamed toml-agents
. It now contains two packages,mlagents.env
andmlagents.trainers
.mlagents.env
can be used to interact directly with a Unity environment, whilemlagents.trainers
contains the classes for training agents. - The supported Unity version has changed from
2017.1 or later
to2017.4 or later
. 2017.4 is an LTS (Long Term Support) version that helps us maintain good quality and support. Earlier versions of Unity might still work, but you may encounter an error listed here.
- Discrete Actions now use branches. You can now specify concurrent discrete actions. You will need to update the Brain Parameters in the Brain Inspector in all your environments that use discrete actions. Refer to the discrete action documentation for more information.
-
In order to run a training session, you can now use the command
mlagents-learn
instead ofpython3 learn.py
after installing themlagents
packages. This change is documented here. For example, if we previously ranpython3 learn.py 3DBall --train
from the
python
subdirectory (which is changed toml-agents
subdirectory in v0.5), we now runmlagents-learn config/trainer_config.yaml --env=3DBall --train
from the root directory where we installed the ML-Agents Toolkit.
-
It is now required to specify the path to the yaml trainer configuration file when running
mlagents-learn
. For an example trainer configuration file, see trainer_config.yaml. An example of passing a trainer configuration tomlagents-learn
is shown above. -
The environment name is now passed through the
--env
option. -
Curriculum learning has been changed. In summary:
- Curriculum files for the same environment must now be placed into a folder. Each curriculum file should be named after the Brain whose curriculum it specifies.
min_lesson_length
now specifies the minimum number of episodes in a lesson and affects reward thresholding.- It is no longer necessary to specify the
Max Steps
of the Academy to use curriculum learning.
using MLAgents;
needs to be added in all of the C# scripts that use ML-Agents.
- We've changed some of the Python packages dependencies in requirement.txt
file. Make sure to run
pip3 install -e .
within yourml-agents/python
folder to update your Python packages.
There are a large number of new features and improvements in the ML-Agents toolkit v0.3 which change both the training process and Unity API in ways which will cause incompatibilities with environments made using older versions. This page is designed to highlight those changes for users familiar with v0.1 or v0.2 in order to ensure a smooth transition.
- The ML-Agents Toolkit is no longer compatible with Python 2.
- The training script
ppo.py
andPPO.ipynb
Python notebook have been replaced with a singlelearn.py
script as the launching point for training with ML-Agents. For more information on usinglearn.py
, see here. - Hyperparameters for training Brains are now stored in the
trainer_config.yaml
file. For more information on using this file, see here.
- Modifications to an Agent's rewards must now be done using either
AddReward()
orSetReward()
. - Setting an Agent to done now requires the use of the
Done()
method. CollectStates()
has been replaced byCollectObservations()
, which now no longer returns a list of floats.- To collect observations, call
AddVectorObs()
withinCollectObservations()
. Note that you can callAddVectorObs()
with floats, integers, lists and arrays of floats, Vector3 and Quaternions. AgentStep()
has been replaced byAgentAction()
.WaitTime()
has been removed.- The
Frame Skip
field of the Academy is replaced by the Agent'sDecision Frequency
field, enabling the Agent to make decisions at different frequencies. - The names of the inputs in the Internal Brain have been changed. You must
replace
state
withvector_observation
andobservation
withvisual_observation
. In addition, you must remove theepsilon
placeholder.
In order to more closely align with the terminology used in the Reinforcement Learning field, and to be more descriptive, we have changed the names of some of the concepts used in ML-Agents. The changes are highlighted in the table below.
Old - v0.2 and earlier | New - v0.3 and later |
---|---|
State | Vector Observation |
Observation | Visual Observation |
Action | Vector Action |
N/A | Text Observation |
N/A | Text Action |