Skip to content

Commit

Permalink
Precommit fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelalonsojr committed Oct 2, 2023
1 parent b4122df commit 17ee61f
Show file tree
Hide file tree
Showing 42 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ repos:
language: python
entry: ./utils/generate_markdown_docs.py --package_dirs ml-agents-envs ml-agents
pass_filenames: false
additional_dependencies: [pyyaml, pydoc-markdown==3.10.1]
additional_dependencies: [pyyaml==5.3, pydoc-markdown==3.10.1]
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void Update()
}

/// <inheritdoc/>
public void Reset() {}
public void Reset() { }

/// <inheritdoc/>
public CompressionSpec GetCompressionSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ internal IList<DisplayNode> GetDisplayNodes()

while (stack.Count != 0)
{
var(current, depth) = stack.Pop();
var (current, depth) = stack.Pop();
var obj = GetObjectAt(current);

var node = new DisplayNode
Expand Down
16 changes: 8 additions & 8 deletions com.unity.ml-agents/Runtime/Academy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void EnableAutomaticStepping()
// This try-catch is because DontDestroyOnLoad cannot be used in Editor Tests
GameObject.DontDestroyOnLoad(m_StepperObject);
}
catch {}
catch { }
}

/// <summary>
Expand Down Expand Up @@ -501,13 +501,13 @@ out var unityRlInitParameters

void ResetActions()
{
DecideAction = () => {};
DestroyAction = () => {};
AgentPreStep = i => {};
AgentSendState = () => {};
AgentAct = () => {};
AgentForceReset = () => {};
OnEnvironmentReset = () => {};
DecideAction = () => { };
DestroyAction = () => { };
AgentPreStep = i => { };
AgentSendState = () => { };
AgentAct = () => { };
AgentForceReset = () => { };
OnEnvironmentReset = () => { };
}

static void OnQuitCommandReceived()
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void CheckParameters(IReadOnlyCollection<T> actionArray, int offset, int
/// </summary>
/// <param name="actionArray">The action array to use for the this segment.</param>
public ActionSegment(T[] actionArray)
: this(actionArray ?? System.Array.Empty<T>(), 0, actionArray?.Length ?? 0) {}
: this(actionArray ?? System.Array.Empty<T>(), 0, actionArray?.Length ?? 0) { }

/// <summary>
/// Construct an <see cref="ActionSegment{T}"/> with an underlying array
Expand Down
4 changes: 2 additions & 2 deletions com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static ActionBuffers FromDiscreteActions(float[] discreteActions)
/// <param name="continuousActions">The continuous actions to send to an <see cref="IActionReceiver"/>.</param>
/// <param name="discreteActions">The discrete actions to send to an <see cref="IActionReceiver"/>.</param>
public ActionBuffers(float[] continuousActions, int[] discreteActions)
: this(new ActionSegment<float>(continuousActions), new ActionSegment<int>(discreteActions)) {}
: this(new ActionSegment<float>(continuousActions), new ActionSegment<int>(discreteActions)) { }

/// <summary>
/// Construct an <see cref="ActionBuffers"/> instance with the continuous and discrete actions that will
Expand All @@ -68,7 +68,7 @@ public ActionBuffers(ActionSegment<float> continuousActions, ActionSegment<int>
public ActionBuffers(ActionSpec actionSpec)
: this(new ActionSegment<float>(new float[actionSpec.NumContinuousActions]),
new ActionSegment<int>(new int[actionSpec.NumDiscreteActions]))
{}
{ }

/// <summary>
/// Create an <see cref="ActionBuffers"/> instance with ActionSpec and all actions stored as a float array.
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal ActionBuffers ActionBuffers
public VectorActuator(IActionReceiver actionReceiver,
ActionSpec actionSpec,
string name = "VectorActuator")
: this(actionReceiver, actionReceiver as IHeuristicProvider, actionSpec, name) {}
: this(actionReceiver, actionReceiver as IHeuristicProvider, actionSpec, name) { }

/// <summary>
/// Create a VectorActuator that forwards to the provided IActionReceiver.
Expand Down
10 changes: 5 additions & 5 deletions com.unity.ml-agents/Runtime/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public AgentVectorActuator(IActionReceiver actionReceiver,
ActionSpec actionSpec,
string name = "VectorActuator"
) : base(actionReceiver, heuristicProvider, actionSpec, name)
{}
{ }

public override BuiltInActuatorType GetBuiltInActuatorType()
{
Expand Down Expand Up @@ -904,7 +904,7 @@ void ResetData()
///
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// </remarks>
public virtual void Initialize() {}
public virtual void Initialize() { }

/// <summary>
/// Implement <see cref="Heuristic"/> to choose an action for this agent using a custom heuristic.
Expand Down Expand Up @@ -1241,7 +1241,7 @@ public ReadOnlyCollection<float> GetStackedObservations()
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_20_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <seealso cref="IActionReceiver.OnActionReceived"/>
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) {}
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { }

/// <summary>
/// Implement `OnActionReceived()` to specify agent behavior at every step, based
Expand Down Expand Up @@ -1309,15 +1309,15 @@ public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) {}
/// <param name="actions">
/// Struct containing the buffers of actions to be executed at this step.
/// </param>
public virtual void OnActionReceived(ActionBuffers actions) {}
public virtual void OnActionReceived(ActionBuffers actions) { }

/// <summary>
/// Implement `OnEpisodeBegin()` to set up an Agent instance at the beginning
/// of an episode.
/// </summary>
/// <seealso cref="Initialize"/>
/// <seealso cref="EndEpisode"/>
public virtual void OnEpisodeBegin() {}
public virtual void OnEpisodeBegin() { }

/// <summary>
/// Gets the most recent ActionBuffer for this agent.
Expand Down
10 changes: 5 additions & 5 deletions com.unity.ml-agents/Runtime/Inference/TensorProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ public enum TensorType

public long Height
{
get { return shape.Length >= 4 ? shape[^ 2] : 1; }
get { return shape.Length >= 4 ? shape[^2] : 1; }
}

public long Width
{
get { return shape.Length >= 3 ? shape[^ 1] : 1; }
get { return shape.Length >= 3 ? shape[^1] : 1; }
}

public long Channels
{
get
{
return shape.Length >= 4 ? shape[^ 3] :
shape.Length == 3 ? shape[^ 2] :
shape.Length == 2 ? shape[^ 1] : 1;
return shape.Length >= 4 ? shape[^3] :
shape.Length == 3 ? shape[^2] :
shape.Length == 2 ? shape[^1] : 1;
}
}

Expand Down
4 changes: 2 additions & 2 deletions com.unity.ml-agents/Runtime/InplaceArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public override string ToString()
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns>Whether the arrays are equivalent.</returns>
public static bool operator==(InplaceArray<T> lhs, InplaceArray<T> rhs)
public static bool operator ==(InplaceArray<T> lhs, InplaceArray<T> rhs)
{
return lhs.Equals(rhs);
}
Expand All @@ -206,7 +206,7 @@ public override string ToString()
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns>Whether the arrays are not equivalent</returns>
public static bool operator!=(InplaceArray<T> lhs, InplaceArray<T> rhs) => !lhs.Equals(rhs);
public static bool operator !=(InplaceArray<T> lhs, InplaceArray<T> rhs) => !lhs.Equals(rhs);

/// <summary>
/// Check that the arrays are equivalent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct BoardSize
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns>True if all fields are less than or equal.</returns>
public static bool operator<=(BoardSize lhs, BoardSize rhs)
public static bool operator <=(BoardSize lhs, BoardSize rhs)
{
return lhs.Rows <= rhs.Rows && lhs.Columns <= rhs.Columns && lhs.NumCellTypes <= rhs.NumCellTypes &&
lhs.NumSpecialTypes <= rhs.NumSpecialTypes;
Expand All @@ -50,7 +50,7 @@ public struct BoardSize
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns>True if all fields are greater than or equal.</returns>
public static bool operator>=(BoardSize lhs, BoardSize rhs)
public static bool operator >=(BoardSize lhs, BoardSize rhs)
{
return lhs.Rows >= rhs.Rows && lhs.Columns >= rhs.Columns && lhs.NumCellTypes >= rhs.NumCellTypes &&
lhs.NumSpecialTypes >= rhs.NumSpecialTypes;
Expand Down Expand Up @@ -200,7 +200,7 @@ public bool SimpleIsMoveValid(Move move)
using (TimerStack.Instance.Scoped("SimpleIsMoveValid"))
{
var moveVal = GetCellType(move.Row, move.Column);
var(otherRow, otherCol) = move.OtherCell();
var (otherRow, otherCol) = move.OtherCell();
var oppositeVal = GetCellType(otherRow, otherCol);

// Simple check - if the values are the same, don't match
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static Move FromPositionAndDirection(int row, int col, Direction dir, Boa
/// <returns></returns>
public bool InRangeForBoard(BoardSize boardSize)
{
var(otherRow, otherCol) = OtherCell();
var (otherRow, otherCol) = OtherCell();
// Get the maximum row and column this move would affect.
var maxMoveRow = Mathf.Max(Row, otherRow);
var maxMoveCol = Mathf.Max(Column, otherCol);
Expand Down
20 changes: 10 additions & 10 deletions com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public string FullyQualifiedBehaviorName

void Awake()
{
OnPolicyUpdated += mode => {};
OnPolicyUpdated += mode => { };
}

internal IPolicy GeneratePolicy(ActionSpec actionSpec, ActuatorManager actuatorManager)
Expand All @@ -233,17 +233,17 @@ internal IPolicy GeneratePolicy(ActionSpec actionSpec, ActuatorManager actuatorM
case BehaviorType.HeuristicOnly:
return new HeuristicPolicy(actuatorManager, actionSpec);
case BehaviorType.InferenceOnly:
{
if (m_Model == null)
{
var behaviorType = BehaviorType.InferenceOnly.ToString();
throw new UnityAgentsException(
$"Can't use Behavior Type {behaviorType} without a model. " +
"Either assign a model, or change to a different Behavior Type."
);
if (m_Model == null)
{
var behaviorType = BehaviorType.InferenceOnly.ToString();
throw new UnityAgentsException(
$"Can't use Behavior Type {behaviorType} without a model. " +
"Either assign a model, or change to a different Behavior Type."
);
}
return new SentisPolicy(actionSpec, actuatorManager, m_Model, m_InferenceDevice, m_BehaviorName, m_DeterministicInference);
}
return new SentisPolicy(actionSpec, actuatorManager, m_Model, m_InferenceDevice, m_BehaviorName, m_DeterministicInference);
}
case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)
{
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void RemoveAt(int index)
public float this[int index]
{
get { return 0.0f; }
set {}
set { }
}
}

Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void Update()
}

/// <inheritdoc/>
public void Reset() {}
public void Reset() { }

/// <inheritdoc/>
public CompressionSpec GetCompressionSpec()
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/GridSensorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected string[] DetectableTags
}

/// <inheritdoc/>
public void Reset() {}
public void Reset() { }

/// <summary>
/// Clears the perception buffer before loading in new data.
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ObservationWriter

TensorShape m_TensorShape;

public ObservationWriter() {}
public ObservationWriter() { }

/// <summary>
/// Set the writer to write to an IList at the given channelOffset.
Expand Down
6 changes: 3 additions & 3 deletions com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public int OutputSize()
var startPositionWorld = Transform.TransformPoint(startPositionLocal);
var endPositionWorld = Transform.TransformPoint(endPositionLocal);

return (StartPositionWorld : startPositionWorld, EndPositionWorld : endPositionWorld);
return (StartPositionWorld: startPositionWorld, EndPositionWorld: endPositionWorld);
}

/// <summary>
Expand Down Expand Up @@ -329,7 +329,7 @@ public int Write(ObservationWriter writer)
// For each ray, write the information to the observation buffer
for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
{
m_RayPerceptionOutput.RayOutputs ? [rayIndex].ToFloatArray(numDetectableTags, rayIndex, m_Observations);
m_RayPerceptionOutput.RayOutputs?[rayIndex].ToFloatArray(numDetectableTags, rayIndex, m_Observations);
}

// Finally, add the observations to the ObservationWriter
Expand Down Expand Up @@ -364,7 +364,7 @@ public void Update()
}

/// <inheritdoc/>
public void Reset() {}
public void Reset() { }

/// <inheritdoc/>
public ObservationSpec GetObservationSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class BoolReflectionSensor : ReflectionSensorBase
{
public BoolReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 1)
{}
{ }

internal override void WriteReflectedField(ObservationWriter writer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class FloatReflectionSensor : ReflectionSensorBase
{
public FloatReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 1)
{}
{ }

internal override void WriteReflectedField(ObservationWriter writer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class IntReflectionSensor : ReflectionSensorBase
{
public IntReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 1)
{}
{ }

internal override void WriteReflectedField(ObservationWriter writer)
{
Expand Down
Loading

0 comments on commit 17ee61f

Please sign in to comment.