浏览代码

Turns physics modules into optional dependencies. (#5112)

/check-for-ModelOverriders
GitHub 4 年前
当前提交
3d53ec5a
共有 22 个文件被更改,包括 375 次插入198 次删除
  1. 100
      .yamato/com.unity.ml-agents-optional-dep-tests.yml
  2. 263
      .yamato/com.unity.ml-agents-test.yml
  3. 3
      com.unity.ml-agents.extensions/package.json
  4. 2
      com.unity.ml-agents/CHANGELOG.md
  5. 16
      com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
  6. 14
      com.unity.ml-agents/Editor/Unity.ML-Agents.Editor.asmdef
  7. 14
      com.unity.ml-agents/Runtime/Agent.cs
  8. 10
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
  9. 2
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponent2D.cs
  10. 4
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
  11. 2
      com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs
  12. 10
      com.unity.ml-agents/Runtime/Unity.ML-Agents.asmdef
  13. 7
      com.unity.ml-agents/Runtime/Utilities.cs
  14. 2
      com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs
  15. 10
      com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef
  16. 13
      com.unity.ml-agents/Tests/Runtime/RuntimeAPITest.cs
  17. 16
      com.unity.ml-agents/Tests/Runtime/Sensor/RayPerceptionSensorTests.cs
  18. 12
      com.unity.ml-agents/Tests/Runtime/Sensor/Unity.ML-Agents.Runtime.Sensor.Tests.asmdef
  19. 12
      com.unity.ml-agents/Tests/Runtime/Unity.ML-Agents.Runtime.Tests.asmdef
  20. 4
      com.unity.ml-agents/package.json
  21. 40
      .yamato/com.unity.ml-agents-coverage.yml
  22. 17
      .yamato/coverage_tests.metafile

100
.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")
optional_deps:
- name: Analytics
project: "OptionalDepedencyTests/NoAnalyticsModule"
version: 2020.2
- name: Physics
project: OptionalDepedencyTests/NoPhysicsModule
version: 2020.2
- name: Physics2D
project: OptionalDepedencyTests/NoPhysics2DModule
version: 2020.2
---
{% for optional_dep in optional_deps %}
OptionalDependencyTests_{{ optional_dep.name }}:
name : Test Optional Package Dependencies {{ optional_dep.name }}
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
{% unless optional_dep.name == "Physics" %}
unity-config project add dependency com.unity.modules.physics@1.0.0
{% endunless %}
{% unless optional_dep.name == "Physics2D" %}
unity-config project add dependency com.unity.modules.physics2d@1.0.0
{% endunless %}
{% unless optional_dep.name == "Analytics" %}
unity-config project add dependency com.unity.modules.unityanalytics@1.0.0
{% endunless %}
upm-ci project test -u {{ optional_dep.version }} --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
{% for coverage_editor in coverage_test_editors %}
{% for coverage_plathform in coverage_test_platforms %}
{% for coverage_package in coverage_test_packages %}
- .yamato/com.unity.ml-agents-coverage.yml#test_coverage_{{ coverage_package.name }}_{{ coverage_platform.name }}_{{ coverage_editor.version }}
{% endfor %}
{% endfor %}
{% endfor %}
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")
{% endfor %}

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


{% metadata_file .yamato/coverage_tests.metafile %}
- version: 2019.4
enableCodeCoverage: !!bool true
# We want some scene tests to run in the DevProject, but packages there only support 2020+
testProject: Project
enableNoDefaultPackages: !!bool true
- version: 2020.2
enableCodeCoverage: !!bool true
testProject: DevProject
enableNoDefaultPackages: !!bool true
- version: 2021.1
enableCodeCoverage: !!bool true
testProject: DevProject
enableNoDefaultPackages: !!bool true
- version: 2019.4
enableCodeCoverage: !!bool true
# We want some scene tests to run in the DevProject, but packages there only support 2020+
testProject: Project
enableNoDefaultPackages: !!bool true
- version: 2020.2
enableCodeCoverage: !!bool true
testProject: DevProject
enableNoDefaultPackages: !!bool true
- version: 2021.1
enableCodeCoverage: !!bool true
testProject: DevProject
enableNoDefaultPackages: !!bool true
- version: trunk
# Workaround for MLA-1596 - need to make sure we load the right results.
enableCodeCoverage: !!bool false
testProject: DevProject
- version: trunk
# Workaround for MLA-1596 - need to make sure we load the right results.
enableCodeCoverage: !!bool false
testProject: DevProject
- name: win
type: Unity::VM
image: package-ci/win10:stable
flavor: b1.large
- name: mac
type: Unity::VM::osx
image: package-ci/mac:stable
flavor: b1.small
- name: linux
type: Unity::VM
image: package-ci/ubuntu:stable
flavor: b1.medium
- name: win
type: Unity::VM
image: package-ci/win10:stable
flavor: b1.large
- name: mac
type: Unity::VM::osx
image: package-ci/mac:stable
flavor: b1.small
- name: linux
type: Unity::VM
image: package-ci/ubuntu:stable
flavor: b1.medium
- name: com.unity.ml-agents
assembly: Unity.ML-Agents
minCoveragePct: 72
- name: com.unity.ml-agents.extensions
assembly: Unity.ML-Agents.Extensions*
minCoveragePct: 75
- name: com.unity.ml-agents
assembly: Unity.ML-Agents
minCoveragePct: 72
- name: com.unity.ml-agents.extensions
assembly: Unity.ML-Agents.Extensions*
minCoveragePct: 75
name: Run All Combinations of Editors/Platforms Tests
dependencies:
{% for editor in test_editors %}
{% for platform in test_platforms %}
- .yamato/com.unity.ml-agents-test.yml#test_com.unity.ml-agents_{{ platform.name }}_{{ editor.version }}
{% endfor %}
{% endfor %}
{% for editor in trunk_editor %}
{% for platform in test_platforms %}
- .yamato/com.unity.ml-agents-test.yml#test_com.unity.ml-agents_{{ platform.name }}_{{ editor.version }}
{% endfor %}
{% endfor %}
triggers:
cancel_old_ci: true
recurring:
- branch: main
frequency: daily
name: Run All Combinations of Editors/Platforms Tests
dependencies:
{% for coverage_editor in coverage_test_editors %}
{% for coverage_plathform in coverage_test_platforms %}
{% for coverage_package in coverage_test_packages %}
- .yamato/com.unity.ml-agents-coverage.yml#test_coverage_{{ coverage_package.name }}_{{ coverage_platform.name }}_{{ coverage_editor.version }}
{% endfor %}
{% endfor %}
{% endfor %}
{% for editor in test_editors %}
{% for platform in test_platforms %}
- .yamato/com.unity.ml-agents-test.yml#test_com.unity.ml-agents_{{ platform.name }}_{{ editor.version }}
{% endfor %}
{% endfor %}
{% for editor in trunk_editor %}
{% for platform in test_platforms %}
- .yamato/com.unity.ml-agents-test.yml#test_com.unity.ml-agents_{{ platform.name }}_{{ editor.version }}
{% endfor %}
{% endfor %}
triggers:
cancel_old_ci: true
recurring:
- branch: main
frequency: daily
{% for package in packages %}
{% for package in packages %}
{% for platform in test_platforms %}
{% for platform in test_platforms %}
{% if editor.enableCodeCoverage %}
{% capture coverageOptions %} --enable-code-coverage --code-coverage-options 'generateHtmlReport;assemblyFilters:+{{ package.assembly }}'{% endcapture %}
{% else %}
{% assign coverageOptions = "" %}
{% endif %}
{% if editor.enableNoDefaultPackages %}
{% if editor.enableNoDefaultPackages %}
{% else %}
{% else %}
{% endif %}
{% endif %}
name : {{ package.name }} test {{ editor.version }} on {{ platform.name }}
agent:
type: {{ platform.type }}
image: {{ platform.image }}
flavor: {{ platform.flavor}}
commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} {{ noDefaultPackagesOptions }} --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
triggers:
cancel_old_ci: true
{% if platform.name == "linux" %}
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 " {{ editor.testProject }}/**" OR
{% if package.name == "com.unity.ml-agents.extensions" %}
pull_request.changes.any match "com.unity.ml-agents.extensions/**" OR
name : {{ package.name }} test {{ editor.version }} on {{ platform.name }}
agent:
type: {{ platform.type }}
image: {{ platform.image }}
flavor: {{ platform.flavor}}
commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ noDefaultPackagesOptions }} --extra-utr-arg "reruncount=2"
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
{% for coverage_editor in coverage_test_editors %}
{% for coverage_plathform in coverage_test_platforms %}
{% for coverage_package in coverage_test_packages %}
- .yamato/com.unity.ml-agents-coverage.yml#test_coverage_{{ coverage_package.name }}_{{ coverage_platform.name }}_{{ coverage_editor.version }}
{% endfor %}
{% endfor %}
{% endfor %}
triggers:
cancel_old_ci: true
{% if platform.name == "linux" %}
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 " {{ editor.testProject }}/**" OR
{% if package.name == "com.unity.ml-agents.extensions" %}
pull_request.changes.any match "com.unity.ml-agents.extensions/**" OR
{% endif %}
pull_request.changes.any match ".yamato/com.unity.ml-agents-test.yml")
pull_request.changes.any match ".yamato/com.unity.ml-agents-test.yml")
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% for package in packages %}
{% for package in packages %}
{% for platform in test_platforms %}
{% for platform in test_platforms %}
{% if editor.enableCodeCoverage %}
{% if editor.enableCodeCoverage %}
{% else %}
{% assign coverageOptions = "" %}
{% endif %}
{% else %}
{% assign coverageOptions = "" %}
{% endif %}
name : {{ package.name }} test {{ editor.version }} on {{ platform.name }}
agent:
type: {{ platform.type }}
image: {{ platform.image }}
flavor: {{ platform.flavor}}
commands:
- python3 -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade
- unity-downloader-cli -u trunk -c editor --wait --fast
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-create-project-arg="-upmNoDefaultPackages" --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
triggers:
cancel_old_ci: true
{% endfor %}
name : {{ package.name }} test {{ editor.version }} on {{ platform.name }}
agent:
type: {{ platform.type }}
image: {{ platform.image }}
flavor: {{ platform.flavor}}
commands:
- python3 -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade
- unity-downloader-cli -u trunk -c editor --wait --fast
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-create-project-arg="-upmNoDefaultPackages" --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
{% for coverage_editor in coverage_test_editors %}
{% for coverage_plathform in coverage_test_platforms %}
{% for coverage_package in coverage_test_packages %}
- .yamato/com.unity.ml-agents-coverage.yml#test_coverage_{{ coverage_package.name }}_{{ coverage_platform.name }}_{{ coverage_editor.version }}
{% endfor %}
{% endfor %}
{% endfor %}
triggers:
cancel_old_ci: true
{% endfor %}
{% endfor %}
{% endfor %}

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


"unity": "2019.4",
"description": "A source-only package for new features based on ML-Agents",
"dependencies": {
"com.unity.ml-agents": "2.0.0-exp.1"
"com.unity.ml-agents": "2.0.0-exp.1",
"com.unity.modules.physics": "1.0.0"
}
}

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


- The `.onnx` models input names have changed. All input placeholders will now use the prefix `obs_` removing the distinction between visual and vector observations. Models created with this version will not be usable with previous versions of the package (#5080)
- The `.onnx` models discrete action output now contains the discrete actions values and not the logits. Models created with this version will not be usable with previous versions of the package (#5080)
- Added ML-Agents package settings. (#5027)
- Make com.unity.modules.unityanalytics an optional dependency. (#5109)
- Make com.unity.modules.physics and com.unity.modules.physics2d optional dependencies. (#5112)
#### ml-agents / ml-agents-envs / gym-unity (Python)
### Bug Fixes

16
com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs


protected void OnRayPerceptionInspectorGUI(bool is3d)
{
#if !MLA_UNITY_PHYSICS_MODULE
if (is3d)
{
EditorGUILayout.HelpBox("The Physics Module is not currently present. " +
"Please add it to your project in order to use the Ray Perception APIs in the " +
$"{nameof(RayPerceptionSensorComponent3D)}", MessageType.Warning);
}
#endif
#if !MLA_UNITY_PHYSICS2D_MODULE
if (!is3d)
{
EditorGUILayout.HelpBox("The Physics2D Module is not currently present. " +
"Please add it to your project in order to use the Ray Perception APIs in the " +
$"{nameof(RayPerceptionSensorComponent3D)}", MessageType.Warning);
}
#endif
var so = serializedObject;
so.Update();

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


"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.modules.physics",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS_MODULE"
},
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS2D_MODULE"
}
]
}

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


internal class AgentVectorActuator : VectorActuator
{
public AgentVectorActuator(IActionReceiver actionReceiver,
IHeuristicProvider heuristicProvider,
ActionSpec actionSpec,
string name = "VectorActuator"
IHeuristicProvider heuristicProvider,
ActionSpec actionSpec,
string name = "VectorActuator"
) : base(actionReceiver, heuristicProvider, actionSpec, name)
{ }

/// <param name="reward">The new value of the reward.</param>
public void SetReward(float reward)
{
#if DEBUG
#endif
m_CumulativeReward += (reward - m_Reward);
m_Reward = reward;
}

/// <param name="increment">Incremental reward value.</param>
public void AddReward(float increment)
{
#if DEBUG
#endif
m_Reward += increment;
m_CumulativeReward += increment;
}

#if DEBUG
#endif
#if DEBUG
#endif
m_GroupReward += increment;
}

10
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs


unscaledCastRadius;
// Do the cast and assign the hit information for each detectable tag.
bool castHit;
float hitFraction;
GameObject hitObject;
var castHit = false;
var hitFraction = 1.0f;
GameObject hitObject = null;
#if MLA_UNITY_PHYSICS_MODULE
RaycastHit rayHit;
if (scaledCastRadius > 0f)
{

// To avoid 0/0, set the fraction to 0.
hitFraction = castHit ? (scaledRayLength > 0 ? rayHit.distance / scaledRayLength : 0.0f) : 1.0f;
hitObject = castHit ? rayHit.collider.gameObject : null;
#endif
#if MLA_UNITY_PHYSICS2D_MODULE
RaycastHit2D rayHit;
if (scaledCastRadius > 0f)
{

castHit = rayHit;
hitFraction = castHit ? rayHit.fraction : 1.0f;
hitObject = castHit ? rayHit.collider.gameObject : null;
#endif
}
var rayOutput = new RayPerceptionOutput.RayOutput

2
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponent2D.cs


public RayPerceptionSensorComponent2D()
{
// Set to the 2D defaults (just in case they ever diverge).
RayLayerMask = Physics2D.DefaultRaycastLayers;
RayLayerMask = -5;
}
/// <inheritdoc/>

4
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs


set { m_RayLength = value; UpdateSensor(); }
}
// The value of the default layers.
const int k_PhysicsDefaultLayers = -5;
LayerMask m_RayLayerMask = Physics.DefaultRaycastLayers;
LayerMask m_RayLayerMask = k_PhysicsDefaultLayers;
/// <summary>
/// Controls which layers the rays can hit.

2
com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs


void AddFloatObs(float obs)
{
#if DEBUG
#endif
m_Observations.Add(obs);
}

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


"name": "com.unity.modules.unityanalytics",
"expression": "1.0.0",
"define": "MLA_UNITY_ANALYTICS_MODULE"
},
{
"name": "com.unity.modules.physics",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS_MODULE"
},
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS2D_MODULE"
}
]
}

7
com.unity.ml-agents/Runtime/Utilities.cs


using System;
using System.Diagnostics;
/// <summary>
/// Calculates the cumulative sum of an integer array. The result array will be one element
/// larger than the input array since it has a padded 0 at the beginning.

return result;
}
#if DEBUG
[Conditional("DEBUG")]
if (float.IsNaN(value))
{
throw new ArgumentException($"NaN {valueCategory} passed to {caller}.");

throw new ArgumentException($"Inifinity {valueCategory} passed to {caller}.");
}
}
#endif
}

2
com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs


Assert.IsTrue(sensorComponent.Grayscale);
}
#if MLA_UNITY_PHYSICS_MODULE
[Test]
public void CheckSetupRayPerceptionSensorComponent()
{

sensorComponent.CreateSensor();
}
#endif
}
}

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


"name": "com.unity.modules.unityanalytics",
"expression": "1.0.0",
"define": "MLA_UNITY_ANALYTICS_MODULE"
},
{
"name": "com.unity.modules.physics",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS_MODULE"
},
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS2D_MODULE"
}
]
}

13
com.unity.ml-agents/Tests/Runtime/RuntimeAPITest.cs


#if UNITY_INCLUDE_TESTS
using System.Collections;
using System.Collections.Generic;
using Unity.MLAgents;

behaviorParams.BrainParameters.VectorObservationSize = 3;
behaviorParams.BrainParameters.NumStackedVectorObservations = 2;
behaviorParams.BrainParameters.VectorActionDescriptions = new[] { "Continuous1", "TestActionA", "TestActionB" };
behaviorParams.BrainParameters.ActionSpec = new ActionSpec(1, new []{2, 2});
behaviorParams.BrainParameters.ActionSpec = new ActionSpec(1, new[] { 2, 2 });
behaviorParams.BehaviorName = "TestBehavior";
behaviorParams.TeamId = 42;
behaviorParams.UseChildSensors = true;

// Can't actually create an Agent with InferenceOnly and no model, so change back
behaviorParams.BehaviorType = BehaviorType.Default;
#if MLA_UNITY_PHSYICS_MODULE
var sensorComponent = gameObject.AddComponent<RayPerceptionSensorComponent3D>();
sensorComponent.SensorName = "ray3d";
sensorComponent.DetectableTags = new List<string> { "Player", "Respawn" };

// ISensor isn't set up yet.
Assert.IsNull(sensorComponent.RaySensor);
#endif
// Make sure we can set the behavior type correctly after the agent is initialized

decisionRequester.DecisionPeriod = 2;
decisionRequester.TakeActionsBetweenDecisions = true;
#if MLA_UNITY_PHSYICS_MODULE
#endif
// Let's change the inference device
var otherDevice = behaviorParams.InferenceDevice == InferenceDevice.CPU ? InferenceDevice.GPU : InferenceDevice.CPU;
agent.SetModel(behaviorParams.BehaviorName, behaviorParams.Model, otherDevice);

var actions = agent.GetStoredActionBuffers().DiscreteActions;
// default Heuristic implementation should return zero actions.
Assert.AreEqual(new ActionSegment<int>(new[] {0, 0}), actions);
Assert.AreEqual(new ActionSegment<int>(new[] { 0, 0 }), actions);
Assert.AreEqual(1, agent.numHeuristicCalls);
Academy.Instance.EnvironmentStep();

}
}
}
#endif

16
com.unity.ml-agents/Tests/Runtime/Sensor/RayPerceptionSensorTests.cs


using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.TestTools;
namespace Unity.MLAgents.Tests
{

public class RayPerception3DTests
{
[Test]
public void TestDefaultLayersAreNegativeFive()
{
#if MLA_UNITY_PHYSICS_MODULE
Assert.IsTrue(Physics.DefaultRaycastLayers == -5);
#endif
#if MLA_UNITY_PHYSICS2D_MODULE
Assert.IsTrue(Physics2D.DefaultRaycastLayers == -5);
#endif
}
#if MLA_UNITY_PHYSICS_MODULE
// Use built-in tags
const string k_CubeTag = "Player";
const string k_SphereTag = "Respawn";

sphere3.transform.position = new Vector3(0, 0, -10);
sphere3.tag = k_SphereTag;
sphere3.name = "sphere3";
Physics.SyncTransforms();
}

Assert.AreEqual(-1, castOutput.RayOutputs[0].HitTagIndex);
}
}
#endif
}
}

12
com.unity.ml-agents/Tests/Runtime/Sensor/Unity.ML-Agents.Runtime.Sensor.Tests.asmdef


"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [
{
"name": "com.unity.modules.physics",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS_MODULE"
},
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS2D_MODULE"
}
]
}

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


"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [
{
"name": "com.unity.modules.physics",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS_MODULE"
},
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "MLA_UNITY_PHYSICS2D_MODULE"
}
]
}

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


"dependencies": {
"com.unity.barracuda": "1.3.2-preview",
"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.jsonserialize": "1.0.0"
}
}

40
.yamato/com.unity.ml-agents-coverage.yml


{% metadata_file .yamato/coverage_tests.metafile %}
---
{% for package in coverage_test_packages %}
{% for editor in coverage_test_editors %}
{% for platform in coverage_test_platforms %}
{% capture coverageOptions %} --enable-code-coverage --code-coverage-options 'generateHtmlReport;assemblyFilters:+{{ package.assembly }}'{% endcapture %}
test_coverage_{{ package.name }}_{{ platform.name }}_{{ editor.version }}:
name : Coverage {{ package.name }} test {{ editor.version }} on {{ platform.name }}
agent:
type: {{ platform.type }}
image: {{ platform.image }}
flavor: {{ platform.flavor}}
commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --type project-tests --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
artifacts:
logs:
paths:
- "upm-ci~/test-results/**/*"
dependencies:
- .yamato/com.unity.ml-agents-pack.yml#pack
triggers:
cancel_old_ci: true
{% if platform.name == "linux" %}
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 " {{ editor.testProject }}/**" OR
{% if package.name == "com.unity.ml-agents.extensions" %}
pull_request.changes.any match "com.unity.ml-agents.extensions/**" OR
{% endif %}
pull_request.changes.any match ".yamato/com.unity.ml-agents-test.yml")
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}

17
.yamato/coverage_tests.metafile


coverage_test_editors:
- version: 2020.2
testProject: DevProject
coverage_test_platforms:
- name: linux
type: Unity::VM
image: package-ci/ubuntu:stable
flavor: b1.medium
coverage_test_packages:
- name: com.unity.ml-agents
assembly: Unity.ML-Agents
minCoveragePct: 72
- name: com.unity.ml-agents.extensions
assembly: Unity.ML-Agents.Extensions*
minCoveragePct: 75
正在加载...
取消
保存