Cmdstanr: Allow passing flags to stanc compiler

Created on 9 Nov 2019  路  7Comments  路  Source: stan-dev/cmdstanr

In $compile() it would be nice if there were flags we could pass to stanc. In the new compiler we have a --use-opencl to move the data over to the GPU once instead of on each function call (which you can imagine is a good bit faster)

Maybe it would be good to make each setup portion into a list of options like stanc_flags, cxx_flags, cmdstan_flags. Or something like that.

feature

All 7 comments

You can already do that in a way. Its maybe not the nicest interface for stanc flags, but does work. Turn off quiet so you see the compile calls.

cmdstan_model(stan_file = my_stan_program,
              compiler_flags = c("STANCFLAGS = --allow_undefined"),
              quiet = FALSE)

We could redo this as stanc3 is bound to have many more useful flags:

cmdstan_model(stan_file = my_stan_program,
              stanc_flags = c("--allow_undefined", "--someotheroption"),
              quiet = FALSE)

or

cmdstan_model(stan_file = my_stan_program,
              stanc_flags = c("allow_undefined", "someotheroption"),
              quiet = FALSE)

We could redo this as stanc3 is bound to have many more useful flags:

Sounds good! I think I slightly prefer the second option ("allow_undefined") but maybe we allow both so it doesn鈥檛 error with "--allow_undefined"?

More complicated, but what if we did

cmdstan_model(stan_file = my_stan_program,
              stanc_flags = list(allow_undefined = TRUE, use_opencl = TRUE),
              quiet = FALSE)

Then for list items that are true we do --{name_list_item} and for list_items with a non-null lhs we input their arguments as --flag_name={RHS}

I agree that this is a better way of handling it.
My thinking is that we should only allow specifying the flags that are supported in the latest release. And for other have a experimental argument (or unsupported). Something like:

cmdstan_model(stan_file = my_stan_program,
              stanc_flags = list(allow_undefined = TRUE, use_opencl = TRUE),
              experimental_stanc_flags = c("somethingnew")
              quiet = FALSE)

Though that seems a bit weird from an API standpoint. Thoughts?

idk if we need the experimental_flag option. We can just do something like

my_flags = c("use-opencl" = TRUE, includes = c("path/to/whatever"))

comp_flags = c()
for (i in seq_len(length(my_flags))) {
  if (isTRUE(as.logical(my_flags[[i]]))) {
    comp_flags = c(comp_flags, paste0("--",names(my_flags)[i]))
  } else {
    comp_flags = c(comp_flags, paste0("--", names(my_flags)[i], "=", "'", my_flags[[i]], "'"))
  }
}
paste0(comp_flags, collapse = " ")
# [1] "--use-opencl --includes='path/to/whatever'"

And that will let people pass experimental flags as well

That would work. Will try to handle this tmrw. Will tag you.

Closing this as this issue is superseeded now by #121 that will also tackle make options.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbbales2 picture bbbales2  路  9Comments

bbbales2 picture bbbales2  路  9Comments

jstagge picture jstagge  路  5Comments

nerutenbeck picture nerutenbeck  路  4Comments

yizhang-yiz picture yizhang-yiz  路  4Comments