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

Question Can I get n? in --num-envs=<n>

Discussion in 'ML-Agents' started by AVOlight, Apr 21, 2023.

  1. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    Can I get n within my Unity instances?
    Want to use the index to distribute training data in a convenient and optimized way.
     
  2. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    709
    Try parsing the CLI arguments from each game for the value of
    --mlagents-port
    or
    -logFile
    name.

    Looking at
    environments.py
    the port always starts from 5005:
    Code (CSharp):
    1.     # Default base port for environments. Each environment will be offset from this
    2.     # by it's worker_id.
    3.     BASE_ENVIRONMENT_PORT = 5005
    From the Unity game you should be able to simply read the port number and subtract 5005 to derive the playerID which is the same as "n"

    For instance, running the command:
    mlagents-learn config/config.yaml --run-id=my_robot --env "C:\project\robot_training.exe" --num-envs 2
    Launches two instance of the game.

    And each instance is then passed the arguments:
    Code (CSharp):
    1. ['--mlagents-port', '5005', '-logFile', 'C:\\project\\results\\ai_robot\\run_logs\\Player-0.log']
    2. ['--mlagents-port', '5006', '-logFile', 'C:\\project\\results\\ai_robot\\run_logs\\Player-1.log']
    Using the port number or parsing the log filename are two possibilities.
     
    Last edited: Apr 30, 2023
    AVOlight likes this.
  3. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    Thank you very much! @CloudyVR

    I didn't realize the Player logs were in there
    so your reply has really helped me a lot! Thanks again