Skip to content

gdhy9064/Unity-ML-Agents-for-python-API-without-X-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Unity ML-Agents for python mlagents API without X server

Background

  As we know, the environments of Unity ML-Agents are always along with GUI, which are hardly to run in the servers without X server when we don't have root access. Here I find a way to run ML-Agents with two tools, Proot and Xvfb.

Environment

  • A server without X server and root access, mine is one which provides Jupyter Lab only.

Preparations

  1. Ubuntu rootfs where Xvfb is installed.
  2. ML-Agents environment for testing.
  3. Static proot binary.

Guide

  1. Upload ubuntu rootfs to server and uncompress.
  2. Upload ML-Agents environment to server and uncompress to a directory in rootfs.
  3. Download proot binary to server, rename to proot for convenience.
  4. Run the command below to start Xvfb with display :1. The flag PROOT_NO_SECCOMP will received by proot, which means the kernel of my server is under SECCOMP mode. Without this flag, mine will raise error like 'proot info: pid 4349: terminated with signal 11'. The argument -b /dev means to bind /dev to the root of rootfs, as well as -r ./ubuntu-rootfs/ means use ./ubuntu-rootfs/ as new root. Next is the command you want to run.

PROOT_NO_SECCOMP=1 ./proot -b /dev -b /proc -r ./ubuntu-rootfs/ Xvfb :1 -screen 0 800x800x16

  1. New a file to customize our own ML-Agents script for python mlagents API as follows. Such as a file named 'myrollerball.x86_64'. The suffix of file is significant for python mlagents API to identify. When python mlagents API run this script, mlagents will pass two arguments, --mlagents-port and {the port you used}, which we receive with $1 and $2 and pass to real ML-Agents binary.
#!/bin/sh
export PROOT_NO_SECCOMP=1
export DISPLAY=:1
./proot -b /proc -b /dev -r ./ubuntu-rootfs/ /linux/rollerball.x86_64 $1 $2
  1. Use python mlagents API to connect with ML-Agents environment as follows.
from mlagents_envs.environment import UnityEnvironment

env_name = './myrollerball.x86_64'

env = UnityEnvironment(file_name=env_name, base_port=5004)
env.reset()
  1. Enjoy it : )

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published