Skip to content

Commit 0947443

Browse files
jagapioutkoeppe
authored andcommitted
[install.sh, README.md] New installation script, README.md update.
1 parent de0d047 commit 0947443

File tree

2 files changed

+132
-5
lines changed

2 files changed

+132
-5
lines changed

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ If you use *DeepMind Lab2D* in your research and would like to cite it, we
2121
suggest you cite the
2222
[accompanying whitepaper](https://arxiv.org/abs/2011.07027).
2323

24+
## Installation
25+
26+
[![PyPI version](https://img.shields.io/pypi/v/dmlab2d.svg)](https://pypi.python.org/pypi/dmlab2d)
27+
28+
[*DeepMind Lab2d* is available on PyPI](https://pypi.python.org/pypi/dmlab2d)
29+
and can be installed using:
30+
31+
```shell
32+
pip install dmlab2d
33+
```
34+
35+
`dmlab2d` is distributed as pre-built wheels for Linux and macOS. If there is no
36+
appropriate wheel for your platform, you will need to build it from source. See
37+
[`install.sh`](install.sh) for an example installation script that can be
38+
adapted to your setup.
39+
2440
## Getting started
2541

2642
We provide an example "random" agent in `python/random_agent`, which performs
@@ -33,22 +49,23 @@ bazel run -c opt dmlab2d/random_agent -- --level_name=clean_up
3349

3450
## External dependencies, prerequisites and porting notes
3551

36-
*DeepMind Lab2D* currently ships as source code only. It depends on a few
37-
external software libraries, which we ship in several different ways:
52+
*DeepMind Lab2D* depends on a few external software libraries, which we ship in
53+
several different ways:
3854

3955
* The `dm_env`, `eigen`, `luajit`, `lua5.1`, `lua5.2`, `luajit`, `png`
4056
and `zlib` libraries are referenced as external Bazel sources, and Bazel
4157
BUILD files are provided. The dependent code itself should be fairly
42-
portable, but the BUILD rules we ship are specific to Linux on x86. To build
43-
on a different platform you will most likely have to edit those BUILD files.
58+
portable, and the BUILD rules we ship are specific to Linux x86 and
59+
MacOS (x86 and arm64). To build on a different platform you will most likely
60+
have to edit those BUILD files.
4461

4562
* A "generic reinforcement learning API" is included in
4663
[`//third_party/rl_api`](third_party/rl_api).
4764

4865
* Several additional libraries are required but are not shipped in any form;
4966
they must be present on your system:
5067

51-
* `Python 3.6` or above with `NumPy`, `PyGame`, and `packaging`.
68+
* `Python 3.8` or above with `NumPy`, `PyGame`, and `packaging`.
5269

5370
The build rules are using a few compiler settings that are specific to
5471
GCC/Clang. If some flags are not recognized by your compiler (typically those

install.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2023 DeepMind Technologies Limited.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Installs dmlab2d from source on Linux/macOS.
18+
19+
set -euxo pipefail
20+
21+
function check_version_gt() {
22+
local required="$1"
23+
local input lowest
24+
input="$(grep -Eo '[0-9]+\.[0-9]+' /dev/stdin | head -n 1)"
25+
lowest="$(printf "${required}\n${input}" | sort -V | head -n 1)"
26+
[[ ${lowest} == ${required} ]]
27+
}
28+
29+
function check_setup() {
30+
echo -e "\nChecking OS is Linux or macOS..."
31+
uname -a
32+
[[ "$(uname -s)" =~ (Linux|Darwin) ]]
33+
34+
echo -e "\nChecking python version..."
35+
python --version | tee /dev/stdout | check_version_gt '3.8'
36+
37+
echo -e "\nChecking pip version..."
38+
pip install --upgrade pip
39+
pip --version | tee /dev/stdout | check_version_gt '20.3'
40+
41+
echo -e "\nChecking clang version ..."
42+
clang --version | tee /dev/stdout | check_version_gt '14.0'
43+
44+
echo -e "\nChecking bazel version..."
45+
bazel --version | tee /dev/stdout | check_version_gt '6.2'
46+
}
47+
48+
function install_dmlab2d() {
49+
echo -e "\nInstalling dmlab2d requirements..."
50+
pip install packaging
51+
52+
echo -e "\nBuilding dmlab2d wheel..."
53+
case "$(uname -srp)" in
54+
Linux*)
55+
local -r EXTRA_CONFIG=(
56+
--linkopt=-fuse-ld=lld
57+
)
58+
;;
59+
'Darwin 22.'*arm)
60+
local -r EXTRA_CONFIG=(
61+
--config=libc++
62+
--config=macos_arm64
63+
--repo_env=PY_PLATFORM_OVERRIDE=macosx_13_0_arm64
64+
)
65+
;;
66+
'Darwin 21.'*arm)
67+
local -r EXTRA_CONFIG=(
68+
--config=libc++
69+
--config=macos_arm64
70+
--repo_env=PY_PLATFORM_OVERRIDE=macosx_12_0_arm64
71+
)
72+
;;
73+
Darwin*i386)
74+
local -r EXTRA_CONFIG=(
75+
--config=libc++
76+
--config=macos
77+
)
78+
;;
79+
*)
80+
echo "ERROR: no supported config for ${platform}..." >&2
81+
exit 1
82+
;;
83+
esac
84+
C=clang CXX=clang++ bazel --bazelrc=.bazelrc build \
85+
--compilation_mode=opt \
86+
--dynamic_mode=off \
87+
--config=luajit \
88+
"${EXTRA_CONFIG[@]}" \
89+
--subcommands \
90+
--verbose_failures \
91+
--experimental_ui_max_stdouterr_bytes=-1 \
92+
--sandbox_debug \
93+
//dmlab2d:dmlab2d_wheel
94+
95+
echo -e "\nInstalling dmlab2d..."
96+
pip install -vvv --find-links=bazel-bin/dmlab2d dmlab2d
97+
}
98+
99+
function test_dmlab2d() {
100+
echo -e "\nTesting dmlab2d..."
101+
python dmlab2d/dmlab2d_test.py
102+
}
103+
104+
function main() {
105+
check_setup
106+
install_dmlab2d
107+
test_dmlab2d
108+
}
109+
110+
main "$@"

0 commit comments

Comments
 (0)