“The first duty in life is to be as artificial as possible. What the second duty is no one has as yet discovered.” Oscar Wilde
Windy Walk (part 2) – addendum

Windy Walk (part 2) – addendum


  1. Previously we constructed a very simple class to emulate the type of environment which is provided by OpenAI. Windy Walk (part 1)
  2. Then we implemented the same windy walk model as an extension to OpenAI. For this we created a custom python package, we named it gym_drifty_walk, you can grab it from github .
  3. These two versions we used, to produce exactly the same “Windy Walks” results, as shown by the plots.

I this addendum post we’ll take a look at  the package code in gym_drifty_walk.

There are excellent articles about how to create a python package, I have no intention to duplicate those, I recommend python-packaging. One warning: the packaging article is written for python 2, so be aware of that.

There are things missing in this (like e.g. tests) that you would typically add. We choose to use the most basic approach that works, which we believe lowers the barrier to comprehension.

The most basic steps you need are these:

  • Choose a package name
    We have already done that:  gym_drifty_walk
  • ✓ Follow the basic package structure
    Here the structure is like this :

    (Remark; This tree-representation of the directory structure can be obtained using tree )

    So in the mother directory (as in mother ship) you need the setup.py (used for installing), the README.md (for advice on the package) , the LICENSE.md (setting out the terms of use) and the directory holding the actual code. Here the same tree with comments:

  • ✓ Match various names Having named the package (=gym_drifty_walk) the directory holding the actual code should be given the same name. In the setup again there’s a line with the name, and in gym_drifty_walk/gym_drifty_walk/envs/__init__.py the name needs to be reflected. Further name matching occurs. The first name matching concerns gym_drifty_walk/gym_drifty_walk/__init__.py
    There is actually only one line in that file

    The id (=”drifty_walk-v0″) is used later when you import the environment like this:

    The secondname matching concerns DriftyWalkEnv which occurs in the two files in  gym_drifty_walk/gym_drifty_walk/envs namely  drifty_walk_env.py and __init__.py.
    In drifty_walk_env.py you’ll find the line

    and in __init__.py you’ll find

    The name matching in this file was already mentioned above (regarding gym_drifty_walk) however there are two more matches:

    and finally drifty_walk_env which needs to match the file in the same directory.

    Here’s a summary of the name matching requirements:

    nameOccurs in FileNeeds to match..
    "gym_drifty_walk"gym_drifty_walk/setup.pythe package name
    "gym_drifty_walk"gym_drifty_walk/gym_drifty_walk/envs/__init__.pythe package name
    "drifty_walk-v0"gym_drifty_walk/gym_drifty_walk/__init__.pythe environment‘s name
    "DriftyWalkEnv"gym_drifty_walk/gym_drifty_walk/envs/__init__.pythe class name
    "DriftyWalkEnv"gym_drifty_walk/gym_drifty_walk/envs/drifty_walk_env.pythe class name
PHP Code Snippets Powered By : XYZScripts.com