Skip to content

Commit 5b9b8ff

Browse files
Making some fields and properties internal (#3342)
* Making some fields and properties internal * Fixing the formating * Making more things internal * Adressing the comments * reverting the changes made to the recorder * WriteAdapter public * Have to make AgentInfo and TensorProxy public because of changes to write adapter and the demorecorder
1 parent b3657f4 commit 5b9b8ff

26 files changed

+84
-77
lines changed

com.unity.ml-agents/Runtime/Academy.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace MLAgents
2525
/// <summary>
2626
/// Helper class to step the Academy during FixedUpdate phase.
2727
/// </summary>
28-
public class AcademyFixedUpdateStepper : MonoBehaviour
28+
internal class AcademyFixedUpdateStepper : MonoBehaviour
2929
{
3030
void FixedUpdate()
3131
{
@@ -92,7 +92,7 @@ public bool IsCommunicatorOn
9292
int m_TotalStepCount;
9393

9494
/// Pointer to the communicator currently in use by the Academy.
95-
public ICommunicator Communicator;
95+
internal ICommunicator Communicator;
9696

9797
bool m_Initialized;
9898
List<ModelRunner> m_ModelRunners = new List<ModelRunner>();
@@ -108,27 +108,27 @@ public bool IsCommunicatorOn
108108

109109
// Signals to all the Agents at each environment step so they can use
110110
// their Policy to decide on their next action.
111-
public event System.Action DecideAction;
111+
internal event System.Action DecideAction;
112112

113113
// Signals to all the listeners that the academy is being destroyed
114-
public event System.Action DestroyAction;
114+
internal event System.Action DestroyAction;
115115

116116
// Signals to all the agents at each environment step along with the
117117
// Academy's maxStepReached, done and stepCount values. The agents rely
118118
// on this event to update their own values of max step reached and done
119119
// in addition to aligning on the step count of the global episode.
120-
public event System.Action<int> AgentSetStatus;
120+
internal event System.Action<int> AgentSetStatus;
121121

122122
// Signals to all the agents at each environment step so they can send
123123
// their state to their Policy if they have requested a decision.
124-
public event System.Action AgentSendState;
124+
internal event System.Action AgentSendState;
125125

126126
// Signals to all the agents at each environment step so they can act if
127127
// they have requested a decision.
128-
public event System.Action AgentAct;
128+
internal event System.Action AgentAct;
129129

130130
// Signals to all the agents each time the Academy force resets.
131-
public event System.Action AgentForceReset;
131+
internal event System.Action AgentForceReset;
132132

133133
// Signals that the Academy has been reset by the training process
134134
public event System.Action OnEnvironmentReset;
@@ -154,7 +154,7 @@ public bool IsCommunicatorOn
154154
/// Initialize the Academy if it hasn't already been initialized.
155155
/// This method is always safe to call; it will have no effect if the Academy is already initialized.
156156
/// </summary>
157-
public void LazyInitialization()
157+
internal void LazyInitialization()
158158
{
159159
if (!m_Initialized)
160160
{
@@ -426,7 +426,7 @@ void EnvironmentReset()
426426
/// <param name="inferenceDevice"> The inference device (CPU or GPU)
427427
/// the ModelRunner will use </param>
428428
/// <returns> The ModelRunner compatible with the input settings</returns>
429-
public ModelRunner GetOrCreateModelRunner(
429+
internal ModelRunner GetOrCreateModelRunner(
430430
NNModel model, BrainParameters brainParameters, InferenceDevice inferenceDevice)
431431
{
432432
var modelRunner = m_ModelRunners.Find(x => x.HasModel(model, inferenceDevice));

com.unity.ml-agents/Runtime/ActionMasker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace MLAgents
66
{
7-
public class ActionMasker
7+
internal class ActionMasker
88
{
99
/// When using discrete control, is the starting indices of the actions
1010
/// when all the branches are concatenated with each other.

com.unity.ml-agents/Runtime/Agent.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public struct AgentInfo
5050
/// Struct that contains the action information sent from the Brain to the
5151
/// Agent.
5252
/// </summary>
53-
public struct AgentAction
53+
internal struct AgentAction
5454
{
5555
public float[] vectorActions;
5656
}
@@ -174,12 +174,12 @@ public abstract class Agent : MonoBehaviour
174174
/// Currently generated from attached SensorComponents, and a legacy VectorSensor
175175
/// </summary>
176176
[FormerlySerializedAs("m_Sensors")]
177-
public List<ISensor> sensors;
177+
internal List<ISensor> sensors;
178178

179179
/// <summary>
180180
/// VectorSensor which is written to by AddVectorObs
181181
/// </summary>
182-
public VectorSensor collectObservationsSensor;
182+
internal VectorSensor collectObservationsSensor;
183183

184184
/// MonoBehaviour function that is called when the attached GameObject
185185
/// becomes enabled or active.
@@ -420,7 +420,7 @@ public virtual float[] Heuristic()
420420
/// Set up the list of ISensors on the Agent. By default, this will select any
421421
/// SensorBase's attached to the Agent.
422422
/// </summary>
423-
public void InitializeSensors()
423+
internal void InitializeSensors()
424424
{
425425
// Get all attached sensor components
426426
SensorComponent[] attachedSensorComponents;
@@ -710,20 +710,11 @@ void _AgentReset()
710710
AgentReset();
711711
}
712712

713-
public void UpdateAgentAction(AgentAction action)
713+
internal void UpdateAgentAction(AgentAction action)
714714
{
715715
m_Action = action;
716716
}
717717

718-
/// <summary>
719-
/// Updates the vector action.
720-
/// </summary>
721-
/// <param name="vectorActions">Vector actions.</param>
722-
public void UpdateVectorAction(float[] vectorActions)
723-
{
724-
m_Action.vectorActions = vectorActions;
725-
}
726-
727718
/// <summary>
728719
/// Scales continuous action from [-1, 1] to arbitrary range.
729720
/// </summary>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor.Tests")]
4+
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor")]

com.unity.ml-agents/Runtime/AssemblyInfo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.ml-agents/Runtime/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace MLAgents
33
/// <summary>
44
/// Grouping for use in AddComponentMenu (instead of nesting the menus).
55
/// </summary>
6-
public enum MenuGroup
6+
internal enum MenuGroup
77
{
88
Default = 0,
99
Sensors = 50

com.unity.ml-agents/Runtime/EpisodeIdCounter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace MLAgents
22
{
3-
public static class EpisodeIdCounter
3+
internal static class EpisodeIdCounter
44
{
55
private static int Counter;
66
public static int GetEpisodeId()

com.unity.ml-agents/Runtime/Grpc/GrpcExtensions.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
namespace MLAgents
1515
{
16-
public static class GrpcExtensions
16+
internal static class GrpcExtensions
1717
{
1818
/// <summary>
1919
/// Converts a AgentInfo to a protobuf generated AgentInfoActionPairProto
2020
/// </summary>
2121
/// <returns>The protobuf version of the AgentInfoActionPairProto.</returns>
22-
internal static AgentInfoActionPairProto ToInfoActionPairProto(this AgentInfo ai)
22+
public static AgentInfoActionPairProto ToInfoActionPairProto(this AgentInfo ai)
2323
{
2424
var agentInfoProto = ai.ToAgentInfoProto();
2525

@@ -39,7 +39,7 @@ internal static AgentInfoActionPairProto ToInfoActionPairProto(this AgentInfo ai
3939
/// Converts a AgentInfo to a protobuf generated AgentInfoProto
4040
/// </summary>
4141
/// <returns>The protobuf version of the AgentInfo.</returns>
42-
internal static AgentInfoProto ToAgentInfoProto(this AgentInfo ai)
42+
public static AgentInfoProto ToAgentInfoProto(this AgentInfo ai)
4343
{
4444
var agentInfoProto = new AgentInfoProto
4545
{
@@ -64,7 +64,7 @@ internal static AgentInfoProto ToAgentInfoProto(this AgentInfo ai)
6464
/// <param name="bp">The instance of BrainParameter to extend.</param>
6565
/// <param name="name">The name of the brain.</param>
6666
/// <param name="isTraining">Whether or not the Brain is training.</param>
67-
internal static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining)
67+
public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining)
6868
{
6969
var brainParametersProto = new BrainParametersProto
7070
{
@@ -81,7 +81,7 @@ internal static BrainParametersProto ToProto(this BrainParameters bp, string nam
8181
/// <summary>
8282
/// Convert metadata object to proto object.
8383
/// </summary>
84-
internal static DemonstrationMetaProto ToProto(this DemonstrationMetaData dm)
84+
public static DemonstrationMetaProto ToProto(this DemonstrationMetaData dm)
8585
{
8686
var demoProto = new DemonstrationMetaProto
8787
{
@@ -97,7 +97,7 @@ internal static DemonstrationMetaProto ToProto(this DemonstrationMetaData dm)
9797
/// <summary>
9898
/// Initialize metadata values based on proto object.
9999
/// </summary>
100-
internal static DemonstrationMetaData ToDemonstrationMetaData(this DemonstrationMetaProto demoProto)
100+
public static DemonstrationMetaData ToDemonstrationMetaData(this DemonstrationMetaProto demoProto)
101101
{
102102
var dm = new DemonstrationMetaData
103103
{
@@ -118,7 +118,7 @@ internal static DemonstrationMetaData ToDemonstrationMetaData(this Demonstration
118118
/// </summary>
119119
/// <param name="bpp">An instance of a brain parameters protobuf object.</param>
120120
/// <returns>A BrainParameters struct.</returns>
121-
internal static BrainParameters ToBrainParameters(this BrainParametersProto bpp)
121+
public static BrainParameters ToBrainParameters(this BrainParametersProto bpp)
122122
{
123123
var bp = new BrainParameters
124124
{
@@ -129,23 +129,23 @@ internal static BrainParameters ToBrainParameters(this BrainParametersProto bpp)
129129
return bp;
130130
}
131131

132-
internal static UnityRLInitParameters ToUnityRLInitParameters(this UnityRLInitializationInputProto inputProto)
132+
public static UnityRLInitParameters ToUnityRLInitParameters(this UnityRLInitializationInputProto inputProto)
133133
{
134134
return new UnityRLInitParameters
135135
{
136136
seed = inputProto.Seed
137137
};
138138
}
139139

140-
internal static AgentAction ToAgentAction(this AgentActionProto aap)
140+
public static AgentAction ToAgentAction(this AgentActionProto aap)
141141
{
142142
return new AgentAction
143143
{
144144
vectorActions = aap.VectorActions.ToArray()
145145
};
146146
}
147147

148-
internal static List<AgentAction> ToAgentActionList(this UnityRLInputProto.Types.ListAgentActionProto proto)
148+
public static List<AgentAction> ToAgentActionList(this UnityRLInputProto.Types.ListAgentActionProto proto)
149149
{
150150
var agentActions = new List<AgentAction>(proto.Value.Count);
151151
foreach (var ap in proto.Value)
@@ -155,7 +155,7 @@ internal static List<AgentAction> ToAgentActionList(this UnityRLInputProto.Types
155155
return agentActions;
156156
}
157157

158-
internal static ObservationProto ToProto(this Observation obs)
158+
public static ObservationProto ToProto(this Observation obs)
159159
{
160160
ObservationProto obsProto = null;
161161

@@ -199,7 +199,7 @@ internal static ObservationProto ToProto(this Observation obs)
199199
/// <param name="sensor"></param>
200200
/// <param name="writeAdapter"></param>
201201
/// <returns></returns>
202-
internal static ObservationProto GetObservationProto(this ISensor sensor, WriteAdapter writeAdapter)
202+
public static ObservationProto GetObservationProto(this ISensor sensor, WriteAdapter writeAdapter)
203203
{
204204
var shape = sensor.GetObservationShape();
205205
ObservationProto observationProto = null;

com.unity.ml-agents/Runtime/Grpc/RpcCommunicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace MLAgents
1717
{
1818
/// Responsible for communication with External using gRPC.
19-
public class RpcCommunicator : ICommunicator
19+
internal class RpcCommunicator : ICommunicator
2020
{
2121
public event QuitCommandHandler QuitCommandReceived;
2222
public event ResetCommandHandler ResetCommandReceived;

com.unity.ml-agents/Runtime/ICommunicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Since the messages are sent back and forth with exchange and simultaneously when
8989
UnityOutput and UnityInput can be extended to provide functionalities beyond RL
9090
UnityRLOutput and UnityRLInput can be extended to provide new RL functionalities
9191
*/
92-
public interface ICommunicator : IDisposable
92+
internal interface ICommunicator : IDisposable
9393
{
9494
/// <summary>
9595
/// Quit was received by the communicator.

com.unity.ml-agents/Runtime/InferenceBrain/ApplierImpl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MLAgents.InferenceBrain
1111
/// The Applier for the Continuous Action output tensor. Tensor is assumed to contain the
1212
/// continuous action data of the agents in the batch.
1313
/// </summary>
14-
public class ContinuousActionOutputApplier : TensorApplier.IApplier
14+
internal class ContinuousActionOutputApplier : TensorApplier.IApplier
1515
{
1616
public void Apply(TensorProxy tensorProxy, IEnumerable<int> actionIds, Dictionary<int, float[]> lastActions)
1717
{
@@ -42,7 +42,7 @@ public void Apply(TensorProxy tensorProxy, IEnumerable<int> actionIds, Dictionar
4242
/// The Applier for the Discrete Action output tensor. Uses multinomial to sample discrete
4343
/// actions from the logits contained in the tensor.
4444
/// </summary>
45-
public class DiscreteActionOutputApplier : TensorApplier.IApplier
45+
internal class DiscreteActionOutputApplier : TensorApplier.IApplier
4646
{
4747
readonly int[] m_ActionSize;
4848
readonly Multinomial m_Multinomial;
@@ -189,7 +189,7 @@ public static void Eval(TensorProxy src, TensorProxy dst, Multinomial multinomia
189189
/// The Applier for the Memory output tensor. Tensor is assumed to contain the new
190190
/// memory data of the agents in the batch.
191191
/// </summary>
192-
public class MemoryOutputApplier : TensorApplier.IApplier
192+
internal class MemoryOutputApplier : TensorApplier.IApplier
193193
{
194194
Dictionary<int, List<float>> m_Memories;
195195

@@ -219,7 +219,7 @@ public void Apply(TensorProxy tensorProxy, IEnumerable<int> actionIds, Dictionar
219219
}
220220
}
221221

222-
public class BarracudaMemoryOutputApplier : TensorApplier.IApplier
222+
internal class BarracudaMemoryOutputApplier : TensorApplier.IApplier
223223
{
224224
readonly int m_MemoriesCount;
225225
readonly int m_MemoryIndex;

com.unity.ml-agents/Runtime/InferenceBrain/BarracudaModelParamLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MLAgents.InferenceBrain
1111
/// Prepares the Tensors for the Learning Brain and exposes a list of failed checks if Model
1212
/// and BrainParameters are incompatible.
1313
/// </summary>
14-
public class BarracudaModelParamLoader
14+
internal class BarracudaModelParamLoader
1515
{
1616
enum ModelActionType
1717
{

0 commit comments

Comments
 (0)