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

Jwang 445 install pure python modules only #447

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ include setup.py
include *.ini
# docs
recursive-include doc *
# optimal learning
recursive-include moe/optimal_learning *
# webapp
recursive-include moe *
recursive-include moe/templates *
recursive-include moe/static *
# cpp files
recursive-include moe/optimal_learning/cpp *

# remove what we don't want, kept in step with .gitignore
# Logs
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ all: production
clean:
find . -name '*.pyc' -delete
rm -rf moe/build
rm -rf build
rm -rf MOE.egg-info

production:
python setup.py install
Expand Down
2 changes: 2 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Requires:

.. Warning:: Boost, MOE, and the virtualenv must be built with the same python. (OS X users: we recommend using the MacPorts Python: ``/opt/local/bin/python``.)

9. Should you have difficulty in compiling the C++ library and cannot work around, you could set environmental variable ```MOE_NO_BUILD_CPP=True``` to skip installation of C++ components. Note that if you choose to go this route, please do not use optimal learning modules in REST interface for now, as this part is not compatible with no C++ components build yet.

OSX Tips
--------

Expand Down
4 changes: 4 additions & 0 deletions moe/optimal_learning/python/constant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Some default configuration parameters for optimal_learning components."""
from collections import namedtuple
import os

import moe.optimal_learning.python.python_version.optimization as python_optimization
import moe.views.constant as views_constant
Expand Down Expand Up @@ -299,3 +300,6 @@ class DefaultOptimizerInfoTuple(_BaseDefaultOptimizerInfoTuple):
# TODO(GH-257): Find a better default.
DEFAULT_KRIGING_NOISE_VARIANCE = 1e-8
DEFAULT_KRIGING_STD_DEVIATION_COEF = 0.0

# Whether cpp components were installed
CPP_COMPONENT_INSTALLED = os.environ.get('MOE_NO_BUILD_CPP', 'False') == 'False'
200 changes: 151 additions & 49 deletions moe/optimal_learning/python/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,213 @@
"""Links between the python and cpp_wrapper implementations of domains, covariances and optimizations."""
from collections import namedtuple

from moe.optimal_learning.python.constant import SQUARE_EXPONENTIAL_COVARIANCE_TYPE, TENSOR_PRODUCT_DOMAIN_TYPE, SIMPLEX_INTERSECT_TENSOR_PRODUCT_DOMAIN_TYPE, NULL_OPTIMIZER, NEWTON_OPTIMIZER, GRADIENT_DESCENT_OPTIMIZER, L_BFGS_B_OPTIMIZER, LOG_MARGINAL_LIKELIHOOD, LEAVE_ONE_OUT_LOG_LIKELIHOOD
import moe.optimal_learning.python.cpp_wrappers.covariance as cpp_covariance
import moe.optimal_learning.python.cpp_wrappers.domain as cpp_domain
from moe.optimal_learning.python.cpp_wrappers.log_likelihood import GaussianProcessLogMarginalLikelihood, GaussianProcessLeaveOneOutLogLikelihood
import moe.optimal_learning.python.cpp_wrappers.optimization as cpp_optimization
from moe.optimal_learning.python.constant import SQUARE_EXPONENTIAL_COVARIANCE_TYPE, TENSOR_PRODUCT_DOMAIN_TYPE, SIMPLEX_INTERSECT_TENSOR_PRODUCT_DOMAIN_TYPE, NULL_OPTIMIZER, NEWTON_OPTIMIZER, GRADIENT_DESCENT_OPTIMIZER, L_BFGS_B_OPTIMIZER, LOG_MARGINAL_LIKELIHOOD, LEAVE_ONE_OUT_LOG_LIKELIHOOD, CPP_COMPONENT_INSTALLED
import moe.optimal_learning.python.python_version.covariance as python_covariance
import moe.optimal_learning.python.python_version.domain as python_domain
import moe.optimal_learning.python.python_version.optimization as python_optimization
from moe.optimal_learning.python.python_version.log_likelihood import GaussianProcessLogMarginalLikelihood as PythonGaussianProcessLogMarginalLikelihood

if CPP_COMPONENT_INSTALLED:
import moe.optimal_learning.python.cpp_wrappers.covariance as cpp_covariance
import moe.optimal_learning.python.cpp_wrappers.domain as cpp_domain
from moe.optimal_learning.python.cpp_wrappers.log_likelihood import GaussianProcessLogMarginalLikelihood, GaussianProcessLeaveOneOutLogLikelihood
import moe.optimal_learning.python.cpp_wrappers.optimization as cpp_optimization

# Covariance
CovarianceLinks = namedtuple(
# Covariance
CovarianceLinks = namedtuple(
'CovarianceLinks',
[
'python_covariance_class',
'cpp_covariance_class',
],
)

COVARIANCE_TYPES_TO_CLASSES = {
SQUARE_EXPONENTIAL_COVARIANCE_TYPE: CovarianceLinks(
python_covariance.SquareExponential,
cpp_covariance.SquareExponential,
),
}

# Domain
DomainLinks = namedtuple(
'DomainLinks',
[
'python_domain_class',
'cpp_domain_class',
],
)

DOMAIN_TYPES_TO_DOMAIN_LINKS = {
TENSOR_PRODUCT_DOMAIN_TYPE: DomainLinks(
python_domain.TensorProductDomain,
cpp_domain.TensorProductDomain,
),
SIMPLEX_INTERSECT_TENSOR_PRODUCT_DOMAIN_TYPE: DomainLinks(
None,
cpp_domain.SimplexIntersectTensorProductDomain,
),
}

# Optimization
OptimizerMethod = namedtuple(
'OptimizerMethod',
[
'optimizer_type',
'python_parameters_class',
'cpp_parameters_class',
'python_optimizer_class',
'cpp_optimizer_class',
],
)

OPTIMIZER_TYPES_TO_OPTIMIZER_METHODS = {
NULL_OPTIMIZER: OptimizerMethod(
optimizer_type=NULL_OPTIMIZER,
python_parameters_class=python_optimization.NullParameters,
cpp_parameters_class=cpp_optimization.NullParameters,
python_optimizer_class=python_optimization.NullOptimizer,
cpp_optimizer_class=cpp_optimization.NullOptimizer,
),
NEWTON_OPTIMIZER: OptimizerMethod(
optimizer_type=NEWTON_OPTIMIZER,
python_parameters_class=python_optimization.NewtonParameters,
cpp_parameters_class=cpp_optimization.NewtonParameters,
python_optimizer_class=None,
cpp_optimizer_class=cpp_optimization.NewtonOptimizer,
),
GRADIENT_DESCENT_OPTIMIZER: OptimizerMethod(
optimizer_type=GRADIENT_DESCENT_OPTIMIZER,
python_parameters_class=python_optimization.GradientDescentParameters,
cpp_parameters_class=cpp_optimization.GradientDescentParameters,
python_optimizer_class=python_optimization.GradientDescentOptimizer,
cpp_optimizer_class=cpp_optimization.GradientDescentOptimizer,
),
L_BFGS_B_OPTIMIZER: OptimizerMethod(
optimizer_type=L_BFGS_B_OPTIMIZER,
python_parameters_class=python_optimization.LBFGSBParameters,
cpp_parameters_class=None,
python_optimizer_class=python_optimization.LBFGSBOptimizer,
cpp_optimizer_class=None,
),
}

# Log Likelihood
LogLikelihoodMethod = namedtuple(
'LogLikelihoodMethod',
[
'log_likelihood_type',
'log_likelihood_class',
]
)

LOG_LIKELIHOOD_TYPES_TO_LOG_LIKELIHOOD_METHODS = {
LOG_MARGINAL_LIKELIHOOD: LogLikelihoodMethod(
log_likelihood_type=LOG_MARGINAL_LIKELIHOOD,
log_likelihood_class=GaussianProcessLogMarginalLikelihood,
),
LEAVE_ONE_OUT_LOG_LIKELIHOOD: LogLikelihoodMethod(
log_likelihood_type=LEAVE_ONE_OUT_LOG_LIKELIHOOD,
log_likelihood_class=GaussianProcessLeaveOneOutLogLikelihood,
),
}
else:

# Covariance
CovarianceLinks = namedtuple(
'CovarianceLinks',
[
'python_covariance_class',
'cpp_covariance_class',
],
)
],
)

COVARIANCE_TYPES_TO_CLASSES = {
COVARIANCE_TYPES_TO_CLASSES = {
SQUARE_EXPONENTIAL_COVARIANCE_TYPE: CovarianceLinks(
python_covariance.SquareExponential,
cpp_covariance.SquareExponential,
),
}
None,
),
}

# Domain
DomainLinks = namedtuple(
# Domain
DomainLinks = namedtuple(
'DomainLinks',
[
'python_domain_class',
'cpp_domain_class',
],
)
],
)

DOMAIN_TYPES_TO_DOMAIN_LINKS = {
DOMAIN_TYPES_TO_DOMAIN_LINKS = {
TENSOR_PRODUCT_DOMAIN_TYPE: DomainLinks(
python_domain.TensorProductDomain,
cpp_domain.TensorProductDomain,
),
None,
),
SIMPLEX_INTERSECT_TENSOR_PRODUCT_DOMAIN_TYPE: DomainLinks(
None,
cpp_domain.SimplexIntersectTensorProductDomain,
),
}
None,
),
}

# Optimization
OptimizerMethod = namedtuple(
# Optimization
OptimizerMethod = namedtuple(
'OptimizerMethod',
[
'optimizer_type',
'python_parameters_class',
'cpp_parameters_class',
'python_optimizer_class',
'cpp_optimizer_class',
],
)
],
)

OPTIMIZER_TYPES_TO_OPTIMIZER_METHODS = {
OPTIMIZER_TYPES_TO_OPTIMIZER_METHODS = {
NULL_OPTIMIZER: OptimizerMethod(
optimizer_type=NULL_OPTIMIZER,
python_parameters_class=python_optimization.NullParameters,
cpp_parameters_class=cpp_optimization.NullParameters,
cpp_parameters_class=None,
python_optimizer_class=python_optimization.NullOptimizer,
cpp_optimizer_class=cpp_optimization.NullOptimizer,
),
cpp_optimizer_class=None,
),
NEWTON_OPTIMIZER: OptimizerMethod(
optimizer_type=NEWTON_OPTIMIZER,
python_parameters_class=python_optimization.NewtonParameters,
cpp_parameters_class=cpp_optimization.NewtonParameters,
cpp_parameters_class=None,
python_optimizer_class=None,
cpp_optimizer_class=cpp_optimization.NewtonOptimizer,
),
cpp_optimizer_class=None,
),
GRADIENT_DESCENT_OPTIMIZER: OptimizerMethod(
optimizer_type=GRADIENT_DESCENT_OPTIMIZER,
python_parameters_class=python_optimization.GradientDescentParameters,
cpp_parameters_class=cpp_optimization.GradientDescentParameters,
cpp_parameters_class=None,
python_optimizer_class=python_optimization.GradientDescentOptimizer,
cpp_optimizer_class=cpp_optimization.GradientDescentOptimizer,
),
cpp_optimizer_class=None,
),
L_BFGS_B_OPTIMIZER: OptimizerMethod(
optimizer_type=L_BFGS_B_OPTIMIZER,
python_parameters_class=python_optimization.LBFGSBParameters,
cpp_parameters_class=None,
python_optimizer_class=python_optimization.LBFGSBOptimizer,
cpp_optimizer_class=None,
),
}
),
}

# Log Likelihood
LogLikelihoodMethod = namedtuple(
# Log Likelihood
LogLikelihoodMethod = namedtuple(
'LogLikelihoodMethod',
[
'log_likelihood_type',
'log_likelihood_class',
]
)
]
)

LOG_LIKELIHOOD_TYPES_TO_LOG_LIKELIHOOD_METHODS = {
LOG_LIKELIHOOD_TYPES_TO_LOG_LIKELIHOOD_METHODS = {
LOG_MARGINAL_LIKELIHOOD: LogLikelihoodMethod(
log_likelihood_type=LOG_MARGINAL_LIKELIHOOD,
log_likelihood_class=GaussianProcessLogMarginalLikelihood,
),
log_likelihood_class=PythonGaussianProcessLogMarginalLikelihood,
),
LEAVE_ONE_OUT_LOG_LIKELIHOOD: LogLikelihoodMethod(
log_likelihood_type=LEAVE_ONE_OUT_LOG_LIKELIHOOD,
log_likelihood_class=GaussianProcessLeaveOneOutLogLikelihood,
),
}
log_likelihood_class=None,
),
}
5 changes: 5 additions & 0 deletions moe/optimal_learning/python/python_version/covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def num_hyperparameters(self):
"""Return the number of hyperparameters of this covariance function."""
return self._hyperparameters.size

@staticmethod
def make_default_hyperparameters(dim):
"""Return a default set up hyperparameters given the dimension of the space."""
return numpy.ones(dim + 1)

def get_hyperparameters(self):
"""Get the hyperparameters (array of float64 with shape (num_hyperparameters)) of this covariance."""
return numpy.copy(self._hyperparameters)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# -*- coding: utf-8 -*-
"""Dummy test case that invokes all of the C++ unit tests."""
import moe.build.GPP as C_GP
from moe.optimal_learning.python.constant import CPP_COMPONENT_INSTALLED

if CPP_COMPONENT_INSTALLED:
import moe.build.GPP as C_GP

class TestCppUnitTestWrapper(object):
class TestCppUnitTestWrapper(object):

"""Calls a C++ function that runs all C++ unit tests.
"""Calls a C++ function that runs all C++ unit tests.

TODO(GH-115): Remove/fix this once C++ gets a proper unit testing framework.
TODO(GH-115): Remove/fix this once C++ gets a proper unit testing framework.

"""
"""

def test_run_cpp_unit_tests(self):
"""Call C++ function that runs all C++ unit tests and assert 0 errors."""
number_of_cpp_test_errors = C_GP.run_cpp_tests()
assert number_of_cpp_test_errors == 0
def test_run_cpp_unit_tests(self):
"""Call C++ function that runs all C++ unit tests and assert 0 errors."""
number_of_cpp_test_errors = C_GP.run_cpp_tests()
assert number_of_cpp_test_errors == 0
30 changes: 16 additions & 14 deletions moe/tests/optimal_learning/python/cpp_wrappers/exception_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
"""Tests for the C++-defined Python exception type objects."""
import pytest

import moe.build.GPP as C_GP
from moe.optimal_learning.python.constant import CPP_COMPONENT_INSTALLED

if CPP_COMPONENT_INSTALLED:
import moe.build.GPP as C_GP

class TestExceptionStructure(object):
class TestExceptionStructure(object):

"""Tests for the C++-defined Python exception type objects."""
"""Tests for the C++-defined Python exception type objects."""

def test_exception_class_hierarchy(self):
"""Test that the C++-defined Python exception type objects have the right class hiearchy."""
# Base class inherits from Exception
assert issubclass(C_GP.OptimalLearningException, Exception)
def test_exception_class_hierarchy(self):
"""Test that the C++-defined Python exception type objects have the right class hiearchy."""
# Base class inherits from Exception
assert issubclass(C_GP.OptimalLearningException, Exception)

type_objects = (C_GP.BoundsException, C_GP.InvalidValueException, C_GP.SingularMatrixException)
for type_object in type_objects:
assert issubclass(type_object, C_GP.OptimalLearningException)
type_objects = (C_GP.BoundsException, C_GP.InvalidValueException, C_GP.SingularMatrixException)
for type_object in type_objects:
assert issubclass(type_object, C_GP.OptimalLearningException)

def test_exception_thrown_from_cpp(self):
"""Test that a C++ interface function throws the expected type."""
with pytest.raises(C_GP.BoundsException):
C_GP.GaussianProcess([-1.0, [1.0]], [], [], [], 1, 0)
def test_exception_thrown_from_cpp(self):
"""Test that a C++ interface function throws the expected type."""
with pytest.raises(C_GP.BoundsException):
C_GP.GaussianProcess([-1.0, [1.0]], [], [], [], 1, 0)
Loading