浏览代码

Make analytics module an optional dependency. (#5109)

Co-authored-by: Chris Elion <chris.elion@unity3d.com>
/develop/input-actuator-tanks
GitHub 4 年前
当前提交
367f7a60
共有 14 个文件被更改,包括 112 次插入34 次删除
  1. 1
      .yamato/com.unity.ml-agents-test.yml
  2. 2
      Project/Packages/manifest.json
  3. 1
      com.unity.ml-agents/CHANGELOG.md
  4. 28
      com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs
  5. 38
      com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs
  6. 4
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
  7. 4
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
  8. 3
      com.unity.ml-agents/Runtime/Policies/RemotePolicy.cs
  9. 9
      com.unity.ml-agents/Runtime/Unity.ML-Agents.asmdef
  10. 3
      com.unity.ml-agents/Tests/Editor/Analytics/InferenceAnalyticsTests.cs
  11. 6
      com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs
  12. 7
      com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef
  13. 3
      com.unity.ml-agents/package.json
  14. 37
      .yamato/com.unity.ml-agents-optional-dep-tests.yml

1
.yamato/com.unity.ml-agents-test.yml


{% endfor %}
{% endfor %}
{% endfor %}

2
Project/Packages/manifest.json


{
"dependencies": {
"com.unity.ads": "2.0.8",
"com.unity.analytics": "3.2.3",
"com.unity.purchasing": "2.2.1",
"com.unity.textmeshpro": "1.4.1",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",

1
com.unity.ml-agents/CHANGELOG.md


### Minor Changes
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
- Updated com.unity.barracuda to 1.3.2-preview. (#5084)
- Make com.unity.modules.unityanalytics an optional dependency. (#5109)
- Added 3D Ball to the `com.unity.ml-agents` samples. (#5077)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- The `encoding_size` setting for RewardSignals has been deprecated. Please use `network_settings` instead. (#4982)

28
com.unity.ml-agents/Runtime/Analytics/InferenceAnalytics.cs


#if MLA_UNITY_ANALYTICS_MODULE || !UNITY_2019_4_OR_NEWER
#define MLA_UNITY_ANALYTICS_MODULE_ENABLED
#endif
using System.Diagnostics;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Inference;

#if MLA_UNITY_ANALYTICS_MODULE_ENABLED
#endif
#if MLA_UNITY_ANALYTICS_MODULE_ENABLED
#endif
#endif // MLA_UNITY_ANALYTICS_MODULE_ENABLED
#endif // UNITY_EDITOR
namespace Unity.MLAgents.Analytics

return true;
}
#if UNITY_EDITOR
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE_ENABLED
#else
if (result == AnalyticsResult.Ok)
{
s_EventRegistered = true;
}
#elif MLA_UNITY_ANALYTICS_MODULE_ENABLED
#endif
#endif
if (s_EventRegistered && s_SentModels == null)
{
s_SentModels = new HashSet<NNModel>();

/// <param name="actionSpec">ActionSpec for the Agent. Used to generate information about the action space.</param>
/// <param name="actuators">List of IActuators for the Agent. Used to generate information about the action space.</param>
/// <returns></returns>
[Conditional("MLA_UNITY_ANALYTICS_MODULE_ENABLED")]
public static void InferenceModelSet(
NNModel nnModel,
string behaviorName,

var data = GetEventForModel(nnModel, behaviorName, inferenceDevice, sensors, actionSpec, actuators);
// Note - to debug, use JsonUtility.ToJson on the event.
// Debug.Log(JsonUtility.ToJson(data, true));
#if UNITY_EDITOR
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE_ENABLED
if (AnalyticsUtils.s_SendEditorAnalytics)
{
EditorAnalytics.SendEventWithLimit(k_EventName, data, k_EventVersion);

38
com.unity.ml-agents/Runtime/Analytics/TrainingAnalytics.cs


#if MLA_UNITY_ANALYTICS_MODULE || !UNITY_2019_4_OR_NEWER
#define MLA_UNITY_ANALYTICS_MODULE_ENABLED
#endif
using System.Diagnostics;
#if MLA_UNITY_ANALYTICS_MODULE_ENABLED
#if UNITY_EDITOR
using UnityEditor.Analytics;
#endif
#endif
using UnityEditor.Analytics;
#endif
namespace Unity.MLAgents.Analytics

static bool EnableAnalytics()
{
#if MLA_UNITY_ANALYTICS_MODULE_ENABLED
#else
AnalyticsResult result = AnalyticsResult.UnsupportedPlatform;
#endif
#else
return false;
#endif // UNITY_EDITOR
}
s_EventsRegistered = true;

}
return s_EventsRegistered;
#else
return false;
#endif // MLA_UNITY_ANALYTICS_MODULE_ENABLED
}
/// <summary>

/// <param name="packageVersion"></param>
[Conditional("MLA_UNITY_ANALYTICS_MODULE_ENABLED")]
public static void SetTrainerInformation(string packageVersion, string communicationVersion)
{
s_TrainerPackageVersion = packageVersion;

public static bool IsAnalyticsEnabled()
{
#if UNITY_EDITOR
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE_ENABLED
return EditorAnalytics.enabled;
#else
return false;

[Conditional("MLA_UNITY_ANALYTICS_MODULE_ENABLED")]
public static void TrainingEnvironmentInitialized(TrainingEnvironmentInitializedEvent tbiEvent)
{
if (!IsAnalyticsEnabled())

// Debug.Log(
// $"Would send event {k_TrainingEnvironmentInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
// );
#if UNITY_EDITOR
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE_ENABLED
#else
return;
[Conditional("MLA_UNITY_ANALYTICS_MODULE_ENABLED")]
public static void RemotePolicyInitialized(
string fullyQualifiedBehaviorName,
IList<ISensor> sensors,

// Debug.Log(
// $"Would send event {k_RemotePolicyInitializedEventName} with body {JsonUtility.ToJson(data, true)}"
// );
#if UNITY_EDITOR
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE_ENABLED
#else
return;
#endif
}

return fullyQualifiedBehaviorName.Substring(0, lastQuestionIndex);
}
[Conditional("MLA_UNITY_ANALYTICS_MODULE_ENABLED")]
public static void TrainingBehaviorInitialized(TrainingBehaviorInitializedEvent tbiEvent)
{
if (!IsAnalyticsEnabled())

// Debug.Log(
// $"Would send event {k_TrainingBehaviorInitializedEventName} with body {JsonUtility.ToJson(tbiEvent, true)}"
// );
#if UNITY_EDITOR
#if UNITY_EDITOR && MLA_UNITY_ANALYTICS_MODULE_ENABLED
if (AnalyticsUtils.s_SendEditorAnalytics)
{
EditorAnalytics.SendEventWithLimit(k_TrainingBehaviorInitializedEventName, tbiEvent);

4
com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs


using UnityEngine;
using System.Runtime.CompilerServices;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.Analytics;
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor")]
[assembly: InternalsVisibleTo("Unity.ML-Agents.Editor.Tests")]

}
#region Analytics
internal static TrainingEnvironmentInitializedEvent ToTrainingEnvironmentInitializedEvent(
this TrainingEnvironmentInitialized inputProto)
{

NumNetworkHiddenUnits = inputProto.NumNetworkHiddenUnits,
};
}
#endregion
}

4
com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs


using System.Linq;
using UnityEngine;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.Analytics;
namespace Unity.MLAgents
{

var pythonPackageVersion = initializationInput.RlInitializationInput.PackageVersion;
var pythonCommunicationVersion = initializationInput.RlInitializationInput.CommunicationVersion;
TrainingAnalytics.SetTrainerInformation(pythonPackageVersion, pythonCommunicationVersion);
var communicationIsCompatible = CheckCommunicationVersionsAreCompatible(

3
com.unity.ml-agents/Runtime/Policies/RemotePolicy.cs


using Unity.MLAgents.Sensors;
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents.Policies

9
com.unity.ml-agents/Runtime/Unity.ML-Agents.asmdef


"Grpc.Core.dll"
],
"autoReferenced": true,
"defineConstraints": []
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.modules.unityanalytics",
"expression": "1.0.0",
"define": "MLA_UNITY_ANALYTICS_MODULE"
}
]
}

3
com.unity.ml-agents/Tests/Editor/Analytics/InferenceAnalyticsTests.cs


using UnityEngine;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.Analytics;
namespace Unity.MLAgents.Tests.Analytics
{

6
com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs


using NUnit.Framework;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.CommunicatorObjects;
using Unity.MLAgents.Analytics;
using Unity.MLAgents.CommunicatorObjects;
namespace Unity.MLAgents.Tests
{

sparseChannelSensor.Mapping = new[] { 0, 0, 0, 1, 1, 1 };
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), false);
}
[Test]
public void TestDefaultTrainingEvents()
{

7
com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef


"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [
{
"name": "com.unity.modules.unityanalytics",
"expression": "1.0.0",
"define": "MLA_UNITY_ANALYTICS_MODULE"
}
]
}

3
com.unity.ml-agents/package.json


"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0"
"com.unity.modules.physics2d": "1.0.0"
}
}

37
.yamato/com.unity.ml-agents-optional-dep-tests.yml


OptionalDependencyTestsLinux:
name : LinuxOptionalDependenciesTests
agent:
type: Unity::VM
image: package-ci/ubuntu:stable
flavor: b1.medium
commands:
- |
curl -L https://artifactory.prd.it.unity3d.com/artifactory/api/gpg/key/public | sudo apt-key add -
sudo sh -c "echo 'deb https://artifactory.prd.it.unity3d.com/artifactory/unity-apt-local bionic main' > /etc/apt/sources.list.d/unity.list"
sudo apt update
sudo apt install -y unity-config
npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
unity-config settings editor-path ./.Editor
unity-config project create opt-deps-test
unity-config project add dependency com.unity.ml-agents/
unity-config project add testable com.unity.ml-agents
unity-config project add dependency com.unity.modules.imageconversion@1.0.0
unity-config project add dependency com.unity.modules.jsonserialize@1.0.0
unity-config project add dependency com.unity.modules.physics@1.0.0
unity-config project add dependency com.unity.modules.physics2d@1.0.0
upm-ci project test -u 2019.4 --type project-tests --project-path opt-deps-test --package-filter com.unity.ml-agents
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
triggers:
cancel_old_ci: true
expression: |
(pull_request.target eq "main" OR
pull_request.target match "release.+") AND
NOT pull_request.draft AND
(pull_request.changes.any match "com.unity.ml-agents/**" OR
pull_request.changes.any match ".yamato/com.unity.ml-agents-test.yml")
正在加载...
取消
保存