Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3.9 #160

Merged
merged 19 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
19ef3c7
[ci] Enable test workflows on Python 3.9.
ChrisCummins Mar 30, 2021
6b8aeda
Bump grpcio from 1.34 to 1.36.
ChrisCummins Mar 30, 2021
390ce35
Bump bazel requirement to 4.0.0.
ChrisCummins Mar 30, 2021
2967b82
[ci] Reverse order of sudo in setup.
ChrisCummins Mar 30, 2021
1c5c750
Add libjpeg-dev to list of required linux packages.
ChrisCummins Mar 30, 2021
77bf4d4
Bump the gym dependency to 0.18.0.
ChrisCummins Mar 30, 2021
890df9d
[examples] Fix initialization of temporary directory variable.
ChrisCummins Mar 30, 2021
f07c30e
Add zlib to macOS dependencies.
ChrisCummins Mar 30, 2021
2a3bc1f
[readme] Recommend python 3.9 for conda environments.
ChrisCummins Mar 30, 2021
503b3c5
[ci] Use python 3.9 for continuous integration jobs.
ChrisCummins Mar 30, 2021
d33852d
[setup.py] Add a list of supported python versions
ChrisCummins Mar 30, 2021
560872a
[setup.py] Bump development status to Alpha.
ChrisCummins Mar 30, 2021
a5b2b7e
[README] Use non-sudo instructions for linux setup.
ChrisCummins Mar 31, 2021
ab6c018
[README] Simplify table of contents.
ChrisCummins Mar 31, 2021
6ea1267
[README] Use syntax highlighting for installation instructions.
ChrisCummins Mar 31, 2021
768ad1c
[README] Small tweak to wording.
ChrisCummins Mar 31, 2021
5c48161
[README] Use -U in pip install example.
ChrisCummins Mar 31, 2021
97a460b
[README] Don't use '$' prefix on shell commands.
ChrisCummins Mar 31, 2021
d21a015
[README] Add explicit "proceed to all platforms" below.
ChrisCummins Mar 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
4.0.0
26 changes: 17 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python: [3.6, 3.7, 3.8]
python: [3.6, 3.7, 3.8, 3.9]
exclude:
# Only test recent python versions on macOS.
- os: macos-latest
Expand All @@ -36,17 +36,21 @@ jobs:

- name: Install dependencies (linux)
run: |
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v1.6.1/bazelisk-linux-amd64" > bazel.tmp
sudo mv bazel.tmp /usr/local/bin/bazel
chmod +x /usr/local/bin/bazel
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v1.6.1/bazelisk-linux-amd64" > bazel
chmod +x bazel
sudo mv bazel /usr/local/bin/bazel
sudo apt install clang-9 patchelf
python -m pip install -r compiler_gym/requirements.txt -r examples/requirements.txt -r leaderboard/requirements.txt -r tests/requirements.txt
if: matrix.os == 'ubuntu-latest'

- name: Install dependencies (macOS)
run: |
brew install bazelisk
brew install bazelisk zlib
python -m pip install -r compiler_gym/requirements.txt -r examples/requirements.txt -r leaderboard/requirements.txt -r tests/requirements.txt
env:
LDFLAGS: -L/usr/local/opt/zlib/lib
CPPFLAGS: -I/usr/local/opt/zlib/include
PKG_CONFIG_PATH: /usr/local/opt/zlib/lib/pkgconfig
if: matrix.os == 'macos-latest'

- name: Test
Expand Down Expand Up @@ -76,17 +80,21 @@ jobs:

- name: Install dependencies (linux)
run: |
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v1.6.1/bazelisk-linux-amd64" > bazel.tmp
sudo mv bazel.tmp /usr/local/bin/bazel
chmod +x /usr/local/bin/bazel
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v1.6.1/bazelisk-linux-amd64" > bazel
chmod +x bazel
sudo mv bazel /usr/local/bin/bazel
sudo apt install clang-9 patchelf
python -m pip install -r compiler_gym/requirements.txt -r examples/requirements.txt -r leaderboard/requirements.txt -r tests/requirements.txt
if: matrix.os == 'ubuntu-latest'

- name: Install dependencies (macos)
run: |
brew install bazelisk
brew install bazelisk zlib
python -m pip install -r compiler_gym/requirements.txt -r examples/requirements.txt -r leaderboard/requirements.txt -r tests/requirements.txt
env:
LDFLAGS: -L/usr/local/opt/zlib/lib
CPPFLAGS: -I/usr/local/opt/zlib/include
PKG_CONFIG_PATH: /usr/local/opt/zlib/lib/pkgconfig
if: matrix.os == 'macos-latest'

- name: Install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fuzz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python: [3.8]
python: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pre_commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:
wget -O hadolint https://github.com/hadolint/hadolint/releases/download/v1.19.0/hadolint-Linux-x86_64
chmod +x hadolint
sudo mv hadolint /usr/local/bin
- name: Install Python 3.8
- name: Install Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- name: Install Python dependencies
run: |
sudo apt-get install python3-setuptools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python: [3.8]
python: [3.9]

steps:
- uses: actions/checkout@v2
Expand Down
80 changes: 50 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,13 @@ developers to expose new optimization problems for AI.

**Table of Contents**

<!-- MarkdownTOC -->

- [Getting Started](#getting-started)
- [Installation](#installation)
- [Building from Source](#building-from-source)
- [Trying it out](#trying-it-out)
- [Leaderboards](#leaderboards)
- [llvm-ic-v0](#llvm-ic-v0)
- [cBench-v1](#cBench-v1)
- [Contributing](#contributing)
- [Citation](#citation)

<!-- /MarkdownTOC -->

# Getting Started

Starting with CompilerGym is simple. If you not already familiar with the gym
Expand All @@ -58,55 +51,82 @@ for an overview of the key concepts.

Install the latest CompilerGym release using:

$ pip install compiler_gym
pip install -U compiler_gym

The binary works on macOS and Linux (on Ubuntu 18.04, Fedora 28, Debian 10 or
newer equivalents).

### Building from Source
### Building from Source <!-- omit in toc -->

If you prefer, you may build from source. This requires a modern C++ toolchain
and bazel.

If you prefer, you may build from source. This requires a modern C++ toolchain.
On macOS you can use the system compiler. On linux, install the required
toolchain using:
#### macOS <!-- omit in toc -->

On macOS the required dependencies can be installed using
[homebrew](https://docs.brew.sh/Installation):

```sh
brew install bazelisk zlib
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
```

$ sudo apt install clang libtinfo5 patchelf
$ export CC=clang
$ export CXX=clang++
Now proceed to [All platforms](#all-platforms) below.

#### Linux <!-- omit in toc -->

On debian-based linux systems, install the required toolchain using:

```sh
sudo apt install clang libtinfo5 libjpeg-dev patchelf
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/bazelisk-linux-amd64 -O bazel
chmod +x bazel && mkdir -p ~/.local/bin && mv -v bazel ~/.local/bin
export PATH="$HOME/.local/bin:$PATH"
export CC=clang
export CXX=clang++
```

#### All platforms <!-- omit in toc -->

We recommend using
[conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/)
to manage the remaining build dependencies. First create a conda environment
with the required dependencies:

$ conda create -n compiler_gym python=3.8 bazel=3.1.0 cmake pandoc
$ conda activate compiler_gym
conda create -n compiler_gym python=3.9 cmake pandoc
conda activate compiler_gym

Then clone the CompilerGym source code using:

$ git clone https://github.com/facebookresearch/CompilerGym.git
$ cd CompilerGym
git clone https://github.com/facebookresearch/CompilerGym.git
cd CompilerGym

Install the python development dependencies using:

$ make init
make init

The `make init` target only needs to be run once on initial setup, or when
upgrading to a different CompilerGym release.

Then run the test suite to confirm that everything is working:
Run the test suite to confirm that everything is working:

$ make test
make test

To build and install the python package, run:
To build and install the `compiler_gym` python package, run:

$ make install
make install

**NOTE:** To use the python code that is installed by `make install` you must
leave the root directory of this repository. Attempting to import `compiler_gym`
while in the root of this repository will cause import errors.
**NOTE:** To use the `compiler_gym` package that is installed by `make install`
you must leave the root directory of this repository. Attempting to import
`compiler_gym` while in the root of this repository will cause import errors.

When you are finished, you can deactivate and delete the conda
environment using:

$ conda deactivate
$ conda env remove -n compiler_gym
conda deactivate
conda env remove -n compiler_gym


## Trying it out
Expand Down Expand Up @@ -147,7 +167,7 @@ sequence of optimizations that lead to the greatest reduction in instruction
count in the program being compiled. Reward is the reduction in codesize
achieved scaled to the reduction achieved by LLVM's builtin `-Oz` pipeline.

### cBench-v1
### cBench-v1 <!-- omit in toc -->

This leaderboard tracks the results achieved by algorithms on the `llvm-ic-v0`
environment on the 23 benchmarks in the `cBench-v1` dataset.
Expand Down
7 changes: 4 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ rules_proto_toolchains()

# === GRPC ===

# Version should be kept in step with compiler_gym/requirements.txt.
http_archive(
name = "com_github_grpc_grpc",
sha256 = "7372a881122cd85a7224435a1d58bc5e11c88d4fb98a64b83f36f3d1c2f16d39",
strip_prefix = "grpc-1.34.0",
sha256 = "1a5127c81487f4e3e57973bb332f04b9159f94d860c207e096d8a587d371edbd",
strip_prefix = "grpc-1.36.0",
urls = [
"https://github.com/grpc/grpc/archive/v1.34.0.tar.gz",
"https://github.com/grpc/grpc/archive/v1.36.0.tar.gz",
],
)

Expand Down
5 changes: 3 additions & 2 deletions compiler_gym/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
absl-py>=0.10.0
deprecated>=1.2.12
fasteners==0.15
grpcio==1.34.0
gym>=0.17.2
# Version should be kept in step with @com_github_grpc_grpc in WORKSPACE.
grpcio>=1.36.0
gym>=0.18.0
humanize>=2.6.0
networkx==2.5
numpy>=1.19.3
Expand Down
2 changes: 1 addition & 1 deletion docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Begin by firing up a python interpreter:

.. code-block::

$ python
python

To start with we import the gym module and the CompilerGym environments:

Expand Down
2 changes: 1 addition & 1 deletion examples/RandomSearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Status runSearch(const fs::path& workingDir, std::vector<int>* bestActions, int6
}

void runThread(std::vector<int>* bestActions, int64_t* bestCost) {
const fs::path workingDir = workingDir / fs::unique_path();
const fs::path workingDir = fs::unique_path();
fs::create_directories(workingDir);
if (!runSearch(workingDir, bestActions, bestCost).ok()) {
LOG(ERROR) << "Search failed";
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ def get_tag(self):
include_package_data=True,
python_requires=">=3.6",
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Compilers",
],
Expand Down