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

Can't build to simple gym-like interface #127

Closed
bjg2 opened this issue Feb 11, 2019 · 9 comments
Closed

Can't build to simple gym-like interface #127

bjg2 opened this issue Feb 11, 2019 · 9 comments

Comments

@bjg2
Copy link

bjg2 commented Feb 11, 2019

Walking through the examples, I haven't understood how can I build the code, and after build have an easy, gym-like environment I could instantiate / reset / step / etc? Everything that I managed was building and starting stuff directly through bazel, similar to python_random_agent, but I don't see how to call step/reset outside of bazel. Am I missing something or there is no description of how to build+run such an environment?

@tkoeppe
Copy link
Collaborator

tkoeppe commented Feb 11, 2019

DeepMind Lab is predominantly a library that you integrate into your own project. We use Bazel as the build system, but there are several ways you can use the code from elsewhere:

  • If you want to program in Python, you can build DeepMind Lab as a PIP, install that and then just import the module from Python.

  • You can also build the shared library (either with software or with hardware rendering); see the BUILD file for the relevant targets, and then link against that (either directly, at link time, from native code, or dynamically via dlopen). Then you'd use the provided C API to drive the environment. In fact, that's exactly what the Python module is doing, so you can use the Python module source code as an example for loading the DSO.

@mtrazzi
Copy link

mtrazzi commented Feb 12, 2019

@tkoeppe thanks for the answer. I'm also trying to build some kind of gym-like API to a deepmind lab env. The pip package tutorial & dmlab_module.c in python are well-documented, so thanks for that as well. A few comments on the gym-like env and pip package:

  • I'm also (cc @bjg2 ) trying to build some kind of gym-like wrapper to a DeepMind Lab env (here for the gist to my current wrapper). I'm trying to find a way of querying whether an env has finished or not (this one). I saw in the lua api doc that there seems to be a hasEpisodeFinished method to query the env via lua. @tkoeppe Is there a way to do the same via the python API? The "done" variable is necessary for some "gym-like" interface.

  • Also, I've tried to build a pip package from mac, and it's almost working on the macos branch. It's just a matter of changing the cp/mkdir/mktemp options from linux to mac (what I've almost finished here). @tkoeppe Should I do a pull request on the macos branch when I'm done?

@bjg2
Copy link
Author

bjg2 commented Feb 12, 2019

So I built and run pip - tank you very much. I found pip installation page via google though and I'm not sure how could anyone know where to find pip installation instructions? I think readme should improve answering that question, cause I guess that's the main thing people coming here are looking for?

Regarding above question, I found answer on python API readme:

reset(episode=-1, seed=None)
Resets the environment to its initialization state. This method needs to be called to start a new episode after the last episode ended (which puts the environment into is_running() == False state).

I have one more question: what kind of events could be returned with events() method?

For anyone breaking their head on how to start environments via python:

# Install external dependencies as described in https://github.com/deepmind/lab#external-dependencies-prerequisites-and-porting-notes
git clone https://github.com/deepmind/lab.git dm-lab
cd dm-lab
virtualenv -p python3 venv
source venv/bin/activate
# Change files similar to this change, but for python3.6 https://github.com/deepmind/lab/commit/20449696670d2de5fa71be86b21330a227e33d49
bazel build -c opt python/pip_package:build_pip_package
./bazel-bin/python/pip_package/build_pip_package $(pwd)
# pip install generated wheel from wherever
# Test the instalation, for example with https://github.com/deepmind/lab/tree/master/python/pip_package#testing-the-installation

@tkoeppe
Copy link
Collaborator

tkoeppe commented Feb 12, 2019

@mtrazzi: Regarding the macos branch: Will this work generally and for everyone? I haven't looked at the PIP build script, so if you can/have, that would be very helpful. I think we would integrate those changes into the "floating commit", such as ccfe8a6.

It's a bit of a pain for users to have the "macos" branch be this constant rebasing; I'm thinking of turning the branch into a checked in .patch file that you just apply locally...

@tkoeppe
Copy link
Collaborator

tkoeppe commented Feb 12, 2019

@mtrazzi: I'm not super familiar with the Python API, but have a look at is_running. According to the reset documentation, that's what tells you that an episode has ended.

@mtrazzi
Copy link

mtrazzi commented Feb 12, 2019

@tkoeppe The is_running() method works well, thanks. Here is a working gym-like wrapper @bjg2, let me know if that helps.

@tkoeppe I'm not sure how to contribute to this "floating commit". I tried to git checkout to the commit and make a pull request but it doesn't seem to belong to any branch. Here is the pip bash script that works on macos.

@tkoeppe
Copy link
Collaborator

tkoeppe commented Feb 12, 2019

@mtrazzi: I think you can just make a pull request against the "macos" branch? What I mean by "floating" is that I'll eventually rebase that branch, so that commit will "float up" to to the top (and get a new commit hash).

@mtrazzi
Copy link

mtrazzi commented Feb 13, 2019

@tkoeppe done

@tkoeppe
Copy link
Collaborator

tkoeppe commented Dec 5, 2019

So, I think that the macos branch already contains the necessary modifications, right? I think that settles everything? Please feel free to reopen if you have new information.

Note also that I recently added a Python wrapper module for our new dm_env Python API, in case that's of interest or use to anyone.

@tkoeppe tkoeppe closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants