Skip to content

Commit

Permalink
updated installer and profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
chrodan committed Oct 19, 2014
1 parent b5d96a3 commit 30976f8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
18 changes: 16 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,28 @@
project = u'RLPy'
copyright = u'2014, Alborz Geramifard, Robert H. Klein, Christoph Dann, William Dabney, Jonathan How'

def get_version_string():
import re
# Grab the version string from the documentation.
conf_fn = os.path.join(os.path.dirname(__file__), '..', 'setup.py')
VERSION_PATTERN = re.compile("version = '([^']+)'")
with open(conf_fn) as source:
for line in source:
match = VERSION_PATTERN.search(line)
if match:
return match.group(1)
raise ValueError('Could not extract release version from sphinx doc')


# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = get_version_string()
# The short X.Y version.
version = '1.3'
# The full version, including alpha/beta/rc tags.
release = '1.3'

autoclass_content = "both"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
7 changes: 5 additions & 2 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ Stable Version

RLPy is available on Pypi. The latest stable version can be installed directly with pip::

pip install rlpy
pip install -U rlpy

This command downloads the latest release of RLPy and installs it into the default package location
of your python distribution. For more information of the disutils package systems, have a look at the `documentation <https://docs.python.org/2/install/index.html#install-index>`_.
of your python distribution.
Only the library itself is installed. If you like to have the documentation and example scripts, have a look at how to install the development version below.

For more information of the disutils package systems, have a look at the `documentation <https://docs.python.org/2/install/index.html#install-index>`_.

If you are using MacOS make sure you have the latest version of Xcode using::

Expand Down
56 changes: 56 additions & 0 deletions examples/tutorial/gridworld_profiled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
"""
Getting Started Tutorial for RLPy
=================================
This file contains a very basic example of a RL experiment:
A simple Grid-World.
"""
__author__ = "Robert H. Klein"
from rlpy.Domains import GridWorld
from rlpy.Agents import Q_Learning
from rlpy.Representations import Tabular
from rlpy.Policies import eGreedy
from rlpy.Experiments import Experiment
import os


def make_experiment(exp_id=1, path="./Results/Tutorial/gridworld-qlearning"):
"""
Each file specifying an experimental setup should contain a
make_experiment function which returns an instance of the Experiment
class with everything set up.
@param id: number used to seed the random number generators
@param path: output directory where logs and results are stored
"""
opt = {}
opt["exp_id"] = exp_id
opt["path"] = path

# Domain:
maze = os.path.join(GridWorld.default_map_dir, '4x5.txt')
domain = GridWorld(maze, noise=0.3)
opt["domain"] = domain

# Representation
representation = Tabular(domain, discretization=20)

# Policy
policy = eGreedy(representation, epsilon=0.2)

# Agent
opt["agent"] = Q_Learning(representation=representation, policy=policy,
discount_factor=domain.discount_factor,
initial_learn_rate=0.1,
learn_rate_decay_mode="boyan", boyan_N0=100,
lambda_=0.)
opt["checks_per_policy"] = 100
opt["max_steps"] = 2000
opt["num_policy_checks"] = 10
experiment = Experiment(**opt)
return experiment

if __name__ == '__main__':
from rlpy.Tools.run import run_profiled
run_profiled(make_experiment, '.', 'gridworld.pdf')
File renamed without changes.
10 changes: 6 additions & 4 deletions rlpy/Tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ def run_profiled(make_exp_fun, profile_location="Profiling",
p = pstats.Stats(dat_fn)
p.sort_stats('time').print_stats(5)

gprof2dot_fn = os.path.join(__rlpy_location__, 'Tools', 'gprof2dot.py')
if(platform.system() == 'Windows'):
# Load the STATS and prepare the dot file for graphvis
command = '.\Profiling\gprof2dot.py -f pstats {dat_fn} > {dot_fn}'.format(
command = gprof2dot_fn + ' -f pstats {dat_fn} > {dot_fn}'.format(
dat_fn=dat_fn,
dot_fn=dot_fn)
os.system(command)

else:
# Load the STATS and prepare the dot file for graphvis
command = '/usr/bin/env python ./Profiling/gprof2dot.py -f pstats {dat_fn} > {dot_fn}'.format(
command = '/usr/bin/env python ' + gprof2dot_fn \
+ ' -f pstats {dat_fn} > {dot_fn}'.format(
dat_fn=dat_fn,
dot_fn=dot_fn)
os.system(command)
Expand Down Expand Up @@ -126,10 +128,10 @@ def prepare_directory(setting, path, **hyperparam):
the id and hyperparameters
and returns an instance of Experiment ready to run
:param path: specifies where to create the directory
:param \*\*hyperparam: all hyperparameters passed to the setting's
:param \*\*hyperparam: all hyperparameters passed to the setting's
``make_experiment()``
:return: filename of the file to execute in path
"""
# create file to execute
variables = "hyper_param = dict(" + ",\n".join(["{}={}".format(k, repr(v))
Expand Down
36 changes: 13 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,9 @@
from Cython.Distutils import build_ext
import numpy
import os
import re
import sys


def get_version_string():
# Grab the version string from the documentation.
conf_fn = os.path.join(os.path.dirname(__file__), 'doc', 'conf.py')
VERSION_PATTERN = re.compile("release = '([^']+)'")
with open(conf_fn) as source:
for line in source:
match = VERSION_PATTERN.search(line)
if match:
return match.group(1)
raise ValueError('Could not extract release version from sphinx doc')

version = get_version_string()
version = '1.3.1'

if sys.platform == 'darwin':
# by default use clang++ as this most likely to have c++11 support
Expand All @@ -37,7 +24,8 @@ def get_version_string():
maintainer="Christoph Dann",
maintainer_email="[email protected]",
license="BSD 3-clause",
description="Value-Function-Based Reinforcement-Learning Library for Education and Research",
description="Value-Function-Based Reinforcement-Learning Library for"
+ " Education and Research",
url="http://acl.mit.edu/rlpy/",
classifiers=['Intended Audience :: Science/Research',
'Intended Audience :: Developers',
Expand All @@ -54,14 +42,16 @@ def get_version_string():
],
long_description=open('README.rst').read(),
packages=find_packages(),
package_data={'rlpy': [
'Domains/GridWorldMaps/*.txt',
'Domains/IntruderMonitoringMaps/*.txt',
'Domains/PinballConfigs/*.cfg',
'Domains/PacmanPackage/layouts/*.lay',
'Domains/SystemAdministratorMaps/*.txt',
"Representations/c_kernels.h",
]},
include_package_data=True,
# package_data={'rlpy': [
# 'Domains/GridWorldMaps/*.txt',
# 'Domains/IntruderMonitoringMaps/*.txt',
# 'Domains/PinballConfigs/*.cfg',
# 'Domains/PacmanPackage/layouts/*.lay',
# 'Domains/SystemAdministratorMaps/*.txt',
# "Representations/c_kernels.h",
# ]
# },
install_requires=[
'numpy >= 1.7',
'scipy',
Expand Down

0 comments on commit 30976f8

Please sign in to comment.