Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

On the use of actionMask with python API

Discussion in 'ML-Agents' started by sb1995282, Jul 28, 2021.

  1. sb1995282

    sb1995282

    Joined:
    Jun 3, 2021
    Posts:
    4
    I am unable to use ActionMask when controling an agent through the python API. Let's say I set some actions enabled or disabled with the script:
    Code (CSharp):
    1. public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
    2.     {
    3.         actionMask.SetActionEnabled(1, 1, false);
    4.         actionMask.SetActionEnabled(1, 0, true);
    5.         actionMask.SetActionEnabled(2, 2, false);
    6.         actionMask.SetActionEnabled(2, 4, true);
    7.     }
    When I access the actionMask through the python API :

    Code (Python):
    1. decision_steps, terminal_steps = env.get_steps(behavior_name)
    2. decision_step = decision_steps[0]
    3. decision_step.action_mask
    I get only false values :

    [array([False, False]), array([False, False]), array([False, False, False, False, False, False, False, False, False,
    False, False, False]), array([False, False, False, False, False, False, False]), array([False, False, False, False, False, False, False, False, False, False, False, False]), array([False, False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False]), array([False, False])]

    What am I doing wrong ?
    I am using ML-Agents 2.0 and 2.1.
    Thank you for your help.
     
    Last edited: Jul 29, 2021
  2. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    134
    Can you reproduce this error with any of our example environments? I verified with our GridWorld environment and the results looks normal with action being properly masked
     
  3. sb1995282

    sb1995282

    Joined:
    Jun 3, 2021
    Posts:
    4
    Do you mean the GridWorld in the example learning environments ? If so, I kept only one agent of this environment and created an executable on which I tested the python API. Though I can move the square, at each iteration decision_step.action_mask only returns [array([False, False, False, False, False])]. I'm not sure what I am doing wrong. I'm really just a rookie at this. Do you know of a notebook I could run to test this so we could know beyond any doubt whether my code is the problem ? Thank you for any assistance.