-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python 3.6 migration, adding setup.py, and Travis integration (#1)
* Move everything in a subfolder and add a setup.pu * Use some pycharm magik * Fixing install_requires and switch to find_packages * Move init to pymb * Adding an __all__ to stuff * Add scikit-sparse as deps for cholesky * Fixing imports, and added scikit-sparse to reqs * Some more formatting changes * Change file( to open( * Change xrange to range * iteritems to items * Adding native rpy2 calls to pick up R version * Adding a Dockerfile to set up conda environment * Adding a travis yml * Use Miniconda docker * Add exec permish to bin 01 * Add a print statement in 01 * Adding miniconda in travis * Only keep py 3.6 * Remove -- frmo apt-get * Move apt packages to block * Add binaries for dependency installation * remove intel packages * Why is stage not continuing.. * Move conda installation to 01 shell * Move all the non R conda installs to use conda-forge * Remove before install block * Adding R and Python versions in jobs * Use R as travis base * Add DESCRIPT * Move 01 and 02 to install block and add a 03 tmb run check * Remove R-base from Conda install * Add more Python checks * Just have checks for now * Reset path thing? * Move apt-get installation inside 01 * try install again ugh * Remove second install true? * Try double scripting * Caching all directories in Travis * brek cache * break... more * Bad yml, fixing * Move back conda to before inst * install in ~/miniconda3 * Add some false installs * A lot of refactor * Add yes flag * - Adding build status on README - Squash build and test in a single stage - Move the R package installation in the install block * Adding apt-get installs of gcc and build ess * Oops missed the folder nav to PyMB * Switch to sourcing python instead of ipython * Move PyMB install to install block and make sure that rpy2 imports * Bad R link * Pip install rpy2 * Try and get libRblas to pick up * Update ld to include properly * Add rpy2.rinterface import * Test if we can run example without activating env in shell file * Adding RcppEigen dependency for TMB * Trying to test where TMB is breaking * Add libeigen3 as installing * Add RcppEigen include flag in linreg.py * let's build TMB from source and not include the Eigen flag * Bad CD * Run example inline
- Loading branch information
Nafis Sadat
authored
Aug 6, 2018
1 parent
85de1d9
commit 17731b3
Showing
11 changed files
with
358 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
sudo: required | ||
|
||
language: r | ||
|
||
os: | ||
- linux | ||
|
||
|
||
# Setup anaconda | ||
before_install: | ||
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh | ||
- chmod +x miniconda.sh | ||
- ./miniconda.sh -b -p /home/travis/miniconda3 | ||
- export PATH=/home/travis/miniconda3/bin:$PATH | ||
- export LD_LIBRARY_PATH=/home/travis/R-bin/lib/R/lib:/home/travis/miniconda3/lib:$LD_LIBRARY_PATH | ||
- R -e 'install.packages(c("Matrix", "RcppEigen", "numDeriv"), repos="http://cran.us.r-project.org", dependencies=T)' | ||
|
||
## Cache R packages | ||
cache: packages | ||
|
||
## Set up conda environment, TMB and PyMB | ||
install: | ||
- conda create -c conda-forge -n pymb_test -y python=3.6 numpy scipy libiconv libxml2 lxml scikit-sparse | ||
- source activate pymb_test | ||
- which -a python && pip install rpy2 && python -c "import rpy2.rinterface as rinterface" | ||
- git clone https://github.com/kaskr/adcomp.git && cd adcomp && make install-metis-full && cd .. | ||
- cd ../PyMB && python setup.py install | ||
|
||
jobs: | ||
include: | ||
- stage: Run PyMB tests | ||
script: | ||
- python Examples/linreg.py | ||
|
||
notifications: | ||
email: | ||
on_success: never | ||
on_failure: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package: PyMB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM continuumio/miniconda3 | ||
|
||
## Get all the Linux dependencies | ||
RUN apt-get update --fix-missing && \ | ||
apt-get install --yes \ | ||
wget \ | ||
curl \ | ||
bzip2 \ | ||
ca-certificates \ | ||
libglib2.0-0 \ | ||
libxext6 \ | ||
libsm6 \ | ||
libxrender1 \ | ||
git \ | ||
gcc \ | ||
g++ \ | ||
libreadline-dev \ | ||
libeigen3-dev \ | ||
tar \ | ||
build-essential && \ | ||
apt-get purge && \ | ||
apt-get clean | ||
|
||
## Install Python dependencies | ||
## NOTE: DO NOT install rpy2 from conda-forge, got issues | ||
RUN conda install -c conda-forge -y numpy scipy && \ | ||
scikit-sparse libiconv libxml2 lxml | ||
|
||
## Install R and rpy2 | ||
RUN conda install -c r -y \ | ||
r-base=3.5.0 && \ | ||
pip install rpy2 | ||
|
||
|
||
## Build TMB and it's dependencies | ||
RUN R -e 'install.packages(c("Matrix", "numDeriv", "RcppEigen"), repos="http://cran.us.r-project.org", dependencies=T)' && \ | ||
cd /opt && \ | ||
git clone https://github.com/kaskr/adcomp.git && cd adcomp && \ | ||
make install-metis-full | ||
|
||
## Install PyMB | ||
RUN cd /opt && \ | ||
git clone https://github.com/kforeman/PyMB.git && \ | ||
cd PyMB && python setup.py install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import numpy as np | ||
import os | ||
|
||
|
||
import PyMB | ||
import rpy2.robjects as ro | ||
import rpy2.rinterface as rin | ||
|
||
# create an empty model | ||
m = PyMB.model(name='linreg_code') | ||
|
||
# code for a simple linear regression | ||
linreg_code = ''' | ||
#include <TMB.hpp> | ||
template<class Type> | ||
Type objective_function<Type>::operator() (){ | ||
// DATA | ||
DATA_VECTOR(Y); | ||
DATA_VECTOR(x); | ||
// PARAMETERS | ||
PARAMETER(alpha); | ||
PARAMETER(Beta); | ||
PARAMETER(logSigma); | ||
// MODEL | ||
vector<Type> Y_hat = alpha + Beta*x; | ||
REPORT(Y_hat); | ||
Type nll = -sum(dnorm(Y, Y_hat, exp(logSigma), true)); | ||
return nll; | ||
} | ||
''' | ||
|
||
# Get the necessary paths to compile TMB code | ||
tmbinclude = ro.r('paste0(find.package("TMB"), "/include")')[0] | ||
# eigeninclude = ro.r('paste0(find.package("RcppEigen"), "/include")')[0] | ||
# tmbinclude = tmbinclude + ' -I' + eigeninclude | ||
rinclude = rin.R_HOME + "/include" | ||
rlib = rin.R_HOME + "/lib" | ||
|
||
# rpy2.rinterface.R_HOME | ||
|
||
# compile the model | ||
m.compile(codestr=linreg_code, | ||
cc='g++', | ||
R=rinclude, | ||
TMB=tmbinclude, | ||
LR=rlib, | ||
verbose=True, | ||
load=True) | ||
|
||
# simulate data | ||
N = 100 | ||
m.data['x'] = np.arange(N) | ||
m.data['Y'] = m.data['x'] + 0.5 + np.random.rand(N) | ||
|
||
# set initial parameter values | ||
m.init['alpha'] = 0. | ||
m.init['Beta'] = 0. | ||
m.init['logSigma'] = 0. | ||
|
||
# set random parameters | ||
m.random = ['alpha', 'Beta'] | ||
|
||
# fit the model | ||
m.optimize(draws=500) | ||
print(m.report('Y_hat')) | ||
m.print_parameters() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from PyMB.model import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.