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.

Syntax error: can't assign to operator when training with executable

Discussion in 'ML-Agents' started by KNRichardson, Jul 31, 2020.

  1. KNRichardson

    KNRichardson

    Joined:
    Jul 20, 2020
    Posts:
    6
    Hi, any idea why I'm getting this syntax error when I try to initiate training on a build from the terminal?

    >>> mlagents-learn /config/ppo/Basic.yaml --env=basictest --run-id=firstRun
    File "<stdin>", line 1
    SyntaxError: can't assign to operator


    I am running the command from the root of the project directory (master-ml-agents if you like), which is where all the cloned directories are (ml-agents, ml-agents-envs etc) including the config folder and including the executable, named basictest.x86_64, and the associated data folder.

    Before this command I'd ran
    python
    >>> from mlagents_envs.environment import UnityEnvironment
    >>> env = UnityEnvironment(file_name='basictest.x86_64')
    >>> env.reset()

    and that works in terms of producing a pop up window showing the basic environment.

    I am on Linux Ubuntu 18.04, Unity 2019.4.4f1. I created a pipenv with Python 3.6, cloned the ML-Agents repo and did pip install -e for ml-agents, ml-agents-envs and gym-unity (all 0.18.0 and tensorflow 2.2.0 was installed as dependency).

    I've tried using the full file path to the build from home drive instead of just build name. I've tried 'Basic' instead of 'basictest'. I've looked at the migration document outlining the config format changes and tried the script upgrade_config.py but it returns an identical yaml file so I think the format I have is up to date. I've tried taking the first line 'behavior:' out of Basic.yaml. Can't figure it out.
     
  2. celion_unity

    celion_unity

    Unity Technologies

    Joined:
    Jun 12, 2019
    Posts:
    289
    Hi,
    mlagents-learn is a console script that gets created when you install the pip package. It looks like you're trying to run it from the python interpreter, which isn't working because that's not valid python code.

    mlagents-learn is meant to be run from the command line, but if you really really want to run it from the interpreter, the equivalent to what you're trying to do would be

    Code (CSharp):
    1. >>> from mlagents.trainers.learn import run_cli, parse_command_line
    2. >>> run_cli(parse_command_line(["/config/ppo/Basic.yaml", "--env=basictest", "--run-id=firstRun"])
    Which is what happens when learn.py is run as the main method here.

    Also note that you probably want
    ./config/ppo/Basic.yaml
    (leading
    .
    )
     
  3. KNRichardson

    KNRichardson

    Joined:
    Jul 20, 2020
    Posts:
    6
    Hi,

    Yep, very obvious now you point it out. Thanks a lot!
     
  4. HarshaMusunuri

    HarshaMusunuri

    Joined:
    Jun 16, 2020
    Posts:
    2
    Hello @KNRichardson @celion_unity . I did env.reset() it is still stuck on the black screen. Could you please help me knowing how you resolved it ? :)