Classes | Functions
stan::test::performance Namespace Reference

Classes

struct  run_command_output
 

Functions

std::ostream & operator<< (std::ostream &os, const run_command_output &out)
 
run_command_output run_command (std::string command)
 
std::vector< double > get_last_iteration_from_file (const char *filename)
 
template<typename T >
std::string quote (const T &val)
 
std::string get_git_hash ()
 
std::string get_git_date ()
 
std::string get_date ()
 
template<class Model >
int command (int num_warmup, int num_samples, const std::string data_file, const std::string output_file, unsigned int random_seed)
 

Function Documentation

template<class Model >
int stan::test::performance::command ( int  num_warmup,
int  num_samples,
const std::string  data_file,
const std::string  output_file,
unsigned int  random_seed 
)

Definition at line 208 of file utility.hpp.

References om::cerr, om::cout, delta, stan::services::sample::hmc_nuts_diag_e_adapt(), in, confusionMatrixTree::out, refresh(), getGoodRuns4SAM::t0, and allInOneTrainingPlots::window.

212  {
213  // Data input
214  std::fstream data_stream(data_file.c_str(),
216  stan::io::dump data_var_context(data_stream);
217  data_stream.close();
218 
219  // Sample output
220  callbacks::writer init_writer;
221  callbacks::stream_logger logger(std::cout, std::cout, std::cout, std::cerr, std::cerr);
222  std::fstream output_stream(output_file.c_str(), std::fstream::out);
223  callbacks::stream_writer sample_writer(output_stream, "# ");
224  callbacks::writer diagnostic_writer;
225  callbacks::interrupt interrupt;
226 
227  Model model(data_var_context, &std::cout);
228  stan::io::empty_var_context init_context;
229  double init_radius = 0;
230  int id = 0;
231  int num_thin = 1;
232  bool save_warmup = false;
233  int refresh = num_samples;
234  double stepsize = 1.0;
235  double stepsize_jitter = 0.0;
236  int max_depth = 10;
237  double delta = 0.8;
238  double gamma = 0.05;
239  double kappa = 0.75;
240  double t0 = 10;
241  int init_buffer = 75;
242  int term_buffer = 50;
243  int window = 25;
245  init_context,
246  random_seed,
247  id,
248  init_radius,
249  num_warmup,
250  num_samples,
251  num_thin,
252  save_warmup,
253  refresh,
254  stepsize,
255  stepsize_jitter,
256  max_depth,
257  delta,
258  gamma,
259  kappa,
260  t0,
261  init_buffer,
262  term_buffer,
263  window,
264  interrupt,
265  logger,
266  init_writer,
267  sample_writer,
268  diagnostic_writer);
269  }
double delta
Definition: runWimpSim.h:98
OStream cerr
Definition: OStream.cxx:7
rosenbrock_model_namespace::rosenbrock_model Model
output_file
save output
OStream cout
Definition: OStream.cxx:6
ifstream in
Definition: comparison.C:7
int hmc_nuts_diag_e_adapt(Model &model, stan::io::var_context &init, stan::io::var_context &init_inv_metric, unsigned int random_seed, unsigned int chain, double init_radius, int num_warmup, int num_samples, int num_thin, bool save_warmup, int refresh, double stepsize, double stepsize_jitter, int max_depth, double delta, double gamma, double kappa, double t0, unsigned int init_buffer, unsigned int term_buffer, unsigned int window, callbacks::interrupt &interrupt, callbacks::logger &logger, callbacks::writer &init_writer, callbacks::writer &sample_writer, callbacks::writer &diagnostic_writer)
const XML_Char XML_Content * model
Definition: expat.h:151
void refresh()
Definition: show_event.C:21
std::string stan::test::performance::get_date ( )

Definition at line 192 of file utility.hpp.

References stan::test::performance::run_command_output::time, and trim().

Referenced by TEST_F().

192  {
193  std::time_t curr_date;
194  time(&curr_date);
195 
196  std::stringstream date_ss;
197  date_ss << std::ctime(&curr_date);
198 
200  date = date_ss.str();
201 
202  boost::trim(date);
203  return date;
204  }
::xsd::cxx::tree::date< char, simple_type > date
Definition: Database.h:186
string trim(string in)
Definition: rootgINukeVal.C:65
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string stan::test::performance::get_git_date ( )

Definition at line 172 of file utility.hpp.

References stan::test::performance::run_command_output::body, stan::test::performance::run_command_output::hasError, run_command(), submit_nova_art::timestamp, and trim().

Referenced by TEST_F().

172  {
173  run_command_output git_date_command
174  = run_command("git log --format=%ct -1");
175  if (git_date_command.hasError)
176  return "NA";
177  boost::trim(git_date_command.body);
178 
179  long timestamp = atol(git_date_command.body.c_str());
180  std::time_t git_date(timestamp);
181 
182  std::stringstream date_ss;
183  date_ss << std::ctime(&git_date);
184 
186  date = date_ss.str();
187 
188  boost::trim(date);
189  return date;
190  }
::xsd::cxx::tree::date< char, simple_type > date
Definition: Database.h:186
string trim(string in)
Definition: rootgINukeVal.C:65
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
run_command_output run_command(std::string command)
Definition: utility.hpp:90
std::string stan::test::performance::get_git_hash ( )

Definition at line 164 of file utility.hpp.

References stan::test::performance::run_command_output::body, stan::test::performance::run_command_output::hasError, run_command(), and trim().

Referenced by TEST_F().

164  {
165  run_command_output git_hash = run_command("git rev-parse HEAD");
166  if (git_hash.hasError)
167  return "NA";
168  boost::trim(git_hash.body);
169  return git_hash.body;
170  }
string trim(string in)
Definition: rootgINukeVal.C:65
run_command_output run_command(std::string command)
Definition: utility.hpp:90
std::vector<double> stan::test::performance::get_last_iteration_from_file ( const char *  filename)

Definition at line 128 of file utility.hpp.

References make_syst_table_plots::line, getGoodRuns4SAM::n, and train_latest_snapshot::values.

Referenced by TEST_F().

128  {
129  std::vector<double> draw;
130  const char comment = '#';
131 
132  std::ifstream file_stream(filename);
134  std::string last_values;
135  while (std::getline(file_stream, line)) {
136  if (line.length() > 0 && line[0] != comment)
137  last_values = line;
138  }
139 
140  std::stringstream values_stream(last_values);
141  std::vector<std::string> values;
143  while (std::getline(values_stream, value, ','))
144  values.push_back(value);
145 
146  draw.resize(values.size());
147  for (size_t n = 0; n < draw.size(); ++n) {
148  draw[n] = atof(values[n].c_str());
149  }
150 
151  return draw;
152  }
string filename
Definition: shutoffs.py:106
const XML_Char int const XML_Char * value
Definition: expat.h:331
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::ostream& stan::test::performance::operator<< ( std::ostream &  os,
const run_command_output out 
)

Definition at line 71 of file utility.hpp.

References stan::test::performance::run_command_output::body, stan::test::performance::run_command_output::command, allTimeWatchdog::endl, stan::test::performance::run_command_output::err_code, stan::test::performance::run_command_output::hasError, stan::test::performance::run_command_output::header, stan::test::performance::run_command_output::output, and stan::test::performance::run_command_output::time.

71  {
72  os << "run_command output:" << "\n"
73  << "- command: " << out.command << "\n"
74  << "- output: " << out.output << "\n"
75  << "- time (ms): " << out.time << "\n"
76  << "- err_code: " << out.err_code << "\n"
77  << "- hasError: " << (out.hasError ? "true" : "false") << "\n"
78  << "- header: " << out.header << "\n"
79  << "- body: " << out.body << std::endl;
80  return os;
81  }
template<typename T >
std::string stan::test::performance::quote ( const T val)

Definition at line 156 of file utility.hpp.

Referenced by TEST_F().

156  {
157  std::stringstream quoted_val;
158  quoted_val << "\""
159  << val
160  << "\"";
161  return quoted_val.str();
162  }
run_command_output stan::test::performance::run_command ( std::string  command)

Runs the command provided and returns the system output as a string.

Parameters
commandA command that can be run from the shell
Returns
the system output of the command

Definition at line 90 of file utility.hpp.

References stan::test::performance::run_command_output::command, confusionMatrixTree::count, stan::test::performance::run_command_output::err_code, in, stan::test::performance::run_command_output::output, and stan::test::performance::run_command_output::run_command_output().

Referenced by get_git_date(), and get_git_hash().

90  {
91  using boost::posix_time::ptime;
92  using boost::posix_time::microsec_clock;
93 
94  FILE *in;
95  std::string new_command = command + " 2>&1";
96  // captures both cout amd err
97 
98  in = popen(command.c_str(), "r");
99 
100  if(!in) {
101  std::string err_msg;
102  err_msg = "Fatal error with popen; could not execute: \"";
103  err_msg+= command;
104  err_msg+= "\"";
105  throw std::runtime_error(err_msg.c_str());
106  }
107 
109  char buf[1024];
110  size_t count;
111  ptime time_start(microsec_clock::universal_time()); // start timer
112  while ((count = fread(&buf, 1, 1024, in)) > 0)
113  output += std::string(&buf[0], &buf[count]);
114  ptime time_end(microsec_clock::universal_time()); // end timer
115 
116  // bits 15-8 is err code, bit 7 if core dump, bits 6-0 is signal number
117  int err_code = pclose(in);
118  // on Windows, err code is the return code.
119  if (err_code != 0 && (err_code >> 8) > 0)
120  err_code >>= 8;
121 
122  return run_command_output(command, output,
123  (time_end - time_start).total_milliseconds(),
124  err_code);
125  }
int command(int num_warmup, int num_samples, const std::string data_file, const std::string output_file, unsigned int random_seed)
Definition: utility.hpp:208
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
ifstream in
Definition: comparison.C:7