Skip to content

Commit

Permalink
Address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel Gonzalez committed Aug 20, 2018
1 parent 6409625 commit f51d317
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 187 deletions.
2 changes: 0 additions & 2 deletions docker/Dockerfile.ci
Expand Up @@ -84,8 +84,6 @@ RUN conda env create -f /root/code/garage/environment.yml && \
# Extras
# prevent pip from complaining about available upgrades
RUN ["/bin/bash", "-c", "source activate garage && pip install --upgrade pip"]
# TensorFlow is not in environment.yml because of CPU vs GPU
RUN ["/bin/bash", "-c", "source activate garage && pip install tensorflow==1.8.0"]
# Fix Box2D install
# See https://github.com/openai/gym/issues/100
# See https://github.com/pybox2d/pybox2d/issues/82
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Expand Up @@ -48,7 +48,7 @@ dependencies:
- pyzmq
- scipy
- tensorboard
- tensorflow
- tensorflow<1.10,>=1.9.0
- Theano==1.0.2
# dev dependencies below this line
- git+https://github.com/openai/baselines.git@f2729693253c0ef4d4086231d36e0a4307ec1cb3#egg=baselines
Expand Down
173 changes: 84 additions & 89 deletions scripts/setup_linux.sh
Expand Up @@ -6,6 +6,9 @@
# regarding the installation of dependencies, apply those same changes to the
# mentioned files.

# Exit if any error occurs
set -e

### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
die()
{
Expand All @@ -30,18 +33,19 @@ begins_with_short_option()
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_mjkey=
_arg_modify_bashrc="off"
_arg_tf_gpu="off"
_arg_set_envvar="off"

print_help ()
{
printf '%s\n' "Installer of garage for Linux."
printf 'Usage: %s [--(no-)tf-gpu] [--(no-)set-envvar] ' "$0"
printf '[-h|--help] <mjkey-path>\n' "$0"
printf '\t%s\n' "<mjkey-path>: Path of the MuJoCo key"
printf 'Usage: %s [--mjkey <arg>] [--(no-)modify-bashrc] ' "$0"
printf '[--(no-)tf-gpu] [-h|--help]\n'
printf '\t%s\n' "--mjkey: Path of the MuJoCo key (no default)"
printf '\t%s' "--tf-gpu,--no-tf-gpu: Install TensorFlow GPU instead of the "
printf '%s\n' "regular version (off by default)"
printf '\t%s' "--set-envvar,--no-set-envvar: Set environment variables "
printf '\t%s' "--modify-bashrc,--no-modify-bashrc: Set environment variables "
printf '%s\n' "required by garage in .bashrc (off by default)"
printf '\t%s\n' "-h,--help: Prints help"
}
Expand All @@ -52,14 +56,23 @@ parse_commandline ()
do
_key="$1"
case "$_key" in
--mjkey)
test $# -lt 2 && \
die "Missing value for the optional argument '$_key'." 1
_arg_mjkey="$2"
shift
;;
--mjkey=*)
_arg_mjkey="${_key##--mjkey=}"
;;
--no-modify-bashrc|--modify-bashrc)
_arg_modify_bashrc="on"
test "${1:0:5}" = "--no-" && _arg_modify_bashrc="off"
;;
--no-tf-gpu|--tf-gpu)
_arg_tf_gpu="on"
test "${1:0:5}" = "--no-" && _arg_tf_gpu="off"
;;
--no-set-envvar|--set-envvar)
_arg_set_envvar="on"
test "${1:0:5}" = "--no-" && _arg_set_envvar="off"
;;
-h|--help)
print_help
exit 0
Expand All @@ -69,43 +82,15 @@ parse_commandline ()
exit 0
;;
*)
_positionals+=("$1")
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}


handle_passed_args_count ()
{
_required_args_string="'mjkey-path'"
error_msg="$(echo "FATAL ERROR: Not enough positional arguments - we" \
"require exactly 1 (namely: $_required_args_string), but got only" \
"${#_positionals[@]}.")"
test ${#_positionals[@]} -ge 1 || _PRINT_HELP=yes die "${error_msg}" 1
error_msg="$(echo "FATAL ERROR: There were spurious positional arguments" \
"--- we expect exactly 1 (namely: $_required_args_string), but got" \
"${#_positionals[@]} (the last one was: '${_positionals[*]: -1}').")"
test ${#_positionals[@]} -le 1 || _PRINT_HELP=yes die "${error_msg}" 1
}

assign_positional_args ()
{
_positional_names=('_arg_mjkey_path' )

for (( ii = 0; ii < ${#_positionals[@]}; ii++))
do
error_msg="$(echo "Error during argument parsing, possibly an Argbash" \
"bug.")"
eval "${_positional_names[ii]}=\${_positionals[ii]}" || \
die "${error_msg}" 1
done
}

parse_commandline "$@"
handle_passed_args_count
assign_positional_args
### END OF CODE GENERATED BY Argbash (sortof) ### ])

# Utility functions
Expand All @@ -118,8 +103,8 @@ print_warning() {
}

# Verify there's a file in the mjkey path
test -f "${_arg_mjkey_path}" || _PRINT_HELP=yes die \
"The path ${_arg_mjkey_path} of the MuJoCo key is not valid." 1
test -f "${_arg_mjkey}" || _PRINT_HELP=yes die \
"The path ${_arg_mjkey} of the MuJoCo key is not valid." 1

# Make sure that we're under the garage directory
GARAGE_DIR="$(readlink -f $(dirname $0)/..)"
Expand Down Expand Up @@ -164,19 +149,19 @@ cd "${GLFW_DIR}"
git checkout 0be4f3f75aebd9d24583ee86590a38e741db0904
mkdir glfw-build
cd glfw-build
cmake -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF \
sudo cmake -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF \
-DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF ..
make -j"$(nproc)"
make install
sudo make -j"$(nproc)"
sudo make install
cd "${GARAGE_DIR}"

# Leave a note in ~/.bashrc for the added environment variables
if [[ "${_arg_set_envvar}" = on ]]; then
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo -e "\n# Added by the garage installer" >> "${BASH_RC}"
fi

# Set up MuJoCo
if [[ ! -d "${HOME}"/.mujoco/mjpro150 ]]; then
if [[ ! -d "${HOME}/.mujoco/mjpro150" ]]; then
mkdir "${HOME}"/.mujoco
MUJOCO_ZIP="$(mktemp -d)/mujoco.zip"
wget https://www.roboti.us/download/mjpro150_linux.zip -O "${MUJOCO_ZIP}"
Expand All @@ -188,25 +173,26 @@ fi
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${HOME}/.mujoco/mjpro150/bin"
LD_LIB_ENV_VAR="LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:${HOME}/.mujoco/mjpro150"
LD_LIB_ENV_VAR="${LD_LIB_ENV_VAR}/bin\""
if [[ "${_arg_set_envvar}" = on ]]; then
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo "export ${LD_LIB_ENV_VAR}" >> "${BASH_RC}"
fi

# Set up conda
hash conda 2>/dev/null || {
if [[ ! -d "${HOME}/miniconda2" ]]; then
CONDA_INSTALLER="$(mktemp -d)/miniconda.sh"
sudo chmod u+x "${CONDA_INSTALLER}"
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh \
-O "${CONDA_INSTALLER}"
sudo bash "${CONDA_INSTALLER}" -b
chmod u+x "${CONDA_INSTALLER}"
bash "${CONDA_INSTALLER}" -b -u
# Add conda to executable programs
CONDA_PATH="${HOME}/miniconda2/bin/"
export PATH="$PATH:${CONDA_PATH}"
PATH_ENV_VAR="PATH=\"\$PATH:${CONDA_PATH}\""
if [[ "${_arg_set_envvar}" = on ]]; then
echo "export ${PATH_ENV_VAR}" >> "${BASH_RC}"
CONDA_SH="${HOME}/miniconda2/etc/profile.d/conda.sh"
. "${CONDA_SH}"
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo ". ${CONDA_SH}" >> "${BASH_RC}"
fi
}
fi
# Export conda in this script
. "${CONDA_SH}"
conda update -q -y conda

# Create conda environment
Expand All @@ -216,47 +202,56 @@ if [[ "${?}" -ne 0 ]]; then
fi

# Extras
source activate garage
# Prevent pip from complaining about available upgrades
pip install --upgrade pip
# TensorFlow is not in environment.yml because of CPU vs GPU
# Remove any TensorFlow installations before installing the desired flavor
pip uninstall -y tensorflow tensorflow-gpu
if [[ "${_arg_tf_gpu}" = on ]]; then
pip install tensorflow-gpu
else
pip install tensorflow
fi
# Fix Box2D install
# See https://github.com/openai/gym/issues/100
# See https://github.com/pybox2d/pybox2d/issues/82
pip uninstall -y Box2D Box2D-kengz box2d-py
pip install Box2D
# We need a MuJoCo key to import mujoco_py
cp ${_arg_mjkey_path} "${HOME}"/.mujoco/mjkey.txt
python -c 'import mujoco_py'
# Set up pre-commit in local repo
pre-commit install -t pre-commit
pre-commit install -t pre-push
pre-commit install -t commit-msg
source deactivate
conda activate garage
{
# Prevent pip from complaining about available upgrades
pip install --upgrade pip

# Remove any TensorFlow installations before installing the GPU flavor
pip uninstall -y tensorflow
if [[ "${_arg_tf_gpu}" = on ]]; then
pip install "tensorflow-gpu<1.10,>=1.9.0"
fi

# Fix Box2D install
# See https://github.com/openai/gym/issues/100
# See https://github.com/pybox2d/pybox2d/issues/82
pip uninstall -y Box2D Box2D-kengz box2d-py
pip install Box2D

# We need a MuJoCo key to import mujoco_py
cp ${_arg_mjkey} "${HOME}"/.mujoco/mjkey.txt

# Build mujoco-py and check it's correctly installed
python -c 'import mujoco_py'

# Install git hooks
pre-commit install -t pre-commit
pre-commit install -t pre-push
pre-commit install -t commit-msg

# Install a virtualenv for the hooks
pre-commit
}
conda deactivate

# Copy template of personal configurations so users can set them later
cp garage/config_personal_template.py garage/config_personal.py

# Add garage to python modules
export PYTHONPATH="$PYTHONPATH:${GARAGE_DIR}"
PYTHON_ENV_VAR="PYTHONPATH=\"\$PYTHONPATH:${GARAGE_DIR}\""
if [[ "${_arg_set_envvar}" = on ]]; then
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo "export ${PYTHON_ENV_VAR}" >> "${BASH_RC}"
else
echo -e "\nRemember to export the following environment variables before" \
"running garage:"
echo "${LD_LIB_ENV_VAR}"
echo "${PATH_ENV_VAR}"
echo "${PYTHON_ENV_VAR}"
echo "You may wish to edit your .bashrc to prepend the exports of these" \
"environment variables."
echo -e "\nRemember to execute the following commands before running garage:"
echo "export ${LD_LIB_ENV_VAR}"
echo ". ${CONDA_SH}"
echo "export ${PYTHON_ENV_VAR}"
echo "You may wish to edit your .bashrc to prepend these commands."
fi

echo -e "\nGarage is installed! To make the changes take effect, work under" \
"a new terminal. Also, make sure to run \`source activate garage\`" \
echo -e "\ngarage is installed! To make the changes take effect, work under" \
"a new terminal. Also, make sure to run \`conda activate garage\`" \
"whenever you open a new terminal and want to run programs under garage." \
| fold -s

0 comments on commit f51d317

Please sign in to comment.