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

Initial implementation using IHeuristicProvider. #4849

Merged
merged 27 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1cd526a
Initial implementation using IHeuristic.
surfnerd Jan 12, 2021
6a45d35
Remove some 'style' changes.
surfnerd Jan 12, 2021
8382acf
Fix the fix.
surfnerd Jan 12, 2021
866e826
Send ActuatorManager to HeuristicPolicy. Have VectorActuator call in…
surfnerd Jan 13, 2021
5917d20
Update com.unity.ml-agents/Runtime/Actuators/IHeuristicProvider.cs
surfnerd Jan 13, 2021
9313864
Update com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
surfnerd Jan 13, 2021
5c028e6
Pass ActuatorManager directly to HeuristicPolicy and PolicyFactory.
surfnerd Jan 13, 2021
e30f643
Revert some logic.
surfnerd Jan 13, 2021
4d72bcb
Update changelog.
surfnerd Jan 13, 2021
3bb3f17
Add tests.
surfnerd Jan 13, 2021
b336c72
Merge branch 'master' into develop-heuristic-interface
surfnerd Jan 14, 2021
35dd22b
Use actuator heuristic for basic scene.
surfnerd Jan 14, 2021
c9245e0
Rename Match3 -> Board for extension classes.
surfnerd Jan 14, 2021
2542348
Fix comments to remove Match3.
surfnerd Jan 14, 2021
640a1bf
Update match3 examples and extensions to use actuators.
surfnerd Jan 15, 2021
6c1761e
Update tests.
surfnerd Jan 15, 2021
55d4348
Update changelog and migrating docs.
surfnerd Jan 15, 2021
511ffc3
Install wheel package to fix error in yamato.
surfnerd Jan 15, 2021
f771e3b
Do not clear heuristic action buffer.
surfnerd Jan 15, 2021
550c74c
Order of operations.
surfnerd Jan 15, 2021
4b1c3e6
Undo renames.
surfnerd Jan 15, 2021
5639930
Make sure all references to 'Board' namespace/directories/comments ar…
surfnerd Jan 19, 2021
67571f4
Remove Heuristic Quality. Move the random seed out of the extension …
surfnerd Jan 19, 2021
797c2fd
Rename ActuatorManager.Heuristic to ActuatorManager.ApplyHeuristic.
surfnerd Jan 19, 2021
7b3be45
More Board reverts.
surfnerd Jan 19, 2021
a872085
Merge branch 'master' into develop-heuristic-interface
surfnerd Jan 19, 2021
8d91dde
Fix comment doc.
surfnerd Jan 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .yamato/gym-interface-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test_gym_interface_{{ editor.version }}:
- |
sudo apt-get update && sudo apt-get install -y python3-venv
python3 -m venv venv && source venv/bin/activate
python -m pip install wheel --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
python -m pip install pyyaml --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
python -u -m ml-agents.tests.yamato.setup_venv
python ml-agents/tests/yamato/scripts/run_gym.py --env=artifacts/testPlayer-Basic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Unity.MLAgents.Actuators;
using UnityEngine;

namespace Unity.MLAgentsExamples
{
Expand Down Expand Up @@ -30,7 +31,7 @@ public override ActionSpec ActionSpec
/// <summary>
/// Simple actuator that converts the action into a {-1, 0, 1} direction
/// </summary>
public class BasicActuator : IActuator
public class BasicActuator : IActuator, IHeuristicProvider
{
public BasicController basicController;
ActionSpec m_ActionSpec;
Expand Down Expand Up @@ -76,6 +77,19 @@ public void OnActionReceived(ActionBuffers actionBuffers)
basicController.MoveDirection(direction);
}

public void Heuristic(in ActionBuffers actionBuffersOut)
{
var direction = Input.GetAxis("Horizontal");
var discreteActions = actionBuffersOut.DiscreteActions;
if (Mathf.Approximately(direction, 0.0f))
{
discreteActions[0] = 0;
return;
}
var sign = Math.Sign(direction);
discreteActions[0] = sign < 0 ? 1 : 2;
}

public void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ GameObject:
- component: {fileID: 3508723250470608012}
- component: {fileID: 3508723250470608011}
- component: {fileID: 3508723250470608009}
- component: {fileID: 3508723250470608013}
- component: {fileID: 3508723250470608014}
- component: {fileID: 2112317463290853299}
m_Layer: 0
m_Name: Match3 Agent
m_TagString: Untagged
Expand Down Expand Up @@ -51,9 +51,13 @@ MonoBehaviour:
m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes:
VectorActionSize:
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: c34da50737a3c4a50918002b20b2b927, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
Expand Down Expand Up @@ -81,7 +85,6 @@ MonoBehaviour:
Board: {fileID: 0}
MoveTime: 0.25
MaxMoves: 500
HeuristicQuality: 0
--- !u!114 &3508723250470608011
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -96,7 +99,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
DebugMoveIndex: -1
CubeSpacing: 1.25
Board: {fileID: 0}
TilePrefab: {fileID: 4007900521885639951, guid: faee4e805953b49e688bd00b45c55f2e,
type: 3}
--- !u!114 &3508723250470608009
Expand All @@ -119,7 +121,7 @@ MonoBehaviour:
BasicCellPoints: 1
SpecialCell1Points: 2
SpecialCell2Points: 3
--- !u!114 &3508723250470608013
--- !u!114 &3508723250470608014
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -128,12 +130,12 @@ MonoBehaviour:
m_GameObject: {fileID: 3508723250470608007}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 08e4b0da54cb4d56bfcbae22dd49ab8d, type: 3}
m_Script: {fileID: 11500000, guid: 530d2f105aa145bd8a00e021bdd925fd, type: 3}
m_Name:
m_EditorClassIdentifier:
ActuatorName: Match3 Actuator
ForceHeuristic: 1
--- !u!114 &3508723250470608014
SensorName: Match3 Sensor
ObservationType: 0
--- !u!114 &2112317463290853299
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -142,11 +144,12 @@ MonoBehaviour:
m_GameObject: {fileID: 3508723250470608007}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 530d2f105aa145bd8a00e021bdd925fd, type: 3}
m_Script: {fileID: 11500000, guid: b17adcc6c9b241da903aa134f2dac930, type: 3}
m_Name:
m_EditorClassIdentifier:
SensorName: Match3 Sensor
ObservationType: 0
ActuatorName: Match3 Actuator
ForceHeuristic: 1
HeuristicQuality: 0
--- !u!1 &3508723250774301855
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ GameObject:
- component: {fileID: 2118285884327540682}
- component: {fileID: 2118285884327540685}
- component: {fileID: 2118285884327540687}
- component: {fileID: 2118285884327540683}
- component: {fileID: 2118285884327540680}
- component: {fileID: 3357012711826686276}
m_Layer: 0
m_Name: Match3 Agent
m_TagString: Untagged
Expand Down Expand Up @@ -82,9 +82,13 @@ MonoBehaviour:
m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes:
VectorActionSize:
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 9e89b8e81974148d3b7213530d00589d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
Expand Down Expand Up @@ -112,7 +116,6 @@ MonoBehaviour:
Board: {fileID: 0}
MoveTime: 0.25
MaxMoves: 500
HeuristicQuality: 0
--- !u!114 &2118285884327540685
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -127,7 +130,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
DebugMoveIndex: -1
CubeSpacing: 1.25
Board: {fileID: 0}
TilePrefab: {fileID: 4007900521885639951, guid: faee4e805953b49e688bd00b45c55f2e,
type: 3}
--- !u!114 &2118285884327540687
Expand All @@ -150,7 +152,7 @@ MonoBehaviour:
BasicCellPoints: 1
SpecialCell1Points: 2
SpecialCell2Points: 3
--- !u!114 &2118285884327540683
--- !u!114 &2118285884327540680
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -159,12 +161,12 @@ MonoBehaviour:
m_GameObject: {fileID: 2118285884327540673}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 08e4b0da54cb4d56bfcbae22dd49ab8d, type: 3}
m_Script: {fileID: 11500000, guid: 530d2f105aa145bd8a00e021bdd925fd, type: 3}
m_Name:
m_EditorClassIdentifier:
ActuatorName: Match3 Actuator
ForceHeuristic: 0
--- !u!114 &2118285884327540680
SensorName: Match3 Sensor
ObservationType: 0
--- !u!114 &3357012711826686276
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -173,8 +175,9 @@ MonoBehaviour:
m_GameObject: {fileID: 2118285884327540673}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 530d2f105aa145bd8a00e021bdd925fd, type: 3}
m_Script: {fileID: 11500000, guid: b17adcc6c9b241da903aa134f2dac930, type: 3}
m_Name:
m_EditorClassIdentifier:
SensorName: Match3 Sensor
ObservationType: 0
ActuatorName: Match3 Actuator
ForceHeuristic: 0
HeuristicQuality: 0
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ GameObject:
- component: {fileID: 3019509692332007781}
- component: {fileID: 3019509692332007778}
- component: {fileID: 3019509692332007776}
- component: {fileID: 3019509692332007780}
- component: {fileID: 3019509692332007783}
- component: {fileID: 8270768986451624427}
m_Layer: 0
m_Name: Match3 Agent
m_TagString: Untagged
Expand Down Expand Up @@ -82,9 +82,13 @@ MonoBehaviour:
m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes:
VectorActionSize:
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 48d14da88fea74d0693c691c6e3f2e34, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
Expand Down Expand Up @@ -112,7 +116,6 @@ MonoBehaviour:
Board: {fileID: 0}
MoveTime: 0.25
MaxMoves: 500
HeuristicQuality: 0
--- !u!114 &3019509692332007778
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -127,7 +130,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
DebugMoveIndex: -1
CubeSpacing: 1.25
Board: {fileID: 0}
TilePrefab: {fileID: 4007900521885639951, guid: faee4e805953b49e688bd00b45c55f2e,
type: 3}
--- !u!114 &3019509692332007776
Expand All @@ -150,7 +152,7 @@ MonoBehaviour:
BasicCellPoints: 1
SpecialCell1Points: 2
SpecialCell2Points: 3
--- !u!114 &3019509692332007780
--- !u!114 &3019509692332007783
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -159,12 +161,12 @@ MonoBehaviour:
m_GameObject: {fileID: 3019509692332007790}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 08e4b0da54cb4d56bfcbae22dd49ab8d, type: 3}
m_Script: {fileID: 11500000, guid: 530d2f105aa145bd8a00e021bdd925fd, type: 3}
m_Name:
m_EditorClassIdentifier:
ActuatorName: Match3 Actuator
ForceHeuristic: 0
--- !u!114 &3019509692332007783
SensorName: Match3 Sensor
ObservationType: 2
--- !u!114 &8270768986451624427
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -173,8 +175,9 @@ MonoBehaviour:
m_GameObject: {fileID: 3019509692332007790}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 530d2f105aa145bd8a00e021bdd925fd, type: 3}
m_Script: {fileID: 11500000, guid: b17adcc6c9b241da903aa134f2dac930, type: 3}
m_Name:
m_EditorClassIdentifier:
SensorName: Match3 Sensor
ObservationType: 2
ActuatorName: Match3 Actuator
ForceHeuristic: 0
HeuristicQuality: 0
10 changes: 10 additions & 0 deletions Project/Assets/ML-Agents/Examples/Match3/Scenes/Match3.unity
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,11 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2112317463290853299, guid: 2fafdcd0587684641b03b11f04454f1b,
type: 3}
propertyPath: HeuristicQuality
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3508723250470608011, guid: 2fafdcd0587684641b03b11f04454f1b,
type: 3}
propertyPath: cubeSpacing
Expand Down Expand Up @@ -1385,6 +1390,11 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2112317463290853299, guid: 2fafdcd0587684641b03b11f04454f1b,
type: 3}
propertyPath: HeuristicQuality
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3508723250470608011, guid: 2fafdcd0587684641b03b11f04454f1b,
type: 3}
propertyPath: cubeSpacing
Expand Down
Loading