Skip to content

Commit

Permalink
Merge branch 'develop' into hyper3f2-expose
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Oct 21, 2022
2 parents fce33cb + 4d2b936 commit 53a02e3
Show file tree
Hide file tree
Showing 59 changed files with 2,751 additions and 1,472 deletions.
11 changes: 5 additions & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

Thanks for reading! We love contributions from everyone in the form of good discussion, issues, and pull requests.

This is the short version. There's more information on the [wiki](https://github.com/stan-dev/math/wiki/Developer-Doc#contributing).

This is the short version. There's more information on the [documentation site](https://mc-stan.org/math/developer_guide.html).
## Issues

We reserve [issues](https://github.com/stan-dev/math/issues) for bugs and feature requests that are defined well enough for a developer to tackle. If you have general questions about the Math library, please see the [Discussion](#discussion) section.
Expand Down Expand Up @@ -31,22 +30,22 @@ Open feature requests should be the ones we want to implement in the Math librar

## Pull Requests

All changes to the Math library are handled through [pull requests](https://github.com/stan-dev/math/pulls). Each pull request should correspond to an issue. We follow a [modified GitFlow branching model](https://github.com/stan-dev/stan/wiki/Dev:-Git-Process) for development.
All changes to the Math library are handled through [pull requests](https://github.com/stan-dev/math/pulls). Each pull request should correspond to an issue. We follow a [modified GitFlow branching model](https://github.com/stan-dev/stan/wiki/Developer-process-overview#2-create-a-branch-for-the-issue) for development.

When a contributor creates a pull request for inclusion to the Math library, here are some of the things we expect:

1. the contribution maintains the Math library's open-source [license](https://github.com/stan-dev/math/wiki/Developer-Doc#licensing): 3-clause BSD
1. the contribution maintains the Math library's open-source [license](https://github.com/stan-dev/stan/wiki/Stan-Licensing): 3-clause BSD
2. the code base remains stable after merging the pull request; we expect the `develop` branch to always be in a good state
3. the changes are maintainable. In code review, we look at the design of the proposed code. We also expect documentation. It should look like idiomatic C++.
4. the changes are tested. For bugs, we expect at least one test that fails before the patch and is fixed after the patch. For new features, we expect at least one test that shows expected behavior and one test that shows the behavior when there's an error.
5. the changes adhere to the Math library's [C++ standards](https://github.com/stan-dev/stan/wiki/Code-Quality). Consistency really helps.
5. the changes adhere to the Math library's [C++ standards](https://github.com/stan-dev/stan/wiki/Coding-Style-and-Idioms). Consistency really helps.

Pull requests are code reviewed after they pass our continuous integration tests. We expect all the above before a pull request is merged. We are an open-source project and once code makes it into the repository, it's on the community to maintain.

It is the responsibility of the contributor submitting the pull request that the code meets these requirements. We're open-source. Once the code gets into the code base, the community of developers take ownership of it.

### Code Reviews
See the [Code Review Guidelines](https://github.com/stan-dev/math/wiki/Developer-Doc#code-review-guidelines) on the Math wiki.
See the [Code Review Guidelines](https://github.com/stan-dev/stan/wiki/Developer-process-overview#code-review-guidelines) on the Math wiki.


## Discussion
Expand Down
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Thanks for submitting a pull request! Please remove this text when submitting.

Start by filling in the Summary, Tests, and Side Effects sections of this pull request and then work through the handy checklist at the bottom. If anything significant is missing, the pull request may be closed until it's ready. The full guidebook on how pull requests are reviewed is here: [Code Review Guidelines](https://github.com/stan-dev/math/wiki/Developer-Doc#code-review-guidelines).
Start by filling in the Summary, Tests, and Side Effects sections of this pull request and then work through the handy checklist at the bottom. If anything significant is missing, the pull request may be closed until it's ready. The full guidebook on how pull requests are reviewed is here: [Code Review Guidelines](https://github.com/stan-dev/stan/wiki/Developer-process-overview#code-review-guidelines).

## Summary

Expand Down Expand Up @@ -40,7 +40,7 @@ Replace this text with a short note on what will change if this pull request is
- header checks pass, (`make test-headers`)
- dependencies checks pass, (`make test-math-dependencies`)
- docs build, (`make doxygen`)
- code passes the built in [C++ standards](https://github.com/stan-dev/stan/wiki/Code-Quality) checks (`make cpplint`)
- code passes the built in [C++ standards](https://github.com/stan-dev/stan/wiki/Coding-Style-and-Idioms) checks (`make cpplint`)

- [ ] the code is written in idiomatic C++ and changes are documented in the doxygen

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/header_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ on:
- 'README.md'
- 'RELEASE-NOTES.txt'

permissions:
contents: read

jobs:
windows:
permissions:
actions: write # for n1hility/cancel-previous-runs to create & stop workflow runs
contents: read # for actions/checkout to fetch code
name: Windows
runs-on: windows-latest

Expand Down Expand Up @@ -47,6 +53,9 @@ jobs:
run: make -j2 test-headers

opencl:
permissions:
actions: write # for n1hility/cancel-previous-runs to create & stop workflow runs
contents: read # for actions/checkout to fetch code
name: OpenCL
runs-on: ubuntu-latest

Expand All @@ -64,6 +73,9 @@ jobs:
echo "STAN_OPENCL=true" > make/local
make -j2 test-headers
no_range_checks:
permissions:
actions: write # for n1hility/cancel-previous-runs to create & stop workflow runs
contents: read # for actions/checkout to fetch code
name: NoRange
runs-on: ubuntu-latest

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ on:
- 'LICENSE.md'
- 'README.md'
- 'RELEASE-NOTES.txt'
permissions:
contents: read

jobs:
prim-rev:
permissions:
actions: write # for n1hility/cancel-previous-runs to create & stop workflow runs
contents: read # for actions/checkout to fetch code
name: prim and rev tests
runs-on: windows-latest

Expand Down
165 changes: 9 additions & 156 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ in order to facilitate the construction and utilization of algorithms
that utilize derivatives.


Documentation, Installation, and Examples
--------------

All of Stan math's documentation is hosted on our website below. Please do not
reference articles in the wiki as they are outdated and not maintained.

[mc-stan.org/math](https://mc-stan.org/math/)


Licensing
---------
The Stan Math Library is licensed under the [new BSD
Expand All @@ -17,159 +26,3 @@ licensed under the Apache 2.0 license. This dependency implies an
additional restriction as compared to the new BSD license alone. The
Apache 2.0 license is incompatible with GPL-2 licensed code if
distributed as a unitary binary. You may refer to the Licensing page on the [Stan wiki](https://github.com/stan-dev/stan/wiki/Stan-Licensing).

Required Libraries
------------------
Stan Math depends on four libraries:

- Boost (version 1.78.0): [Boost Home Page](https://www.boost.org)
- Eigen (version 3.3.9: [Eigen Home Page](https://eigen.tuxfamily.org/index.php?title=Main_Page)
- SUNDIALS (version 6.1.1): [Sundials Home Page](https://computing.llnl.gov/projects/sundials)
- Intel TBB (version 2020.3): [Intel TBB Home Page](https://www.threadingbuildingblocks.org)

These are distributed under the `lib/` subdirectory. Only these
versions of the dependent libraries have been tested with Stan Math.

Documentation
------------

Documentation for Stan math is available at [mc-stan.org/math](https://mc-stan.org/math/)

Contributing
------------

We love contributions from everyone in the form of good discussion, issues, and pull requests.
If you are interested in contributing to Stan math please check the Contributor Guide at [mc-stan.org/math](https://mc-stan.org/math/).

Installation
------------
The Stan Math Library is a C++ library which depends on the Intel TBB
library and requires for some functionality (ordinary differential
equations and root solving) the Sundials library. The build system is
the make facility, which is used to manage all dependencies.

A simple hello world program using Stan Math is as follows:

```cpp
#include <stan/math.hpp>
#include <iostream>

int main() {
std::cout << "log normal(1 | 2, 3)="
<< stan::math::normal_log(1, 2, 3)
<< std::endl;
}
```

If this is in the file `/path/to/foo/foo.cpp`, then you can compile
and run this with something like this, with the `/path/to` business
replaced with actual paths:

```bash
> cd /path/to/foo
> make -j4 -f /path/to/stan-math/make/standalone math-libs
> make -f /path/to/stan-math/make/standalone foo
> ./foo
log normal(1 | 2, 3)=-2.07311
```

The first make command with the `math-libs` target ensures that all
binary dependencies of Stan Math are built and ready to use. The `-j4`
instructs `make` to use 4 cores concurrently which should be adapted
to your needs. The second make command ensures that the Stan Math
sources and all of the dependencies are available to the compiler when
building `foo`.

An example of a real instantiation whenever the path to Stan Math is
`~/stan-dev/math/`:

```bash
> make -j4 -f ~/stan-dev/math/make/standalone math-libs
> make -f ~/stan-dev/math/make/standalone foo
```
The `math-libs` target has to be called only once, and can be omitted
for subsequent compilations.

The standalone makefile ensures that all the required `-I` include
statements are given to the compiler and the necessary libraries are
linked: `~/stan-dev/math` and `~/stan-dev/math/lib/eigen_3.3.9` and
`~/stan-dev/math/lib/boost_1.78.0` and
`~/stan-dev/math/lib/sundials_6.1.1/include` and
`~/stan-dev/math/lib/tbb_2020.3/include`. The
`~/stan-dev/math/lib/tbb` directory is created by the `math-libs`
makefile target automatically and contains the dynamically loaded
Intel TBB library. The flags `-Wl,-rpath,...` instruct the linker to
hard-code the path to the dynamically loaded Intel TBB library inside
the stan-math directory into the final binary. This way the Intel TBB
is found when executing the program.

Note for Windows users: On Windows the `-rpath` feature as used by
Stan Math to hardcode an absolute path to a dynamically loaded library
does not work. On Windows the Intel TBB dynamic library `tbb.dll` is
located in the `math/lib/tbb` directory. The user can choose to copy
this file to the same directory of the executable or to add the
directory `/path/to/math/lib/tbb` as absolute path to the system-wide
`PATH` variable.

Intel TBB
---------

`math` supports the new interface of Intel TBB, can be configured to use an external copy of TBB (e.g., with [`oneTBB`](https://github.com/oneapi-src/oneTBB) or the system TBB library), using the `TBB_LIB` and `TBB_INC` environment variables.

To build the development version of `math` with [`oneTBB`](https://github.com/oneapi-src/oneTBB):

- Install [`oneTBB`](https://github.com/oneapi-src/oneTBB).

For example, installing [`oneTBB`](https://github.com/oneapi-src/oneTBB) on Linux 64-bit (`x86_64`) to `$HOME` directory (change if needed!):
```bash
TBB_RELEASE="https://api.github.com/repos/oneapi-src/oneTBB/releases/latest"
TBB_TAG=$(curl --silent $TBB_RELEASE | grep -Po '"tag_name": "\K.*?(?=")')
TBB_VERSION=${TBB_TAG#?}

wget https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-lin.tgz
tar zxvf oneapi-tbb-$TBB_VERSION-lin.tgz -C $HOME

export TBB="$HOME/oneapi-tbb-$TBB_VERSION"
```
Note that you may replace `TBB_VERSION=${TBB_TAG#?}` with a custom version number if needed ( check available releases [here](https://github.com/oneapi-src/oneTBB/releases) ).

- Set the TBB environment variables (specifically: `TBB` for the installation prefix, `TBB_INC` for the directory that includes the header files, and `TBB_LIB` for the libraries directory).

For example, installing [`oneTBB`](https://github.com/oneapi-src/oneTBB) on Linux 64-bit (`x86_64`) to `$HOME` directory (change if needed!):
```bash
source $TBB/env/vars.sh intel64

export TBB_INC="$TBB/include"
export TBB_LIB="$TBB/lib/intel64/gcc4.8"
```

- Set `Stan` local compiler flags to use the new TBB interface:
```bash
mkdir -p ~/.config/stan
echo TBB_INTERFACE_NEW=true>> ~/.config/stan/make.local
```

Compilers
---------

The above example will use the default compiler of the system as
determined by `make`. On Linux this is usually `g++`, on MacOS
`clang++`, and for Windows this is `g++` if the RTools for Windows are
used. There's nothing special about any of these and they can be
changed through the `CXX` variable of `make`. The recommended way to
set this variable for the Stan Math library is by creating a
`make/local` file within the Stan Math library directory. Defining
`CXX=g++` in this file will ensure that the GNU C++ compiler is always
used, for example. The compiler must be able to fully support C++11
and partially the C++14 standard. The `g++` 4.9.3 version part of
RTools for Windows currently defines the minimal C++ feature set
required by the Stan Math library.

Note that whenever the compiler is changed, the user usually must
clean and rebuild all binary dependencies with the commands:
```bash
> make -f path/to/stan-math/make/standalone math-clean
> make -j4 -f path/to/stan-math/make/standalone math-libs
```
This ensures that the binary dependencies are created with the new
compiler.
Loading

0 comments on commit 53a02e3

Please sign in to comment.