-
-
Notifications
You must be signed in to change notification settings - Fork 371
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
Parallel Adaptive Nuts #3033
Merged
+1,286
−71
Merged
Parallel Adaptive Nuts #3033
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
5edf4e2
adds file_stream_writer and run_adaptive_sampler method for parallel
SteveBronder faa5eb0
fix grammar error for parallel run_adaptive_sampler
SteveBronder 751403f
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot a08ba35
adds test for parallel adaptive
SteveBronder a4c9679
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 04836ef
include mutex
SteveBronder 0608601
make stream_writer not final
SteveBronder 3ebbc5c
init threadpool
SteveBronder a3bf12b
update generate_transitions and cleanup run_adaptive_sampler
SteveBronder 9056101
Merge commit '7eeaf3c58fdd1c40aa62ba7158106529f2fd9563' into HEAD
yashikno 5c7b0bd
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 117274f
start diag_e_adapt parallel
SteveBronder 99d64c1
adds tests for parallel adapter
SteveBronder 35f88a7
Merge remote-tracking branch 'origin/develop' into feature/parallel-a…
SteveBronder ebeb1f9
remove statics from softmax metric and cleanup tests
SteveBronder 142a94a
update to feature/parallel-adapt
SteveBronder 558eeb0
use normal diag_e_adapt if n_chain == 0
SteveBronder 5055e21
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 34114be
use parallel loop around run_adaptive_sampler
SteveBronder 8458782
remove run_adaptive_sampler parallel version
SteveBronder 38e168d
update to remove parallel run_adaptive_sampler
SteveBronder e72409b
Merge commit 'f3bf21bc20271ebb9f7c9613bdb17c16d5cc0c1b' into HEAD
yashikno a2daea0
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 427769c
update get_context to return back the input
SteveBronder f654f37
update math
SteveBronder df1542e
update with docs
SteveBronder 0a5075b
update stan math
SteveBronder ce2b7a1
update file streamer and adapt
SteveBronder e2dfbaf
update stan math
SteveBronder fce9734
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 059a176
adds dense_e_adapt for parallel chains
SteveBronder d99daa0
Merge branch 'feature/parallel-nuts' of github.com:stan-dev/stan into…
SteveBronder 7dd37b6
Merge commit '55f6e5794c1a5a76f8cf23bc154dd254ede3258e' into HEAD
yashikno 147fba5
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot ddfcf86
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder a2666e4
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder 323adb9
update to reflect parallel chain design doc
SteveBronder 7621468
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot f69b139
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder 7146784
make changes so API matches up with design doc
SteveBronder e1e37a4
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot ea9a556
update docs
SteveBronder f3adfb6
Merge branch 'feature/parallel-nuts' of github.com:stan-dev/stan into…
SteveBronder 57031ac
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot ada9dcb
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder bd76742
update so tbb is only used when STAN_THREADS is defined
SteveBronder 851ba01
update to use simple partitioner
SteveBronder 429e7de
fix chain_id default so all is 1
SteveBronder c66a2fd
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 45d64b3
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder 724f887
update create_rng() to follow the design doc
SteveBronder 203d6f3
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot fa22037
adds template to unique_stream_writer to set the stream type, adds te…
SteveBronder 34baa29
Merge branch 'feature/parallel-nuts' of github.com:stan-dev/stan into…
SteveBronder d0e501b
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder a115c82
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 07b2230
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder 51c4472
update dense and diag adapt for math changes
SteveBronder 9866ef0
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder 1ad42b4
cleanup docs and change printout of chain number to take the initial …
SteveBronder c50cf1a
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot c09ca13
update printing logic
SteveBronder 91d51e1
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot 569df85
update to remove +1 from chain number
SteveBronder bbf4d37
Merge remote-tracking branch 'origin/develop' into feature/parallel-nuts
SteveBronder 4f82e24
Make sure to use num_chains instead of n_chain everywhere, fix docs, …
SteveBronder a11a48a
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,127 @@ | ||
#ifndef STAN_CALLBACKS_UNIQUE_STREAM_WRITER_HPP | ||
#define STAN_CALLBACKS_UNIQUE_STREAM_WRITER_HPP | ||
|
||
#include <stan/callbacks/writer.hpp> | ||
#include <ostream> | ||
#include <vector> | ||
#include <string> | ||
|
||
namespace stan { | ||
namespace callbacks { | ||
|
||
/** | ||
* <code>unique_stream_writer</code> is an implementation | ||
* of <code>writer</code> that holds a unique pointer to the stream it is | ||
* writing to. | ||
* @tparam Stream A type with with a valid `operator<<(std::string)` | ||
*/ | ||
template <typename Stream> | ||
class unique_stream_writer final : public writer { | ||
public: | ||
/** | ||
* Constructs a unique stream writer with an output stream | ||
* and an optional prefix for comments. | ||
* | ||
* @param[in, out] A unique pointer to a type inheriting from `std::ostream` | ||
* @param[in] comment_prefix string to stream before each comment line. | ||
* Default is "". | ||
*/ | ||
explicit unique_stream_writer(std::unique_ptr<Stream>&& output, | ||
const std::string& comment_prefix = "") | ||
: output_(std::move(output)), comment_prefix_(comment_prefix) {} | ||
|
||
unique_stream_writer(); | ||
unique_stream_writer(unique_stream_writer& other) = delete; | ||
unique_stream_writer(unique_stream_writer&& other) | ||
: output_(std::move(other.output_)), | ||
comment_prefix_(std::move(other.comment_prefix_)) {} | ||
/** | ||
* Virtual destructor | ||
*/ | ||
virtual ~unique_stream_writer() {} | ||
|
||
/** | ||
* Writes a set of names on a single line in csv format followed | ||
* by a newline. | ||
* | ||
* Note: the names are not escaped. | ||
* | ||
* @param[in] names Names in a std::vector | ||
*/ | ||
void operator()(const std::vector<std::string>& names) { | ||
write_vector(names); | ||
} | ||
/** | ||
* Get the underlying stream | ||
*/ | ||
auto& get_stream() { return *output_; } | ||
|
||
/** | ||
* Writes a set of values in csv format followed by a newline. | ||
* | ||
* Note: the precision of the output is determined by the settings | ||
* of the stream on construction. | ||
* | ||
* @param[in] state Values in a std::vector | ||
*/ | ||
void operator()(const std::vector<double>& state) { write_vector(state); } | ||
|
||
/** | ||
* Writes the comment_prefix to the stream followed by a newline. | ||
*/ | ||
void operator()() { | ||
std::stringstream streamer; | ||
streamer << comment_prefix_ << std::endl; | ||
*output_ << streamer.str(); | ||
} | ||
|
||
/** | ||
* Writes the comment_prefix then the message followed by a newline. | ||
* | ||
* @param[in] message A string | ||
*/ | ||
void operator()(const std::string& message) { | ||
std::stringstream streamer; | ||
streamer << comment_prefix_ << message << std::endl; | ||
*output_ << streamer.str(); | ||
} | ||
|
||
private: | ||
/** | ||
* Output stream | ||
*/ | ||
std::unique_ptr<Stream> output_; | ||
|
||
/** | ||
* Comment prefix to use when printing comments: strings and blank lines | ||
*/ | ||
std::string comment_prefix_; | ||
|
||
/** | ||
* Writes a set of values in csv format followed by a newline. | ||
* | ||
* Note: the precision of the output is determined by the settings | ||
* of the stream on construction. | ||
* | ||
* @param[in] v Values in a std::vector | ||
*/ | ||
template <class T> | ||
void write_vector(const std::vector<T>& v) { | ||
if (v.empty()) | ||
return; | ||
using const_iter = typename std::vector<T>::const_iterator; | ||
const_iter last = v.end(); | ||
--last; | ||
std::stringstream streamer; | ||
for (const_iter it = v.begin(); it != last; ++it) { | ||
streamer << *it << ","; | ||
} | ||
streamer << v.back() << std::endl; | ||
*output_ << streamer.str(); | ||
} | ||
}; | ||
|
||
} // namespace callbacks | ||
} // namespace stan | ||
|
||
#endif |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the code duplication here? Why not make the 1-core function defer to the multi-chain function by wrapping things into 1-sized vectors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion about this, but tbh I'd like to just make sure we are 100% cool with backwards compatibility by always deferring to the original API version if
chains=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na... let's just ensure we have good tests for that and instead make the old code call the new one with chains=1.
One issue you have when doing that is that you get references to inits and other things passed into the function. These then need to be wrapped into a size 1 vector of refs. Since you went with templates one can this use
std::ref
to make this work if I am not mistaken. I'd really like to avoid code duplication which is a source for errors in the future.