Skip to content
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

add pre-commit hook for dotnet-format #4362

Merged
merged 16 commits into from
Aug 17, 2020
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ jobs:
# Need ruby for search-and-replace
sudo apt-get update
sudo apt-get install ruby-full

# install dotnet and the formatter - see https://docs.microsoft.com/en-us/dotnet/core/install/linux-debian#debian-9-
pushd ~
wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
popd

sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1
dotnet tool install -g dotnet-format --version 4.1.131201

python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,9 @@ repos:
name: validate release links
language: script
entry: utils/validate_release_links.py

- id: dotnet-format
name: dotnet-format
language: script
entry: utils/run_dotnet_format.py
types: [c#]

Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void TestCollectObservationsAgentMarkers()
{
using (Measure.ProfilerMarkers(s_Markers))
{
for(var i=0; i<k_MarkerTestSteps; i++)
for (var i = 0; i < k_MarkerTestSteps; i++)
{
RunAgent<CollectObservationsAgent>(k_NumAgentSteps, 7, ObservableAttributeOptions.Ignore);
}
Expand Down
2 changes: 1 addition & 1 deletion Project/Assets/ML-Agents/Editor/DisableBurstFromMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_CLOUD_BUILD
#if UNITY_CLOUD_BUILD
using UnityEditor;

public class DisableBurstFromMenu
Expand Down
18 changes: 11 additions & 7 deletions Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class CrawlerAgent : Agent
Vector3 m_WalkDir; //Direction to the target
Quaternion m_WalkDirLookRot; //Will hold the rotation to our target

[Header("Target To Walk Towards")] [Space(10)]
[Header("Target To Walk Towards")]
[Space(10)]
public TargetController target; //Target the agent will walk towards.

[Header("Body Parts")] [Space(10)] public Transform body;
Expand All @@ -26,20 +27,23 @@ public class CrawlerAgent : Agent
public Transform leg3Lower;


[Header("Orientation")] [Space(10)]
[Header("Orientation")]
[Space(10)]
//This will be used as a stabilized model space reference point for observations
//Because ragdolls can move erratically during training, using a stabilized reference transform improves learning
public OrientationCubeController orientationCube;

JointDriveController m_JdController;

[Header("Reward Functions To Use")] [Space(10)]
[Header("Reward Functions To Use")]
[Space(10)]
public bool rewardMovingTowardsTarget; // Agent should move towards target

public bool rewardFacingTarget; // Agent should face the target
public bool rewardUseTimePenalty; // Hurry up

[Header("Foot Grounded Visualization")] [Space(10)]
[Header("Foot Grounded Visualization")]
[Space(10)]
public bool useFootGroundedVisualization;

public MeshRenderer foot0;
Expand Down Expand Up @@ -205,8 +209,8 @@ void RewardFunctionMovingTowards()
{
throw new ArgumentException(
"NaN in movingTowardsDot.\n" +
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
$" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n"+
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n" +
$" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n" +
$" maximumWalkingSpeed: {maximumWalkingSpeed}"
);
}
Expand All @@ -223,7 +227,7 @@ void RewardFunctionFacingTarget()
{
throw new ArgumentException(
"NaN in movingTowardsDot.\n" +
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n" +
$" body.forward: {body.forward}"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Update()
// Send stats via SideChannel so that they'll appear in TensorBoard.
// These values get averaged every summary_frequency steps, so we don't
// need to send every Update() call.
if ((Time.frameCount % 100)== 0)
if ((Time.frameCount % 100) == 0)
{
m_Recorder.Add("TotalScore", totalScore);
}
Expand Down
10 changes: 5 additions & 5 deletions Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ public override void CollectDiscreteActionMasks(DiscreteActionMasker actionMaske
// Mask the necessary actions if selected by the user.
if (maskActions)
{
// Prevents the agent from picking an action that would make it collide with a wall
// Prevents the agent from picking an action that would make it collide with a wall
var positionX = (int)transform.position.x;
var positionZ = (int)transform.position.z;
var maxPosition = (int)m_ResetParams.GetWithDefault("gridSize", 5f) - 1;

if (positionX == 0)
{
actionMasker.SetMask(0, new []{ k_Left});
actionMasker.SetMask(0, new[] { k_Left });
}

if (positionX == maxPosition)
{
actionMasker.SetMask(0, new []{k_Right});
actionMasker.SetMask(0, new[] { k_Right });
}

if (positionZ == 0)
{
actionMasker.SetMask(0, new []{k_Down});
actionMasker.SetMask(0, new[] { k_Down });
}

if (positionZ == maxPosition)
{
actionMasker.SetMask(0, new []{k_Up});
actionMasker.SetMask(0, new[] { k_Up });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using UnityEngine;

namespace MLAgentsExamples
namespace MLAgentsExamples
{
public class AdjustTrainingTimescale : MonoBehaviour
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using UnityEngine;
using UnityEngine;

namespace Unity.MLAgentsExamples
{
public class DirectionIndicator : MonoBehaviour
{

public bool updatedByAgent; //should this be updated by the agent? If not, it will use local settings
public Transform transformToFollow; //ex: hips or body
public Transform targetToLookAt; //target in the scene the indicator will point to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ namespace Unity.MLAgentsExamples
[System.Serializable]
public class BodyPart
{
[Header("Body Part Info")][Space(10)] public ConfigurableJoint joint;
[Header("Body Part Info")] [Space(10)] public ConfigurableJoint joint;
public Rigidbody rb;
[HideInInspector] public Vector3 startingPos;
[HideInInspector] public Quaternion startingRot;

[Header("Ground & Target Contact")][Space(10)]
[Header("Ground & Target Contact")]
[Space(10)]
public GroundContact groundContact;

public TargetContact targetContact;

[FormerlySerializedAs("thisJDController")]
[HideInInspector] public JointDriveController thisJdController;

[Header("Current Joint Settings")][Space(10)]
[Header("Current Joint Settings")]
[Space(10)]
public Vector3 currentEularJointRotation;

[HideInInspector] public float currentStrength;
public float currentXNormalizedRot;
public float currentYNormalizedRot;
public float currentZNormalizedRot;

[Header("Other Debug Info")][Space(10)]
[Header("Other Debug Info")]
[Space(10)]
public Vector3 currentJointForce;

public float currentJointForceSqrMag;
Expand Down Expand Up @@ -99,7 +102,8 @@ public void SetJointStrength(float strength)

public class JointDriveController : MonoBehaviour
{
[Header("Joint Drive Settings")][Space(10)]
[Header("Joint Drive Settings")]
[Space(10)]
public float maxJointSpring;

public float jointDampen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Unity.MLAgentsExamples
/// </summary>
public class ModelOverrider : MonoBehaviour
{
HashSet<string> k_SupportedExtensions = new HashSet<string>{"nn", "onnx"};
HashSet<string> k_SupportedExtensions = new HashSet<string> { "nn", "onnx" };
const string k_CommandLineModelOverrideFlag = "--mlagents-override-model";
const string k_CommandLineModelOverrideDirectoryFlag = "--mlagents-override-model-directory";
const string k_CommandLineModelOverrideExtensionFlag = "--mlagents-override-model-extension";
Expand Down Expand Up @@ -63,7 +63,7 @@ public class ModelOverrider : MonoBehaviour

int TotalCompletedEpisodes
{
get { return m_PreviousAgentCompletedEpisodes + (m_Agent == null ? 0 : m_Agent.CompletedEpisodes); }
get { return m_PreviousAgentCompletedEpisodes + (m_Agent == null ? 0 : m_Agent.CompletedEpisodes); }
}

int TotalNumSteps
Expand All @@ -73,7 +73,7 @@ int TotalNumSteps

public bool HasOverrides
{
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
}

public static string GetOverrideBehaviorName(string originalBehaviorName)
Expand All @@ -99,17 +99,17 @@ void GetAssetPathFromCommandLine()
var args = commandLineArgsOverride ?? Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length-2)
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length - 2)
{
var key = args[i + 1].Trim();
var value = args[i + 2].Trim();
m_BehaviorNameOverrides[key] = value;
}
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length-1)
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length - 1)
{
m_BehaviorNameOverrideDirectory = args[i + 1].Trim();
}
else if (args[i] == k_CommandLineModelOverrideExtensionFlag && i < args.Length-1)
else if (args[i] == k_CommandLineModelOverrideExtensionFlag && i < args.Length - 1)
{
m_OverrideExtension = args[i + 1].Trim().ToLower();
var isKnownExtension = k_SupportedExtensions.Contains(m_OverrideExtension);
Expand All @@ -124,7 +124,7 @@ void GetAssetPathFromCommandLine()
#endif
}
}
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length-1)
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length - 1)
{
Int32.TryParse(args[i + 1], out maxEpisodes);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public NNModel GetModelForBehaviorName(string behaviorName)
{
assetPath = m_BehaviorNameOverrides[behaviorName];
}
else if(!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
else if (!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
{
assetPath = Path.Combine(m_BehaviorNameOverrideDirectory, $"{behaviorName}.{m_OverrideExtension}");
}
Expand All @@ -214,7 +214,7 @@ public NNModel GetModelForBehaviorName(string behaviorName)
{
model = File.ReadAllBytes(assetPath);
}
catch(IOException)
catch (IOException)
{
Debug.Log($"Couldn't load file {assetPath} at full path {Path.GetFullPath(assetPath)}", this);
// Cache the null so we don't repeatedly try to load a missing file
Expand Down Expand Up @@ -270,7 +270,7 @@ void OverrideModel()

if (!overrideOk && m_QuitOnLoadFailure)
{
if(!string.IsNullOrEmpty(overrideError))
if (!string.IsNullOrEmpty(overrideError))
{
Debug.LogWarning(overrideError);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand Down Expand Up @@ -419,7 +419,7 @@ void OnGUI()
var displayValues = s_DisplayTransformValues[target];

var index = 0;
var orderedKeys = displayValues.Keys.OrderBy(x => - displayValues[x].time);
var orderedKeys = displayValues.Keys.OrderBy(x => -displayValues[x].time);
foreach (var key in orderedKeys)
{
s_KeyStyle.alignment = TextAnchor.MiddleRight;
Expand Down Expand Up @@ -560,4 +560,4 @@ void Initialize()
s_RedStyle = s_ColorStyle[5];
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;

namespace Unity.MLAgentsExamples
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Awake()
m_OriginalMaximumDeltaTime = Time.maximumDeltaTime;
m_OriginalSolverIterations = Physics.defaultSolverIterations;
m_OriginalSolverVelocityIterations = Physics.defaultSolverVelocityIterations;
m_OriginalReuseCollisionCallbacks = Physics.reuseCollisionCallbacks ;
m_OriginalReuseCollisionCallbacks = Physics.reuseCollisionCallbacks;

// Override
Physics.gravity *= gravityMultiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public virtual int Write(ObservationWriter writer)
}

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

/// <inheritdoc/>
public void Reset() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using Random = UnityEngine.Random;
using Unity.MLAgents;
using UnityEngine.Events;
Expand All @@ -12,14 +12,14 @@ namespace Unity.MLAgentsExamples
/// </summary>
public class TargetController : MonoBehaviour
{

[Header("Collider Tag To Detect")]
public string tagToDetect = "agent"; //collider tag to detect

[Header("Target Placement")]
public float spawnRadius; //The radius in which a target can be randomly spawned.
public bool respawnIfTouched; //Should the target respawn to a different position when touched

[Header("Target Fell Protection")]
public bool respawnIfFallsOffPlatform = true; //If the target falls off the platform, reset the position.
public float fallDistance = 5; //distance below the starting height that will trigger a respawn
Expand Down
6 changes: 4 additions & 2 deletions Project/Assets/ML-Agents/Examples/Startup/Scripts/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ void Awake()
// no scene environment variable is found.
var args = Environment.GetCommandLineArgs();
Console.WriteLine("Command line arguments passed: " + String.Join(" ", args));
for (int i = 0; i < args.Length; i++) {
if (args [i] == k_SceneCommandLineFlag && i < args.Length - 1) {
for (int i = 0; i < args.Length; i++)
{
if (args[i] == k_SceneCommandLineFlag && i < args.Length - 1)
{
sceneName = args[i + 1];
}
}
Expand Down
Loading