Skip to content
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

Add ./model compile_info #887

Closed
rok-cesnovar opened this issue Jun 7, 2020 · 8 comments · Fixed by #1010
Closed

Add ./model compile_info #887

rok-cesnovar opened this issue Jun 7, 2020 · 8 comments · Fixed by #1010

Comments

@rok-cesnovar
Copy link
Member

rok-cesnovar commented Jun 7, 2020

Description:

We should add a "compile_info" argument to the model executable that would output information on how to executable was compiled:

Example:

./examples/bernoulli/bernoulli compile-info

outputs:

MODEL_NAME = bernoulli_model
STAN_VERSION = 2.23.0
STANCFLAGS = --allow_undefined
STANC_VERSION = stanc3 124f5639
STAN_THREADS = true

For now, I envisioned adding the stan version, stanc flags, stanc version, and whether the THREADS/MPI/OPENCL flags were used.

Other options I am not sure we want to use but could if there is interest:

  • c++ compiler and version
  • the time of compilation
  • hash of the model code
  • model code (but that is probably overkill)

Current Version:

v2.23.0

@rok-cesnovar
Copy link
Member Author

rok-cesnovar commented Jun 7, 2020

I have this implemented in stan/cmdstan/stanc3 but will wait for feedback before proceeding.

The model would get a constructor with no arguments and a compile info function.

  bernoulli_model() : model_base_crtp(0)  {}  

  std::vector<std::string> model_compile_info() const {
    std::vector<std::string> info;
    info.push_back("MODEL_NAME=bernoulli_model");
    info.push_back("STANCFLAGS=--allow_undefined");
    info.push_back("STANC_VERSION=stanc3 124f5639");
    return info;
  } 

and

stan::model::model_base& new_model() {
  stan_model* m = new stan_model();
  return *m;
}

ant the write_compile_info function in cmdstan would be:

void write_compile_info(stan::callbacks::writer &writer,
                 std::vector<std::string>& compile_info) {
    writer("STAN_VERSION = " + stan::MAJOR_VERSION + "." + stan::MINOR_VERSION + "." + stan::PATCH_VERSION);
    for (int i = 0; i < compile_info.size(); i++) {
       writer(compile_info[i]);
    }
#ifdef STAN_THREADS
    writer("STAN_THREADS=true");
#endif
#ifdef STAN_MPI
    writer("STAN_MPI=true");
#endif
#ifdef STAN_OPENCL
    writer("STAN_OPENCL=true");
    std::stringstream msg;
    msg << "OPENCL_PLATFORM_ID=" << OPENCL_PLATFORM_ID << "\n"
        << "OPENCL_DEVICE_ID=" << OPENCL_DEVICE_ID;
    writer(msg.str());
#endif
}

EDIT: Refactored so that flags are caught in cmdstan not the model.

@rok-cesnovar
Copy link
Member Author

Primary use case is cmdstanX wrappers but this is useful for cmdstan also. I found myself not knowing if I compiled a model with STAN_THREADS/STAN_OPENCL a lot :) .

@wds15
Copy link
Contributor

wds15 commented Jun 7, 2020

I would find it better to have a config.hpp or the like in stan-math. This file would be like our make/local, but more standard like as other packages are doing it.

What is the use case for exposing this via cmdstan?

The name compile_info is possibly misleading as this would include -OX things as well. It should be better to call it something which says „enabled features“ or the like.

@rok-cesnovar
Copy link
Member Author

rok-cesnovar commented Jun 7, 2020

I would find it better to have a config.hpp or the like in stan-math. This file would be like our make/local, but more standard like as other packages are doing it.

That would work for THREADS/MPI/OPENCL but that does not give you version numbers/stanc3 version/stanc flags. Maybe there is a misunderstanding here. This is meant for printing information on how the model was compiled. Not compiling or setting compile flags.

What is the use case for exposing this via cmdstan?

Not sure I understand. This is a cmdstan(X) feature, so it should be exposed in cmdstan. It makes on sense in math as we have no concept of a model there.

The name compile_info is possibly misleading as this would include -OX things as well. It should be better to call it something which says „enabled features“ or the like.

The name is a placeholder for now. There are better names for sure.

@betanalpha
Copy link
Contributor

betanalpha commented Jun 8, 2020 via email

@rok-cesnovar
Copy link
Member Author

That is a good call. The threads/mpi/opencl are represented in a way in the CSV, though that could be made more explicit. For example, num threads is listed but we should also state that threads_enabled = 1.

The version of the compiler and the flags used to compile is however not there. And given that compile-time optimizations in stanc will be available in the next release we really must add this to the CSV to make this more reproducible.

@rok-cesnovar
Copy link
Member Author

One other potentially nice thing would be to also output the input data names and their types in a machine friendly way.

DATA
int N
int[] y
vector z
ENDDATA

The use case is nicer messages on what data is missing in both cmdstan and cmdstanX.

@mitzimorris
Copy link
Member

While we still have the monolithic CSV output it would be great to add this info there as well to make everything as reproducible as possible.

putting this into the monolithic CSV output header makes sense - we need to document the exact format or order of this info w/r/t the command line config info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants