Skip to content

Commit

Permalink
Add debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Dec 24, 2023
1 parent 5b73a90 commit c54de5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Built StanEstimators Binaries

on:
push:
branches: main
branches: debug

jobs:
build-rpackage-binaries:
Expand Down
16 changes: 16 additions & 0 deletions inst/include/cmdstan/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ stan::math::mpi_cluster &get_mpi_cluster() {
#endif

int command(int argc, const char *argv[]) {
Rcpp::Rcout << "a" << std::endl;
stan::callbacks::stream_writer info(Rcpp::Rcout);
stan::callbacks::stream_writer err(Rcpp::Rcerr);
stan::callbacks::stream_logger logger(Rcpp::Rcout, Rcpp::Rcout, Rcpp::Rcout,
Expand Down Expand Up @@ -153,15 +154,18 @@ int command(int argc, const char *argv[]) {
throw std::invalid_argument(thread_msg.str());
}
}
Rcpp::Rcout << "b" << std::endl;
stan::math::init_threadpool_tbb(num_threads);

unsigned int num_chains = get_num_chains(parser);
check_file_config(parser);
Rcpp::Rcout << "c" << std::endl;

parser.print(info);
write_parallel_info(info);
write_opencl_device(info);
info();
Rcpp::Rcout << "d" << std::endl;

// General config for all methods
unsigned int id = get_arg_val<int_argument>(parser, "id");
Expand All @@ -171,17 +175,21 @@ int command(int argc, const char *argv[]) {
//////////////////////////////////////////////////
// Initialize Model //
//////////////////////////////////////////////////
Rcpp::Rcout << "e" << std::endl;
arg_seed *random_arg
= dynamic_cast<arg_seed *>(parser.arg("random")->arg("seed"));
unsigned int random_seed = random_arg->random_value();

std::string filename = get_arg_val<string_argument>(parser, "data", "file");

Rcpp::Rcout << "f" << std::endl;
std::shared_ptr<stan::io::var_context> var_context
= get_var_context(filename);

Rcpp::Rcout << "g" << std::endl;
stan::model::model_base &model
= new_model(*var_context, random_seed, &Rcpp::Rcout);
Rcpp::Rcout << "h" << std::endl;

// Setup callbacks
stan::callbacks::interrupt interrupt;
Expand All @@ -196,9 +204,11 @@ int command(int argc, const char *argv[]) {
std::vector<stan::callbacks::json_writer<std::ofstream>>
diagnostic_json_writers;

Rcpp::Rcout << "i" << std::endl;
init_callbacks(parser, sample_writers, diagnostic_csv_writers,
diagnostic_json_writers);

Rcpp::Rcout << "j" << std::endl;
// Setup initial parameter values - arg "init"
// arg is either filename or init radius value
std::string init = get_arg_val<string_argument>(parser, "init");
Expand All @@ -209,10 +219,13 @@ int command(int argc, const char *argv[]) {
} catch (const std::logic_error &e) {
}

Rcpp::Rcout << "k" << std::endl;
std::vector<std::shared_ptr<stan::io::var_context>> init_contexts
= get_vec_var_context(init, num_chains, id);
Rcpp::Rcout << "l" << std::endl;
std::vector<std::string> model_compile_info = model.model_compile_info();

Rcpp::Rcout << "m" << std::endl;
for (int i = 0; i < num_chains; ++i) {
write_stan(sample_writers[i]);
write_model(sample_writers[i], model.model_name());
Expand All @@ -225,6 +238,7 @@ int command(int argc, const char *argv[]) {
write_model(diagnostic_csv_writers[i], model.model_name());
parser.print(diagnostic_csv_writers[i]);
}
Rcpp::Rcout << "n" << std::endl;

//////////////////////////////////////////////////
// Invoke Services //
Expand Down Expand Up @@ -460,12 +474,14 @@ int command(int argc, const char *argv[]) {
tol_rel_grad, tol_param, num_iterations, save_iterations,
refresh, interrupt, logger, init_writers[0], sample_writers[0]);
} else {
Rcpp::Rcout << "o" << std::endl;
return_code
= stan::services::optimize::lbfgs<stan::model::model_base, false>(
model, *(init_contexts[0]), random_seed, id, init_radius,
history_size, init_alpha, tol_obj, tol_rel_obj, tol_grad,
tol_rel_grad, tol_param, num_iterations, save_iterations,
refresh, interrupt, logger, init_writers[0], sample_writers[0]);
Rcpp::Rcout << "p" << std::endl;
}
}
// ---- optimize end ---- //
Expand Down

0 comments on commit c54de5c

Please sign in to comment.