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

Enable bindings generation via Binder #1

Open
wants to merge 4 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
pyternafold.so
src/pyternafold.*
*/*.o
src/contrafold
src/api_test
src/score_prediction
src/optimize.*
input_data/*
old_input_data/*
datalists/*.txt
local_analysis/*
.vscode
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "extern/pybind11"]
path = extern/pybind11
url = ../../pybind/pybind11
branch = stable
34 changes: 34 additions & 0 deletions BIND
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# from parent eternafold dir
~/programs/build_binder/build/bin/binder --config binder.config --root-module pyternafold --prefix src --bind "" --single-file all_includes.hpp -- -I./src -std=c++11 -DNDEBUG

cd src

make
g++ -O3 -std=c++11 -mfpmath=sse -msse -msse2 -msse3 -DEVIDENCE_SR -DEVIDENCE_PARS -I./ -DNDEBUG -W -pipe -Wundef -Winline --param large-function-growth=100000 -Wall -fPIC -c EncapsulatedPostScript.cpp

pybase=`which python3`
g++ \
-O3 \
-I${pybase::-12}/include/python3.7m -I../extern/pybind11/include -I./ -shared \
-std=c++11 -c pyternafold.cpp \
-o pyternafold.o -fPIC

cd ..

g++ -o pyternafold.so -shared src/pyternafold.o \
src/ParameterManager.o src/LBFGS.o src/LineSearch.o \
src/ComputationEngine.o src/ComputationWrapper.o \
src/OptimizationWrapper.o \
src/InnerOptimizationWrapperStochasticGradient.o \
src/InnerOptimizationWrapperSubgradientMethod.o \
src/InnerOptimizationWrapperLBFGS.o \
src/OuterOptimizationWrapper.o \
src/InnerOptimizationWrapperEM.o \
src/InnerOptimizationWrapper.o \
src/CGOptimizationWrapper.o \
src/SubgradientMethod.o \
src/CGLinear.o \
src/EM.o \
src/GammaMLE.o \
src/FileDescription.o src/Options.o \
src/SStruct.o src/Utilities.o src/EncapsulatedPostScript.o src/InferenceEngine.o src/contrafold_api.o #src/Contrafold.o
13 changes: 13 additions & 0 deletions all_includes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// #include <InnerOptimizationWrapperStochasticGradient.hpp>
// #include <CGOptimizationWrapper.hpp>
// #include <GammaMLE.hpp>
// #include <CGLinear.hpp>
// #include <EncapsulatedPostScript.hpp>
// #include <OuterOptimizationWrapper.hpp>
#include <ParameterManager.hpp>
#include <SStruct.hpp>
#include <InferenceEngine.hpp>
#include <DistributedComputation.hpp>
#include <ComputationEngine.hpp>
#include <ComputationWrapper.hpp>
#include <contrafold_api.hpp>
1 change: 1 addition & 0 deletions binder.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-class std::basic_ostream
1 change: 1 addition & 0 deletions extern/pybind11
Submodule pybind11 added at 8de777
6 changes: 2 additions & 4 deletions src/BundleMethod.ipp → src/BundleMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
// Constructor.
//////////////////////////////////////////////////////////////////////

template<class RealT>
BundleMethod<RealT>::BundleMethod
BundleMethod::BundleMethod
(
const int MAX_ITERATIONS, // maximum number of iterations to run subgradient method
const double lambda
Expand All @@ -29,8 +28,7 @@ BundleMethod<RealT>::BundleMethod
// Implementation of bundle methods for optimization
//////////////////////////////////////////////////////////////////////

template<class RealT>
RealT BundleMethod<RealT>::Minimize(std::vector<RealT> &x)
RealT BundleMethod::Minimize(std::vector<RealT> &x)
{

CBMRMInnerSolver* innerSolver; // pointer to inner solver object
Expand Down
1 change: 0 additions & 1 deletion src/BundleMethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ using namespace std;
// Implementation of bundle optimization routine.
//////////////////////////////////////////////////////////////////////

template<class RealT>
class BundleMethod
{
const int MAX_ITERATIONS;
Expand Down
6 changes: 4 additions & 2 deletions src/CGLinear.ipp → src/CGLinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
// algorithm for solving linear systems.
//////////////////////////////////////////////////////////////////////

#include <CGLinear.hpp>
#include <Utilities.ipp>

//////////////////////////////////////////////////////////////////////
// CGLinear()
//
// Implementation of conjugate gradient for solving linear
// systems Ax = b, where A is symmetric positive definite.
//////////////////////////////////////////////////////////////////////

template<class Real>
Real CGLinear<Real>::Minimize
Real CGLinear::Minimize
(
const std::vector<Real> &b, // right hand side
std::vector<Real> &x, // initial parameter vector
Expand Down
4 changes: 1 addition & 3 deletions src/CGLinear.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// systems Ax = b, where A is symmetric positive definite.
//////////////////////////////////////////////////////////////////////

template<class Real>
using Real = double;
class CGLinear {
public:
Real Minimize
Expand All @@ -38,6 +38,4 @@ class CGLinear {
virtual void Report(const std::string &s) = 0;
};

#include "CGLinear.ipp"

#endif
20 changes: 8 additions & 12 deletions src/CGOptimizationWrapper.ipp → src/CGOptimizationWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,44 @@
#include "CGOptimizationWrapper.hpp"

//////////////////////////////////////////////////////////////////////
// CGOptimizationWrapper<RealT>::CGOptimizationWrapper()
// CGOptimizationWrapper::CGOptimizationWrapper()
//
// Constructor.
//////////////////////////////////////////////////////////////////////

template<class RealT>
CGOptimizationWrapper<RealT>::CGOptimizationWrapper(OptimizationWrapper<RealT> *optimization_wrapper,
CGOptimizationWrapper::CGOptimizationWrapper(OptimizationWrapper *optimization_wrapper,
const std::vector<int> &units,
const std::vector<RealT> &w,
const std::vector<RealT> &C) :
CGLinear<RealT>(), optimization_wrapper(optimization_wrapper), units(units), w(w), C(C)
CGLinear(), optimization_wrapper(optimization_wrapper), units(units), w(w), C(C)
{}

//////////////////////////////////////////////////////////////////////
// CGOptimizationWrapper<RealT>::ComputeAx()
// CGOptimizationWrapper::ComputeAx()
//
// Compute Hessian-vector product.
//////////////////////////////////////////////////////////////////////

template<class RealT>
void CGOptimizationWrapper<RealT>::ComputeAx(std::vector<RealT> &Ax, const std::vector<RealT> &x)
void CGOptimizationWrapper::ComputeAx(std::vector<RealT> &Ax, const std::vector<RealT> &x)
{
std::vector<RealT> Ce = optimization_wrapper->GetParameterManager().ExpandParameterGroupValues(C);
Ax = optimization_wrapper->GetComputationWrapper().ComputeHessianVectorProduct(units, w, x, true, optimization_wrapper->GetOptions().GetRealValue("log_base")) + Ce * x;
}

//////////////////////////////////////////////////////////////////////
// CGOptimizationWrapper<RealT>::Report()
// CGOptimizationWrapper::Report()
//
// Provide progress report on CG algorithm.
//////////////////////////////////////////////////////////////////////

template<class RealT>
void CGOptimizationWrapper<RealT>::Report(int iteration, const std::vector<RealT> &x, RealT f, RealT step_size)
void CGOptimizationWrapper::Report(int iteration, const std::vector<RealT> &x, RealT f, RealT step_size)
{
optimization_wrapper->PrintMessage(SPrintF("CG iteration %d: f = %lf, |x| = %lf, step = %lf, efficiency = %lf%%",
iteration, double(f), double(Norm(x)), double(step_size),
double(optimization_wrapper->GetComputationEngine().GetEfficiency())));
}

template<class RealT>
void CGOptimizationWrapper<RealT>::Report(const std::string &s)
void CGOptimizationWrapper::Report(const std::string &s)
{
optimization_wrapper->PrintMessage(SPrintF("CG message: %s", s.c_str()));
}
10 changes: 3 additions & 7 deletions src/CGOptimizationWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@
#include "OptimizationWrapper.hpp"
#include "CGLinear.hpp"

template<class RealT>
class OptimizationWrapper;

//////////////////////////////////////////////////////////////////////
// class CGOptimizationWrapper
//////////////////////////////////////////////////////////////////////

template<class RealT>
class CGOptimizationWrapper : public CGLinear<RealT>
class CGOptimizationWrapper : public CGLinear
{
OptimizationWrapper<RealT> *optimization_wrapper;
OptimizationWrapper *optimization_wrapper;
const std::vector<int> units;
const std::vector<RealT> w;
const std::vector<RealT> C;

public:
CGOptimizationWrapper(OptimizationWrapper<RealT> *optimizer,
CGOptimizationWrapper(OptimizationWrapper *optimizer,
const std::vector<int> &units,
const std::vector<RealT> &w,
const std::vector<RealT> &C);
Expand All @@ -36,6 +34,4 @@ class CGOptimizationWrapper : public CGLinear<RealT>
void Report(const std::string &s);
};

#include "CGOptimizationWrapper.ipp"

#endif
Loading