Skip to content

Commit

Permalink
remove tensorflow support (#882)
Browse files Browse the repository at this point in the history
* excising tf support

* fix typo

* update travis in light of tf removal

* fix typo in run_tests.R

* additional removal of tf-related code

* fix syntax in test-benchmarks and
lingering tf ref in install_requirements

* remove base/64
  • Loading branch information
paciorek committed May 23, 2019
1 parent 9cdf5c7 commit 599ff8e
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 2,865 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cache:
matrix:
include:
- os: osx
env: NIMBLE_TEST_BATCH=1 NIMBLE_USE_TENSORFLOW=0
env: NIMBLE_TEST_BATCH=1
- os: linux
env: NIMBLE_TEST_BATCH=1
- os: linux
Expand Down Expand Up @@ -56,8 +56,6 @@ install:
- R CMD INSTALL packages/nimble

script:
- source /home/travis/.virtualenvs/r-tensorflow/bin/activate \
|| echo 'Missing tensorflow'
# - pip freeze
- ./run_tests.R

Expand Down
13 changes: 0 additions & 13 deletions install_requirements.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,3 @@ for (package in requirements) {
}
}

## Tensorflow requires custom installation.
if (Sys.getenv('NIMBLE_USE_TENSORFLOW') %in% c('', '1')) {
if (!require(tensorflow)) {
install.packages('tensorflow', repos = 'http://cran.us.r-project.org')
library(tensorflow)
}
tryCatch({
## Calling tf$ triggers loading of the python tensorflow library.
cat('Found Tensorflow version', tf$`__version__`, '\n')
}, error = function(e) {
install_tensorflow()
})
}
1 change: 0 additions & 1 deletion packages/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ clang-format: FORCE
nimble/inst/include/nimble/NimArrBase.h \
nimble/inst/include/nimble/NimArr.h \
nimble/inst/include/nimble/predefinedNimbleLists.h \
nimble/inst/include/nimble/tensorflow.h \
nimble/inst/CppCode/predefinedNimbleLists.cpp \
nimble/inst/CppCode/tensorflow.cpp \
-i
Expand Down
3 changes: 1 addition & 2 deletions packages/nimble/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Depends:
Imports:
methods,igraph,coda,R6
Suggests:
testthat,R2WinBUGS,rjags,rstan,xtable,abind,ggplot2,tensorflow,reticulate
testthat,R2WinBUGS,rjags,rstan,xtable,abind,ggplot2
URL: https://r-nimble.org
SystemRequirements: GNU make
License: BSD_3_clause + file LICENSE | GPL (>= 2)
Expand Down Expand Up @@ -66,7 +66,6 @@ Collate:
genCpp_maps.R
genCpp_liftMaps.R
genCpp_eigenization.R
genCpp_TFize.R
genCpp_addDebugMarks.R
genCpp_generateCpp.R
RCfunction_core.R
Expand Down
29 changes: 11 additions & 18 deletions packages/nimble/R/RCfunction_compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -419,24 +419,17 @@ RCfunProcessing <- setRefClass(
writeLines('***** READY FOR eigenize *****')
browser()
}

if(nimbleOptions('experimentalUseTensorflow')) {
exprClasses_TFize(compileInfo$nimExpr,
compileInfo$newLocalSymTab,
compileInfo$typeEnv)
} else {
tryResult <- try(
exprClasses_eigenize(compileInfo$nimExpr,
compileInfo$newLocalSymTab,
compileInfo$typeEnv))
if(inherits(tryResult, 'try-error')) {
stop(
paste('There is some problem at the Eigen processing step for this code:\n',
paste(deparse(compileInfo$origRcode),
collapse = '\n'),
collapse = '\n'),
call. = FALSE)
}
tryResult <- try(
exprClasses_eigenize(compileInfo$nimExpr,
compileInfo$newLocalSymTab,
compileInfo$typeEnv))
if(inherits(tryResult, 'try-error')) {
stop(
paste('There is some problem at the Eigen processing step for this code:\n',
paste(deparse(compileInfo$origRcode),
collapse = '\n'),
collapse = '\n'),
call. = FALSE)
}
if(debug) {
print('nimDeparse(compileInfo$nimExpr)')
Expand Down
3 changes: 1 addition & 2 deletions packages/nimble/R/cppDefs_RCfunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ RCfunctionDef <- setRefClass('RCfunctionDef',
'<math.h>',
nimbleIncludeFile("EigenTypedefs.h"),
nimbleIncludeFile("Utils.h"),
nimbleIncludeFile("accessorClasses.h"),
if(nimbleOptions('experimentalUseTensorflow')) nimbleIncludeFile("tensorflow.h") else character())
nimbleIncludeFile("accessorClasses.h"))
CPPusings <<- c(CPPusings)
callSuper(...)
},
Expand Down
29 changes: 0 additions & 29 deletions packages/nimble/R/cppDefs_cppProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,6 @@ cppProjectClass <- setRefClass('cppProjectClass',
writeDynamicRegistrationsDotCpp(cppName, dllName)
nimbleUserNamespace$sessionSpecificDll <- compileStaticCode(dllName, cppName, showCompilerOutput)
},
compileTensorflowWrapper = function(showCompilerOutput = nimbleOptions('showCompilerOutput')) {
# Load prerequisite DLLs.
if(!requireNamespace('tensorflow')) stop('tensorflow package must be installed. Try "install.packages(\"tensorflow\")"')
tfPath <- tensorflow::tf$`__path__` # This line triggers loading of _pywrap_tensorflow_internal.so.
tensorflowDllPath <- file.path(tfPath, 'python', '_pywrap_tensorflow_internal.so')
if(!file.exists(tensorflowDllPath)) stop(paste('Missing shared library', tensorflowDllPath))

timeStamp <- format(Sys.time(), "%m_%d_%H_%M_%S")
dllName <- paste0("nimble-tensorflow_", timeStamp)
cppName <- file.path(system.file(package = 'nimble'), 'CppCode', 'tensorflow.cpp')
nimbleUserNamespace$tensorflowWrapperDll <- compileStaticCode(dllName, cppName, showCompilerOutput)
},
compileFile = function(names, showCompilerOutput = nimbleOptions('showCompilerOutput'),
.useLib = UseLibraryMakevars) {
names <- Rname2CppName(names)
Expand Down Expand Up @@ -267,23 +255,6 @@ cppProjectClass <- setRefClass('cppProjectClass',
if(is.null(nimbleUserNamespace$sessionSpecificDll)) {
compileDynamicRegistrations(showCompilerOutput = showCompilerOutput)
}
if(nimbleOptions('experimentalUseTensorflow')) {
if (is.null(nimbleUserNamespace$tensorflowWrapperDll)) {
compileTensorflowWrapper(showCompilerOutput = showCompilerOutput)
}
compileOnce <- FALSE # TODO Compile tensorflow.cpp once and link against the .so file.
if (compileOnce) {
# This passes the the tensorflow wrapper .so as a compiler flag to R CMD SHLIB.
# This fails on travis because passing this linker flag overrides PKG_LIBS from Makevars.
# For more details, see http://www.hep.by/gnu/r-patched/r-exts/R-exts_96.html
# "Supplying linker commands as arguments to R CMD SHLIB will take precedence over PKG_LIBS in `Makevars'."
SHLIBcmd <- paste(SHLIBcmd, nimbleUserNamespace$tensorflowWrapperDll[['path']])
} else {
# This recompiles the tensorflow.cpp wrapper each time it is needed.
# This is inefficient, but works for now.
SHLIBcmd <- paste(SHLIBcmd, file.path(system.file(package = 'nimble'), 'CppCode', 'tensorflow.cpp'))
}
}

origSHLIBcmd <- SHLIBcmd
if(isTRUE(nimbleOptions('stopCompilationBeforeLinking'))) {## used only for testing, when we want to go quickly and skip linking and bail out
Expand Down
Loading

0 comments on commit 599ff8e

Please sign in to comment.