Instructions for cloning Stan with the math library as a submodule.

88 views
Skip to first unread message

Daniel Lee

unread,
Jul 7, 2015, 3:25:33 PM7/7/15
to stan...@googlegroups.com
These instructions start from scratch:

1. Clone the git repository
--------------------------------

Option 1: Clone the git repository normally
   > git clone https://github.com/stan-dev/stan.git
 
   (optional) If you want it in another folder other than "stan", you can add an additional argument to then end that will be the folder name. Example:
   > git clone https://github.com/stan-dev/stan.git stan-new

At this point, you would have cloned Stan without a copy of the Stan Math Library. To verify, you can type (assuming "stan" is the stan directory and you haven't changed working directories yet):
   > ls stan/lib/stan_math_2.7.0/
This should return a list of 0 elements.

OR

Option 2: Clone the git repository using the recursive flag which will pull down the math library
   > git clone --recursive https://github.com/stan-dev/stan.git

This will have cloned the Stan library and the Stan Math Library git submodule. You can verify by typing:
    > ls stan/lib/stan_math_2.7.0/

This should show something like:
    CONTRIBUTING.md doc             licenses        makefile        stan
    README.md       doxygen         make            runTests.py     test


2. Initialize the submodule and update it
------------------------------------------------------

Option 1: Use the make target: "math-revert"

It doesn't matter if you've used option 1 or 2 above. This will grab a copy of the math library and set it to the tagged version that's part of the current branch of Stan.

First get to the Stan directory:
    > cd stan

Then:
    > make math-revert

To checkout a branch of the math library and get it up to the HEAD, type:
   > make math-update/<branch name>

Once the math library is on a branch, to update the math library (for example, if you're on develop, you can bring it up to speed with):
    > make math-update

(if you typed "make math-update", this will also work)

If at any point you want to get back to the original state of the branch, type "make math-revert"


Option 2: Use git

    > git submodule init
    > git submodule update --recursive



Ok, so if you've already cloned Stan and have an empty lib/stan_math_2.7.0, you can start with initializing the submodule and updating it.



---------------------------------

Bob, can you take a look and try out these instructions? Where should we put them? If they need to go into the Stan repo, then we'll tag after the instructions get in. If they can live in a wiki, then I think we're good to tag now.




Daniel

Ben Goodrich

unread,
Jul 7, 2015, 4:16:18 PM7/7/15
to stan...@googlegroups.com, bea...@alum.mit.edu
On Tuesday, July 7, 2015 at 3:25:33 PM UTC-4, Daniel Lee wrote:
Bob, can you take a look and try out these instructions? Where should we put them? If they need to go into the Stan repo, then we'll tag after the instructions get in. If they can live in a wiki, then I think we're good to tag now.

I didn't read the instructions very carefully, but I got the math library to be submodule of StanHeaders. Attached is a StanHeaders for anyone to test. Joshua, I couldn't test OpenMx due to this unrelated error:

> devtools::install_github("OpenMx/OpenMx", ref="master")
...
WARNING
: Failed to download libnpsol.a from http://openmx.psyc.virginia.edu/packages/npsol/linux/x86_64/gcc/libnpsol.a
** libs
make
: *** No rule to make target 'omxSymbolTable.h', needed by 'Compute.o'.  Stop.
ERROR
: compilation failed for package OpenMx

Ben

Ben Goodrich

unread,
Jul 7, 2015, 4:16:52 PM7/7/15
to stan...@googlegroups.com, goodri...@gmail.com, bea...@alum.mit.edu
Actually attaching now. -- Ben
StanHeaders_2.7.0.tar.gz

Bob Carpenter

unread,
Jul 7, 2015, 4:52:11 PM7/7/15
to stan...@googlegroups.com
I think they should go on a Wiki page.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joshua N Pritikin

unread,
Jul 8, 2015, 1:48:15 AM7/8/15
to stan...@googlegroups.com, goodri...@gmail.com
On Tue, Jul 07, 2015 at 01:16:52PM -0700, Ben Goodrich wrote:
> Actually attaching now. -- Ben

Hm, I replaced my includes with simply,

#include <stan/math.hpp>

Now I get a template error,

g++ -I/usr/share/R/include -DNDEBUG -I"/home/joshua/R/x86_64-pc-linux-gnu-library/3.1/RcppEigen/include" -I"/home/joshua/R/x86_64-pc-linux-gnu-library/3.1/StanHeaders/include" -I"/home/joshua/R/x86_64-pc-linux-gnu-library/3.1/BH/include" -fopenmp -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -Wvla -Wno-unused-local-typedefs -fdiagnostics-color=auto -DOMX_BOUNDS_CHECK -D_GLIBCXX_DEBUG -g3 -fno-inline -fno-inline-small-functions -fno-default-inline -O0 -fmax-errors=1 -UNDEBUG -fpic -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -c omxMLFitFunction.cpp -o omxMLFitFunction.o
In file included from /home/joshua/R/x86_64-pc-linux-gnu-library/3.1/StanHeaders/include/stan/math.hpp:225:0,
from omxMLFitFunction.cpp:19:
/home/joshua/R/x86_64-pc-linux-gnu-library/3.1/StanHeaders/include/stan/math/prim/mat/fun/trace_inv_quad_form_ldlt.hpp: In instantiation of ‘typename boost::enable_if_c<((! stan::is_var<T>::value) && (! stan::is_var<T2>::value)), typename boost::math::tools::promote_args<RT1, RT2>::type>::type stan::math::trace_inv_quad_form_ldlt(const stan::math::LDLT_factor<T1, R2, C2>&, const Eigen::Matrix<T2, R2, C2>&) [with T1 = stan::math::fvar<stan::math::var>; T2 = stan::math::fvar<stan::math::var>; int R2 = -1; int C2 = -1; int R3 = -1; int C3 = 1; typename boost::enable_if_c<((! stan::is_var<T>::value) && (! stan::is_var<T2>::value)), typename boost::math::tools::promote_args<RT1, RT2>::type>::type = stan::math::fvar<stan::math::var>]’:
multi_normal_sufficient.hpp:76:63: required from ‘typename boost::math::tools::promote_args<T_sample, typename stan::scalar_type<T2>::type, T_covar>::type stan::prob::multi_normal_sufficient_log(int, const Eigen::Matrix<Scalar, -1, 1>&, const Eigen::Matrix<LhsScalar, -1, -1, 0>&, const T_loc&, const Eigen::Matrix<LhsScalar, -1, -1, 0>&) [with T_sample = double; T_loc = Eigen::Matrix<stan::math::fvar<stan::math::var>, -1, 1>; T_covar = stan::math::fvar<stan::math::var>; typename boost::math::tools::promote_args<T_sample, typename stan::scalar_type<T2>::type, T_covar>::type = stan::math::fvar<stan::math::var>]’
omxMLFitFunction.cpp:133:88: required from ‘T multi_normal_deriv::operator()(Eigen::Matrix<Scalar, -1, 1>&) const [with T = stan::math::fvar<stan::math::var>]’
/home/joshua/R/x86_64-pc-linux-gnu-library/3.1/StanHeaders/include/stan/math/mix/mat/functor/hessian.hpp:59:39: required from ‘void stan::math::hessian(const F&, const Eigen::Matrix<double, -1, 1>&, double&, Eigen::Matrix<double, -1, 1>&, Eigen::Matrix<double, -1, -1>&) [with F = multi_normal_deriv]’
omxMLFitFunction.cpp:218:77: required from here
/home/joshua/R/x86_64-pc-linux-gnu-library/3.1/StanHeaders/include/stan/math/prim/mat/fun/trace_inv_quad_form_ldlt.hpp:33:66: error: call of overloaded ‘multiply(Eigen::Matrix<stan::math::fvar<stan::math::var>, 1, -1, 1, 1, -1>, Eigen::Matrix<stan::math::fvar<stan::math::var>, -1, 1>)’ is ambiguous
return trace(multiply(transpose(B), mdivide_left_ldlt(A, B)));

Any ideas? Need to see the full source code?

Ben Goodrich

unread,
Jul 8, 2015, 7:03:04 AM7/8/15
to stan...@googlegroups.com, jpri...@pobox.com
On Wednesday, July 8, 2015 at 1:48:15 AM UTC-4, Joshua Pritikin wrote:
On Tue, Jul 07, 2015 at 01:16:52PM -0700, Ben Goodrich wrote:
>    Actually attaching now. -- Ben

Hm, I replaced my includes with simply,

  #include <stan/math.hpp>

Now I get a template error,

I did not realize you were utilizing fvars. The #include <stan/math.hpp> is only for reverse mode I think. All the fvar stuff is under stan/math/fwd/ but there might not be a meta-include file, in which case you have to #include the header files that you are using one by one.

Ben

Joshua N Pritikin

unread,
Jul 8, 2015, 11:49:37 PM7/8/15
to stan...@googlegroups.com
On Wed, Jul 08, 2015 at 04:03:04AM -0700, Ben Goodrich wrote:
> I did not realize you were utilizing fvars. The #include
> <stan/math.hpp> is only for reverse mode I think. All the fvar stuff is
> under stan/math/fwd/ but there might not be a meta-include file, in
> which case you have to #include the header files that you are using one
> by one.

After some fiddling, I find that this works,

#include <stan/math.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/scal/fun/value_of.hpp>
#include <stan/math/fwd/scal/fun/is_nan.hpp>
#include <stan/math/fwd/scal/fun/abs.hpp>
#include <stan/math/fwd/scal/fun/log.hpp>
#include <stan/math/fwd/mat/fun/multiply.hpp>
#include <stan/math/mix/mat/functor/hessian.hpp>

OpenMx is ready for the next Stan release again. ;-)

--
Joshua N. Pritikin
Department of Psychology
University of Virginia
485 McCormick Rd, Gilmer Hall Room 102
Charlottesville, VA 22904
http://people.virginia.edu/~jnp3bc

Ben Goodrich

unread,
Jul 9, 2015, 12:30:09 PM7/9/15
to stan...@googlegroups.com, jpri...@pobox.com
On Wednesday, July 8, 2015 at 11:49:37 PM UTC-4, Joshua Pritikin wrote:
On Wed, Jul 08, 2015 at 04:03:04AM -0700, Ben Goodrich wrote:
>    I did not realize you were utilizing fvars. The #include
>    <stan/math.hpp> is only for reverse mode I think. All the fvar stuff is
>    under stan/math/fwd/ but there might not be a meta-include file, in
>    which case you have to #include the header files that you are using one
>    by one.

After some fiddling, I find that this works,

#include <stan/math.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/scal/fun/value_of.hpp>
#include <stan/math/fwd/scal/fun/is_nan.hpp>
#include <stan/math/fwd/scal/fun/abs.hpp>
#include <stan/math/fwd/scal/fun/log.hpp>
#include <stan/math/fwd/mat/fun/multiply.hpp>
#include <stan/math/mix/mat/functor/hessian.hpp>

OpenMx is ready for the next Stan release again. ;-)

If we are putting StanHeaders out there, ostensibly with support of fvars, should Rob's PRs be merged first? I guess OpenMx is not using the affected distributions but somebody could.

Ben

Reply all
Reply to author
Forward
0 new messages