Skip to content

Commit

Permalink
docker experience seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
beneisner committed May 14, 2024
1 parent a919560 commit 0ec5f6c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 5 deletions.
58 changes: 57 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y \
# Dependencies required for python.
build-essential \
curl \
ffmpeg \
git \
libbz2-dev \
libffi-dev \
Expand All @@ -24,6 +25,23 @@ RUN apt-get update && apt-get install -y \
tk-dev \
xz-utils \
zlib1g-dev \
# VirtualGL Dependencies.
libc6 \
libglu1-mesa \
libglvnd-dev \
libxv1 \
mesa-utils \
openbox \
wget \
xvfb \
# CoppeliaSim Dependencies.
libglu1-mesa-dev \
'^libxcb.*-dev' \
libxi-dev \
libxkbcommon-dev \
libxkbcommon-x11-dev \
libxrender-dev \
libx11-xcb-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -40,6 +58,33 @@ RUN pyenv global 3.9.12
RUN mkdir $CODING_ROOT/code
WORKDIR $CODING_ROOT/code

# Download CoppeliaSim
RUN mkdir $CODING_ROOT/.coppelia
WORKDIR $CODING_ROOT/.coppelia
RUN curl -L https://www.coppeliarobotics.com/files/V4_1_0/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04.tar.xz -o CoppeliaSim_Edu_V4_1_0_Ubuntu20_04.tar.xz && \
tar -xf CoppeliaSim_Edu_V4_1_0_Ubuntu20_04.tar.xz && \
rm CoppeliaSim_Edu_V4_1_0_Ubuntu20_04.tar.xz

# Set the working directory back to the code directory.
WORKDIR $CODING_ROOT/code

# modify environment variables for coppelia sim
ENV COPPELIASIM_ROOT="$CODING_ROOT/.coppelia/CoppeliaSim_Edu_V4_1_0_Ubuntu20_04"
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$COPPELIASIM_ROOT"
ENV QT_QPA_PLATFORM_PLUGIN_PATH="$COPPELIASIM_ROOT"

# Install VirtualGL
RUN wget --no-check-certificate https://github.com/VirtualGL/virtualgl/releases/download/3.1.1/virtualgl_3.1.1_amd64.deb \
&& dpkg -i virtualgl_*.deb \
&& rm virtualgl_*.deb

# Configure VirtualGL
RUN /opt/VirtualGL/bin/vglserver_config +s +f -t +egl

# Setup environment variables for NVIDIA and VirtualGL
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES all

# Copy in the requirements.
COPY requirements-gpu.txt .

Expand All @@ -54,12 +99,23 @@ COPY third_party third_party
# Install the third-party libraries.
RUN pip install --no-cache-dir -e third_party/ndf_robot

# Install pyrep.
RUN pip install --no-cache-dir --no-build-isolation "pyrep @ git+https://github.com/stepjam/PyRep.git"

# Copy in pyproject.toml.
COPY pyproject.toml .
RUN mkdir taxpose
RUN touch taxpose/py.typed

RUN pip install --no-cache-dir -e ".[develop]"
# Install our project.
RUN pip install --no-cache-dir -e ".[develop,rlbench]"

# Copy in the code.
COPY . .

# Make directories for mounting.
RUN mkdir $CODING_ROOT/data
RUN mkdir $CODING_ROOT/logs

COPY ./docker/entrypoint.sh /opt/baeisner/entrypoint.sh
ENTRYPOINT ["/opt/baeisner/entrypoint.sh"]
26 changes: 26 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Set the display env variable
export DISPLAY=:99
export VGL_DISPLAY="egl"

# Start Xvfb
Xvfb $DISPLAY -screen 0 1024x768x24 -nolisten tcp -nolisten unix +extension GLX > /dev/null 2>&1 &

# Wait a little for Xvfb to start
sleep 2

echo "Xvfb started on display $DISPLAY"

# If VGL_DEVICE is set, then use it. Else use egl0.
if [ -z "$VGL_DEVICE" ]; then
VGL_DEVICE="egl0"
fi

echo "Using VirtualGL device: $VGL_DEVICE"

# Run your OpenGL application with VirtualGL (add +v command if needed.)
vglrun \
-d $VGL_DEVICE \
-ld /opt/baeisner/.pyenv/versions/3.9.12/lib/python3.9/site-packages/torch/lib \
"$@"
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ develop = [
build_docs = ["mkdocs-material", "mkdocstrings[python]"]
rlbench = [
# These should be installed manually...
"pyrep",
"rlbench",

# This can be done automatically.
# "pyrep",
# "rlbench @ git+https://github.com/stepjam/RLBench.git",
"rpad-rlbench-utils @ git+https://github.com/r-pad/rlbench_utils.git",
]

Expand Down
26 changes: 26 additions & 0 deletions scripts/debug_headless.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time

import numpy as np
from rlbench.action_modes.action_mode import MoveArmThenGripper
from rlbench.action_modes.arm_action_modes import JointVelocity
from rlbench.action_modes.gripper_action_modes import Discrete
from rlbench.environment import Environment
from rlbench.tasks import FS10_V1

action_mode = MoveArmThenGripper(
arm_action_mode=JointVelocity(), gripper_action_mode=Discrete()
)
env = Environment(action_mode, headless=True)
env.launch()

train_tasks = FS10_V1["train"]
test_tasks = FS10_V1["test"]
task_to_train = np.random.choice(train_tasks, 1)[0]
task = env.get_task(task_to_train)
task.sample_variation() # random variation
descriptions, obs = task.reset()

# Step for 10s wall clock time
start = time.time()
while time.time() - start < 10:
obs, reward, terminate = task.step(np.random.normal(size=env.action_shape))

0 comments on commit 0ec5f6c

Please sign in to comment.