Skip to content

Commit

Permalink
Merge pull request #169 from amueller/ci_no_sudo
Browse files Browse the repository at this point in the history
Ci no sudo
  • Loading branch information
amueller committed Jan 15, 2016
2 parents b585f94 + 5816350 commit cb7c033
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 96 deletions.
23 changes: 21 additions & 2 deletions .travis.yml
@@ -1,4 +1,23 @@
sudo: false
language: python
addons:
apt:
sources:
- boost-latest
packages:
- python-scipy
- python-nose
- python-pip
- cython
- cmake
- time
- libatlas-dev
- libatlas3gf-base
- liblapack-dev
- liblapack3gf
- libhdf5-serial-dev
- libboost1.55-dev
- libboost-python1.55-dev
virtualenv:
system_site_packages: true
env:
Expand All @@ -11,10 +30,10 @@ env:
NUMPY_VERSION="1.6.2" SCIPY_VERSION="0.11.0"
## This environment tests the newest supported anaconda env
- DISTRIB="conda" PYTHON_VERSION="2.7"
NUMPY_VERSION="1.8.1" SCIPY_VERSION="0.14.0"
NUMPY_VERSION="1.10.1" SCIPY_VERSION="0.16.0"
# python3 only on ubuntu because of cvxopt
- DISTRIB="conda" PYTHON_VERSION="3.4" OPENGM="false"
NUMPY_VERSION="1.8.1" SCIPY_VERSION="0.14.0"
NUMPY_VERSION="1.10.1" SCIPY_VERSION="0.16.0"
install: source continuous_integration/install.sh
script: bash continuous_integration/test_script.sh
after_success:
Expand Down
28 changes: 8 additions & 20 deletions continuous_integration/install.sh
Expand Up @@ -15,18 +15,15 @@ export CXX=g++
export PIP=pip

# add cython repository
sudo add-apt-repository ppa:cython-dev/master-ppa -y
sudo apt-get update -qq
#sudo add-apt-repository ppa:cython-dev/master-ppa -y
#sudo apt-get update -qq

if [[ "$OPENGM" == "true" ]]; then
sudo add-apt-repository ppa:ukplc-team/testing -y
sudo apt-get update -qq
sudo apt-get install libhdf5-serial-dev libboost1.49-dev libboost-python1.49-dev
git clone https://github.com/opengm/opengm.git
cd opengm
cmake . -DWITH_BOOST=TRUE -DWITH_HDF5=TRUE -DBUILD_PYTHON_WRAPPER=TRUE -DBUILD_EXAMPLES=FALSE -DBUILD_TESTING=FALSE
cmake . -DCMAKE_INSTALL_PREFIX=/home/travis/.local -DWITH_BOOST=TRUE -DWITH_HDF5=TRUE -DBUILD_PYTHON_WRAPPER=TRUE -DBUILD_EXAMPLES=FALSE -DBUILD_TESTING=FALSE
make -j2 --quiet
sudo make install
make install
cd ..
fi

Expand All @@ -46,17 +43,8 @@ if [[ "$DISTRIB" == "conda" ]]; then
# Configure the conda environment and put it in the path using the
# provided versions

if [[ "$PYTHON_VERSION" == "3.4" ]]; then
apt-cache search liblapack
sudo apt-get install build-essential python-dev python-setuptools \
python-numpy python-scipy libatlas-dev libatlas3gf-base liblapack-dev liblapack3gf
conda create -n testenv --yes python=$PYTHON_VERSION pip nose cython scikit-learn\
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION
else
conda create -n testenv --yes python=$PYTHON_VERSION pip nose cython scikit-learn cvxopt\
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION
fi

conda create -n testenv --yes python=$PYTHON_VERSION pip nose cython scikit-learn cvxopt\
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION

source activate testenv

Expand All @@ -71,15 +59,15 @@ if [[ "$DISTRIB" == "conda" ]]; then
elif [[ "$DISTRIB" == "ubuntu" ]]; then
# Use standard ubuntu packages in their default version
# except for cython :-/
sudo apt-get install -qq python-scipy python-nose python-pip python-cvxopt cython
$PIP install --user cvxopt
fi

if [[ "$COVERAGE" == "true" ]]; then
$PIP install coverage coveralls
fi

# install our favorite inference packages
$PIP install pyqpbo ad3 scikit-learn cvxopt
$PIP install pyqpbo ad3 scikit-learn

# Build scikit-learn in the install.sh script to collapse the verbose
# build output in the travis output when it succeeds.
Expand Down
18 changes: 14 additions & 4 deletions doc/conf.py
Expand Up @@ -15,7 +15,8 @@
import sys
import os
import sphinx_bootstrap_theme
import sphinxgallery
import pystruct
#import sphinx_gallery

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand All @@ -32,7 +33,7 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary',
'sphinx.ext.doctest', 'sphinx.ext.pngmath',
'sphinx.ext.viewcode', 'numpy_ext.numpydoc', 'sphinxgallery.gen_gallery']
'sphinx.ext.viewcode', 'numpy_ext.numpydoc', 'sphinx_gallery.gen_gallery']

autosummary_generate = True

Expand Down Expand Up @@ -61,12 +62,21 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
import pystruct
# The short X.Y version.
version = pystruct.__version__
# The full version, including alpha/beta/rc tags.
release = pystruct.__version__

sphinx_gallery_conf = {
'reference_url': {
# The module you locally document uses a None
'pystruct': None,

# External python modules use their documentation websites
'sklearn': 'http://scikit-learn.org/stable',
'matplotlib': 'http://matplotlib.org',
'numpy': 'http://docs.scipy.org/doc/numpy-1.9.1'}}

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
Expand Down Expand Up @@ -134,7 +144,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static', sphinxgallery.path_static()]
html_static_path = ['_static']

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
Expand Down
14 changes: 9 additions & 5 deletions doc/sphinxext/numpy_ext/docscrape.py
Expand Up @@ -6,8 +6,12 @@
import textwrap
import re
import pydoc
from StringIO import StringIO
from warnings import warn
# Try Python 2 first, otherwise load from Python 3
try:
from StringIO import StringIO
except:
from io import StringIO


class Reader(object):
Expand Down Expand Up @@ -115,7 +119,7 @@ def __getitem__(self, key):
return self._parsed_data[key]

def __setitem__(self, key, val):
if not self._parsed_data.has_key(key):
if key not in self._parsed_data:
warn("Unknown section %s" % key)
else:
self._parsed_data[key] = val
Expand Down Expand Up @@ -435,7 +439,7 @@ def __init__(self, func, role='func', doc=None, config={}):
argspec = inspect.formatargspec(*argspec)
argspec = argspec.replace('*', '\*')
signature = '%s%s' % (func_name, argspec)
except TypeError, e:
except TypeError as e:
signature = '%s()' % func_name
self['Signature'] = signature

Expand All @@ -457,8 +461,8 @@ def __str__(self):
'meth': 'method'}

if self._role:
if not roles.has_key(self._role):
print "Warning: invalid role %s" % self._role
if self._role not in roles:
print("Warning: invalid role %s" % self._role)
out += '.. %s:: %s\n \n\n' % (roles.get(self._role, ''),
func_name)

Expand Down
12 changes: 6 additions & 6 deletions doc/sphinxext/numpy_ext/docscrape_sphinx.py
Expand Up @@ -2,10 +2,9 @@
import inspect
import textwrap
import pydoc
import sphinx
from docscrape import NumpyDocString
from docscrape import FunctionDoc
from docscrape import ClassDoc
from .docscrape import NumpyDocString
from .docscrape import FunctionDoc
from .docscrape import ClassDoc


class SphinxDocString(NumpyDocString):
Expand Down Expand Up @@ -156,6 +155,7 @@ def _str_references(self):
out += ['']
# Latex collects all references to a separate bibliography,
# so we need to insert links to it
import sphinx # local import to avoid test dependency
if sphinx.__version__ >= "0.6":
out += ['.. only:: latex', '']
else:
Expand Down Expand Up @@ -188,14 +188,14 @@ def __str__(self, indent=0, func_role="obj"):
out += self._str_index() + ['']
out += self._str_summary()
out += self._str_extended_summary()
for param_list in ('Parameters', 'Returns', 'Raises'):
for param_list in ('Parameters', 'Returns', 'Raises', 'Attributes'):
out += self._str_param_list(param_list)
out += self._str_warnings()
out += self._str_see_also(func_role)
out += self._str_section('Notes')
out += self._str_references()
out += self._str_examples()
for param_list in ('Attributes', 'Methods'):
for param_list in ('Methods',):
out += self._str_member_list(param_list)
out = self._str_indent(out, indent)
return '\n'.join(out)
Expand Down
51 changes: 33 additions & 18 deletions doc/sphinxext/numpy_ext/numpydoc.py
Expand Up @@ -17,12 +17,14 @@
"""

from __future__ import unicode_literals

import sys # Only needed to check Python version
import os
import re
import pydoc
from docscrape_sphinx import get_doc_object
from docscrape_sphinx import SphinxDocString
from sphinx.util.compat import Directive
from .docscrape_sphinx import get_doc_object
from .docscrape_sphinx import SphinxDocString
import inspect


Expand All @@ -34,17 +36,20 @@ def mangle_docstrings(app, what, name, obj, options, lines,

if what == 'module':
# Strip top title
title_re = re.compile(ur'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*',
title_re = re.compile(r'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*',
re.I | re.S)
lines[:] = title_re.sub(u'', u"\n".join(lines)).split(u"\n")
lines[:] = title_re.sub('', "\n".join(lines)).split("\n")
else:
doc = get_doc_object(obj, what, u"\n".join(lines), config=cfg)
lines[:] = unicode(doc).split(u"\n")
doc = get_doc_object(obj, what, "\n".join(lines), config=cfg)
if sys.version_info[0] < 3:
lines[:] = unicode(doc).splitlines()
else:
lines[:] = str(doc).splitlines()

if app.config.numpydoc_edit_link and hasattr(obj, '__name__') and \
obj.__name__:
if hasattr(obj, '__module__'):
v = dict(full_name=u"%s.%s" % (obj.__module__, obj.__name__))
v = dict(full_name="%s.%s" % (obj.__module__, obj.__name__))
else:
v = dict(full_name=obj.__name__)
lines += [u'', u'.. htmlonly::', '']
Expand All @@ -55,7 +60,7 @@ def mangle_docstrings(app, what, name, obj, options, lines,
references = []
for line in lines:
line = line.strip()
m = re.match(ur'^.. \[([a-z0-9_.-])\]', line, re.I)
m = re.match(r'^.. \[([a-z0-9_.-])\]', line, re.I)
if m:
references.append(m.group(1))

Expand All @@ -64,8 +69,8 @@ def mangle_docstrings(app, what, name, obj, options, lines,
if references:
for i, line in enumerate(lines):
for r in references:
if re.match(ur'^\d+$', r):
new_r = u"R%d" % (reference_offset[0] + int(r))
if re.match(r'^\d+$', r):
new_r = "R%d" % (reference_offset[0] + int(r))
else:
new_r = u"%s%d" % (r, reference_offset[0])
lines[i] = lines[i].replace(u'[%s]_' % r,
Expand All @@ -91,16 +96,20 @@ def mangle_signature(app, what, name, obj,

doc = SphinxDocString(pydoc.getdoc(obj))
if doc['Signature']:
sig = re.sub(u"^[^(]*", u"", doc['Signature'])
return sig, u''
sig = re.sub("^[^(]*", "", doc['Signature'])
return sig, ''


def setup(app, get_doc_object_=get_doc_object):
global get_doc_object
get_doc_object = get_doc_object_

app.connect('autodoc-process-docstring', mangle_docstrings)
app.connect('autodoc-process-signature', mangle_signature)
if sys.version_info[0] < 3:
app.connect(b'autodoc-process-docstring', mangle_docstrings)
app.connect(b'autodoc-process-signature', mangle_signature)
else:
app.connect('autodoc-process-docstring', mangle_docstrings)
app.connect('autodoc-process-signature', mangle_signature)
app.add_config_value('numpydoc_edit_link', None, False)
app.add_config_value('numpydoc_use_plots', None, False)
app.add_config_value('numpydoc_show_class_members', True, True)
Expand All @@ -113,9 +122,13 @@ def setup(app, get_doc_object_=get_doc_object):
# Docstring-mangling domains
#-----------------------------------------------------------------------------

from docutils.statemachine import ViewList
from sphinx.domains.c import CDomain
from sphinx.domains.python import PythonDomain
try:
import sphinx # lazy to avoid test dependency
except ImportError:
CDomain = PythonDomain = object
else:
from sphinx.domains.c import CDomain
from sphinx.domains.python import PythonDomain


class ManglingDomainBase(object):
Expand Down Expand Up @@ -170,6 +183,8 @@ def run(self):

lines = list(self.content)
mangle_docstrings(env.app, objtype, name, None, None, lines)
# local import to avoid testing dependency
from docutils.statemachine import ViewList
self.content = ViewList(lines, self.content.parent)

return base_directive.run(self)
Expand Down
10 changes: 5 additions & 5 deletions examples/plot_latent_node.py
Expand Up @@ -54,10 +54,10 @@ def plot_boxes(boxes, size=4, title=""):

G = [make_grid_edges(x) for x in X]

asdf = zip(X_flat, G)
svm.fit(asdf, Y_flat)
plot_boxes(svm.predict(asdf), title="Non-latent SSVM predictions")
print("Training score binary grid CRF: %f" % svm.score(asdf, Y_flat))
X_grid_edges = list(zip(X_flat, G))
svm.fit(X_grid_edges, Y_flat)
plot_boxes(svm.predict(X_grid_edges), title="Non-latent SSVM predictions")
print("Training score binary grid CRF: %f" % svm.score(X_grid_edges, Y_flat))

# using one latent variable for each 2x2 rectangle
latent_crf = LatentNodeCRF(n_labels=2, n_features=1, n_hidden_states=2,
Expand All @@ -83,7 +83,7 @@ def plot_boxes(boxes, size=4, title=""):
plot_boxes(H_init, title="Top: Random initial hidden states. Bottom: Ground"
"truth labeling.")

X_ = zip(X_flat, G, [2 * 2 for x in X_flat])
X_ = list(zip(X_flat, G, [2 * 2 for x in X_flat]))

latent_svm.fit(X_, Y_flat, H_init)

Expand Down
2 changes: 0 additions & 2 deletions pystruct/datasets/synthetic_grids.py
Expand Up @@ -304,8 +304,6 @@ def generate_crosses_explicit(n_samples=5, noise=30, size=9, n_crosses=2):
ix, iy, iz = np.ogrid[:X.shape[0], :X.shape[1], :X.shape[2]]
X[ix, iy, iz, Y_flips] = 1
X[ix, iy, iz, 2 * Y_flips] = 1
#Y = (Y != 0).astype(np.int)
#X = X[:, :, :, :2]
return X, Y


Expand Down
3 changes: 2 additions & 1 deletion pystruct/models/graph_crf.py
Expand Up @@ -66,7 +66,8 @@ class GraphCRF(CRF):
Possible values are:
- 'max-product' for max-product belief propagation.
Recommended for chains an trees. Loopy belief propagatin in case of a general graph.
Recommended for chains an trees. Loopy belief propagation in
case of a general graph.
- 'lp' for Linear Programming relaxation using cvxopt.
- 'ad3' for AD3 dual decomposition.
- 'qpbo' for QPBO + alpha expansion.
Expand Down

0 comments on commit cb7c033

Please sign in to comment.