Initial Setup#
Follow LabGym’s installation instructions for your operating system, up to but NOT including the installation of
pipx
. After following these instructions, you should have the following installed:Git
A C/C++ Compiler
Python 3.10
CUDA 11.8 (if using GPU)
cuDNN (if using GPU)
Install Python 3.9 using the OS-specific installation instructions described in Step 1. If you’re on Windows, install Python 3.9 from this link.
Important
It’s necessary to have both Python 3.9 and 3.10 installed in order to test LabGym on both versions of Python. This will ensure that, for example, you don’t accidentally use a feature of Python that is compatible with Python 3.10 but not Python 3.9, introducing an incompatibility for the users.
Issue the following commands to properly configure Git. For more information on editor configuration, please see this source.
$ git config --global user.name "First Last" $ git config --global user.email "name@example.com" $ git config --global core.editor editorname
Create a GitHub account, then clone the repository.
If you are a member of the Ye Lab, please send a Slack message to Henry Hu to add you to the “umyelab” organization on GitHub. This will give you access to make changes directly to the LabGym repository. Once you have access, navigate to the directory where you store your code on your local machine using
cd
, then use the following command to clone the repository.$ git clone https://github.com/umyelab/LabGym.git
If you aren’t a member of the Ye Lab, create a fork by clicking the “Fork” button on LabGym’s GitHub page. Then, clone the repository using the following command.
$ git clone https://github.com/<your-github-username>/LabGym.git
Move into the LabGym directory, create a virtual environment, and activate it.
$ cd LabGym $ python3.10 -m venv .venv $ source .venv/bin/activate
> cd LabGym > py -3.10 -m venv .venv > .venv\bin\activate
Install LabGym’s dependencies in the virtual environment.
$ python -m pip install -e .
Note
Since you’re in a virtual environment, you should no longer need to use the OS-specific
python
commands.This command uses
pip
to install all the dependencies listed in LabGym’spyproject.toml
file, which is located in the current directory (hence the.
). The-e
flag installs LabGym in “editable mode”, which means the code is kept in place for you to make changes to.If you’re on Windows or Linux, install PyTorch. If you’re on macOS, PyTorch will already be installed.
$ python -m pip install --index-url https://download.pytorch.org/whl/cu118 torch==2.0.1 torchvision==0.15.2
$ python -m pip install --index-url https://download.pytorch.org/whl/cpu torch==2.0.1 torchvision==0.15.2
Install Detectron2.
$ python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
On Windows, you will need to configure your Detectron2 installation for GPU use.
First, download the Detectron2 code using the following command.
> git clone https://github.com/facebookresearch/detectron2.git
The code will now be present in a
detectron2
subfolder within the LabGym folder.If you’re using a GPU, open the
setup.py
file inside thedetectron2
folder using your text editor (e.g. VS Code) and make the following change.Old version:
72if not is_rocm_pytorch: 73 define_macros += [("WITH_CUDA", None)] 74 extra_compile_args["nvcc"] = [ 75 "-O3", 76 "-DCUDA_HAS_FP16=1", 77 "-D__CUDA_NO_HALF_OPERATORS__", 78 "-D__CUDA_NO_HALF_CONVERSIONS__", 79 "-D__CUDA_NO_HALF2_OPERATORS__", 80 ] 81else: 82 define_macros += [("WITH_HIP", None)] 83 extra_compile_args["nvcc"] = []
New version:
72if not is_rocm_pytorch: 73 define_macros += [("WITH_CUDA", None)] 74 extra_compile_args["nvcc"] = [ 75 "-O3", 76 "-DCUDA_HAS_FP16=1", 77 "-D__CUDA_NO_HALF_OPERATORS__", 78 "-D__CUDA_NO_HALF_CONVERSIONS__", 79 "-D__CUDA_NO_HALF2_OPERATORS__", 80 "-DWITH_CUDA", 81 ] 82else: 83 define_macros += [("WITH_HIP", None)] 84 extra_compile_args["nvcc"] = []
Save the
setup.py
file, then exit your text editor.Finally, reopen your terminal,
cd
to the main LabGym folder, then install Detectron2.> set CUDA_HOME=%CUDA_HOME_V11_8% > python -m pip install -e detectron2
Test your setup by launching LabGym. If the LabGym GUI shows up, your setup is successful!
$ python -m LabGym
Note
Launching LabGym while developing is intentionally different than launching LabGym as a user. If you wanted to launch LabGym using the
LabGym
command, you would need to runpython -m pip install -e .
each time you made changes.Launching LabGym through
python -m LabGym
runs the__main__.py
file, which allows you to immediately see the results of your changes.Install
nox
, the development workflow runner for LabGym.$ python -m pip install nox
Install Ruff, a linter and formatter for Python. If you’re using VS Code, you can install the Ruff VS Code Extension.
Then, configure your editor to format your code on save using Ruff. For example, on VS Code, you can add the following to your User
settings.json
:"[python]": { "editor.defaultFormatter": "charliermarsh.ruff" "editor.formatOnSave": true }