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.
- A server without X server and root access, mine is one which provides Jupyter Lab only.
- Ubuntu rootfs where Xvfb is installed.
- ML-Agents environment for testing.
- Static proot binary.
- Upload ubuntu rootfs to server and uncompress.
- Upload ML-Agents environment to server and uncompress to a directory in rootfs.
- Download proot binary to server, rename to proot for convenience.
- 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
- 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
- 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()
- Enjoy it : )