Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Describe what you expect the output to be. Knowing the correct behavior is also
Provide any additional information here.

#### Current Version:
v2.28.0
v2.28.1
10 changes: 7 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pipeline {
steps {
sh """
git clone --recursive https://github.com/stan-dev/performance-tests-cmdstan
git clone https://github.com/stan-dev/stanc3/ performance-tests-cmdstan/stanc3
"""
script {
if (params.cmdstan_pr != 'downstream_tests') {
Expand Down Expand Up @@ -303,7 +304,8 @@ pipeline {
echo 'CXX=${env.CXX}' >> make/local
make -j${env.PARALLEL} build
cd ..
./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 cmdstan/stan/src/test/test-models/good
./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good
./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 example-models
"""
sh """
cd performance-tests-cmdstan/cmdstan/stan
Expand Down Expand Up @@ -337,7 +339,8 @@ pipeline {
echo 'CXX=${env.CXX}' >> make/local
make -j${env.PARALLEL} build
cd ..
./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 cmdstan/stan/src/test/test-models/good
./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good
./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 example-models
"""
sh """
cd performance-tests-cmdstan/cmdstan/stan
Expand Down Expand Up @@ -373,7 +376,8 @@ pipeline {
cd performance-tests-cmdstan/cmdstan
mingw32-make -j${env.PARALLEL} build
cd ..
python ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 cmdstan/stan/src/test/test-models/good
python ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 stanc3/test/integration/good
python ./runPerformanceTests.py -j${env.PARALLEL} ${integration_tests_flags()}--runs=0 example-models
"""
}
bat """
Expand Down
5 changes: 5 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Note: these are the release notes for the stan-dev/stan repository.
Further changes may arise at the interface level (stan-dev/{rstan,
pystan, cmdstan}) and math library level (stan-dev/math).

v2.28.1 (21 October 2021)
======================================================================

- Updated to Stan Math 4.2.1

v2.28.0 (5 October 2021)
======================================================================

Expand Down
2 changes: 1 addition & 1 deletion src/doxygen/doxygen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Stan"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.28.0
PROJECT_NUMBER = 2.28.1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
42 changes: 30 additions & 12 deletions src/stan/callbacks/stream_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class stream_writer : public writer {
* each comment line. Default is "".
*/
explicit stream_writer(std::ostream& output,
const std::string& comment_prefix = "")
: output_(output), comment_prefix_(comment_prefix) {}
const std::string& comment_prefix = "",
bool is_empty = false)
: output_(output), comment_prefix_(comment_prefix), empty_(is_empty) {}

/**
* Virtual destructor
Expand Down Expand Up @@ -57,17 +58,28 @@ class stream_writer : public writer {
/**
* Writes the comment_prefix to the stream followed by a newline.
*/
void operator()() { output_ << comment_prefix_ << std::endl; }
void operator()() {
if (!empty_) {
output_ << comment_prefix_ << std::endl;
}
}

/**
* Writes the comment_prefix then the message followed by a newline.
*
* @param[in] message A string
*/
void operator()(const std::string& message) {
output_ << comment_prefix_ << message << std::endl;
if (!empty_) {
output_ << comment_prefix_ << message << std::endl;
}
}

/**
* Check if the writer is writing to an empty stream
*/
inline bool is_empty() const noexcept final { return empty_; }

private:
/**
* Output stream
Expand All @@ -79,6 +91,10 @@ class stream_writer : public writer {
*/
std::string comment_prefix_;

/**
* Used as check for whether output stream needs to be written to.
*/
bool empty_{false};
/**
* Writes a set of values in csv format followed by a newline.
*
Expand All @@ -89,16 +105,18 @@ class stream_writer : public writer {
*/
template <class T>
void write_vector(const std::vector<T>& v) {
if (v.empty())
return;
if (!empty_) {
if (v.empty())
return;

typename std::vector<T>::const_iterator last = v.end();
--last;
typename std::vector<T>::const_iterator last = v.end();
--last;

for (typename std::vector<T>::const_iterator it = v.begin(); it != last;
++it)
output_ << *it << ",";
output_ << v.back() << std::endl;
for (typename std::vector<T>::const_iterator it = v.begin(); it != last;
++it)
output_ << *it << ",";
output_ << v.back() << std::endl;
}
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/stan/callbacks/tee_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class tee_writer final : public writer {
writer2_(message);
}

/**
* Check if both writers are writing to an empty stream
*/
inline bool is_empty() const noexcept {
return writer1_.is_empty() && writer2_.is_empty();
}

private:
/**
* The first writer
Expand Down
65 changes: 42 additions & 23 deletions src/stan/callbacks/unique_stream_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ class unique_stream_writer final : public writer {
* Default is "".
*/
explicit unique_stream_writer(std::unique_ptr<Stream>&& output,
const std::string& comment_prefix = "")
: output_(std::move(output)), comment_prefix_(comment_prefix) {}
const std::string& comment_prefix = "",
bool is_empty = false)
: output_(std::move(output)),
comment_prefix_(comment_prefix),
empty_(is_empty) {}

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_)) {}
comment_prefix_(std::move(other.comment_prefix_)),
empty_(other.empty_) {}
/**
* Virtual destructor
*/
Expand All @@ -54,7 +58,7 @@ class unique_stream_writer final : public writer {
/**
* Get the underlying stream
*/
auto& get_stream() { return *output_; }
inline auto& get_stream() noexcept { return *output_; }

/**
* Writes a set of values in csv format followed by a newline.
Expand All @@ -70,10 +74,12 @@ class unique_stream_writer final : public writer {
* Writes the comment_prefix to the stream followed by a newline.
*/
void operator()() {
std::stringstream streamer;
streamer.precision(output_.get()->precision());
streamer << comment_prefix_ << std::endl;
*output_ << streamer.str();
if (!empty_) {
std::stringstream streamer;
streamer.precision(output_.get()->precision());
streamer << comment_prefix_ << std::endl;
*output_ << streamer.str();
}
}

/**
Expand All @@ -82,12 +88,19 @@ class unique_stream_writer final : public writer {
* @param[in] message A string
*/
void operator()(const std::string& message) {
std::stringstream streamer;
streamer.precision(output_.get()->precision());
streamer << comment_prefix_ << message << std::endl;
*output_ << streamer.str();
if (!empty_) {
std::stringstream streamer;
streamer.precision(output_.get()->precision());
streamer << comment_prefix_ << message << std::endl;
*output_ << streamer.str();
}
}

/**
* Check if the writer is writing to an empty stream
*/
inline bool is_empty() const noexcept { return empty_; }

private:
/**
* Output stream
Expand All @@ -99,6 +112,10 @@ class unique_stream_writer final : public writer {
*/
std::string comment_prefix_;

/**
* Used as check for whether output stream needs to be written to.
*/
bool empty_{false};
/**
* Writes a set of values in csv format followed by a newline.
*
Expand All @@ -109,18 +126,20 @@ class unique_stream_writer final : public writer {
*/
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;
streamer.precision(output_.get()->precision());
for (const_iter it = v.begin(); it != last; ++it) {
streamer << *it << ",";
if (!empty_) {
if (v.empty())
return;
using const_iter = typename std::vector<T>::const_iterator;
const_iter last = v.end();
--last;
std::stringstream streamer;
streamer.precision(output_.get()->precision());
for (const_iter it = v.begin(); it != last; ++it) {
streamer << *it << ",";
}
streamer << v.back() << std::endl;
*output_ << streamer.str();
}
streamer << v.back() << std::endl;
*output_ << streamer.str();
}
};

Expand Down
5 changes: 5 additions & 0 deletions src/stan/callbacks/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class writer {
* @param[in] message A string
*/
virtual void operator()(const std::string& message) {}

/**
* Check if the writer is writing to an empty stream
*/
virtual bool is_empty() const noexcept { return true; }
};

} // namespace callbacks
Expand Down
32 changes: 19 additions & 13 deletions src/stan/services/util/mcmc_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,19 @@ class mcmc_writer {
template <class Model>
void write_diagnostic_names(stan::mcmc::sample sample,
stan::mcmc::base_mcmc& sampler, Model& model) {
std::vector<std::string> names;
if (!diagnostic_writer_.is_empty()) {
std::vector<std::string> names;

sample.get_sample_param_names(names);
sampler.get_sampler_param_names(names);
sample.get_sample_param_names(names);
sampler.get_sampler_param_names(names);

std::vector<std::string> model_names;
model.unconstrained_param_names(model_names, false, false);
std::vector<std::string> model_names;
model.unconstrained_param_names(model_names, false, false);

sampler.get_sampler_diagnostic_names(model_names, names);
sampler.get_sampler_diagnostic_names(model_names, names);

diagnostic_writer_(names);
diagnostic_writer_(names);
}
}

/**
Expand All @@ -170,13 +172,15 @@ class mcmc_writer {
*/
void write_diagnostic_params(stan::mcmc::sample& sample,
stan::mcmc::base_mcmc& sampler) {
std::vector<double> values;
if (!diagnostic_writer_.is_empty()) {
std::vector<double> values;

sample.get_sample_params(values);
sampler.get_sampler_params(values);
sampler.get_sampler_diagnostics(values);
sample.get_sample_params(values);
sampler.get_sampler_params(values);
sampler.get_sampler_diagnostics(values);

diagnostic_writer_(values);
diagnostic_writer_(values);
}
}

/**
Expand Down Expand Up @@ -247,7 +251,9 @@ class mcmc_writer {
*/
void write_timing(double warmDeltaT, double sampleDeltaT) {
write_timing(warmDeltaT, sampleDeltaT, sample_writer_);
write_timing(warmDeltaT, sampleDeltaT, diagnostic_writer_);
if (!diagnostic_writer_.is_empty()) {
write_timing(warmDeltaT, sampleDeltaT, diagnostic_writer_);
}
log_timing(warmDeltaT, sampleDeltaT);
}
};
Expand Down
19 changes: 11 additions & 8 deletions src/stan/variational/advi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,14 @@ class advi {
= std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
.count()
/ 1000.0;
std::vector<double> print_vector;
print_vector.clear();
print_vector.push_back(iter_counter);
print_vector.push_back(delta_t);
print_vector.push_back(elbo);
diagnostic_writer(print_vector);
if (!diagnostic_writer.is_empty()) {
std::vector<double> print_vector;
print_vector.clear();
print_vector.push_back(iter_counter);
print_vector.push_back(delta_t);
print_vector.push_back(elbo);
diagnostic_writer(print_vector);
}

if (delta_elbo_ave < tol_rel_obj) {
ss << " MEAN ELBO CONVERGED";
Expand Down Expand Up @@ -459,8 +461,9 @@ class advi {
double tol_rel_obj, int max_iterations, callbacks::logger& logger,
callbacks::writer& parameter_writer,
callbacks::writer& diagnostic_writer) const {
diagnostic_writer("iter,time_in_seconds,ELBO");

if (!diagnostic_writer.is_empty()) {
diagnostic_writer("iter,time_in_seconds,ELBO");
}
// Initialize variational approximation
Q variational = Q(cont_params_);

Expand Down
2 changes: 1 addition & 1 deletion src/stan/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define STAN_MAJOR 2
#define STAN_MINOR 28
#define STAN_PATCH 0
#define STAN_PATCH 1

namespace stan {

Expand Down
Loading