Get_inits not working with vb output

get_inits is not working correctly for the output of vb on at least one of the example models. A simple script that reproduces the problem is below. Note that the output of get_inits has the wrong dimension for sigma, and cannot be passed to unconstrain_pars, whereas the same commands work for ordinary sampling.

library(rstan)
options(mc.cores=4)

rstan_options(auto_write=TRUE)

# In example-models/ARM/Ch.17 on your local computer
setwd("/home/rgiordan/Documents/git_repos/example-models/ARM/Ch.17")
model <- stan_model("17.4_multilevel_logistic.stan")

# Load the data and hyperparameters.
stan_data <- new.env()
source("17.4_multilevel_logistic.data.R", local=stan_data)
stan_data <- as.list(stan_data)

num_samples <- 1000
chains <- 1
sampling_result <- sampling(model, data=stan_data, chains=chains, iter=num_samples)
advi_result <- vb(model, data=stan_data, iter=num_samples)

draw_list <- get_inits(sampling_result, iter=1)[[1]]
length(draw_list$sigma) # should be 1, and is 1
unconstrain_pars(sampling_result, draw_list) # Works as expected

vb_draw_list <- get_inits(advi_result, iter=1)
length(vb_draw_list$sigma)  # should be 1, and is 93
unconstrain_pars(advi_result, vb_draw_list) # fails with the message:
# Error in object@.MISC$stan_fit_instance$unconstrain_pars(pars) : 
#  mismatch in number dimensions declared and found in context; processing stage=initialization; variable 
# name=sigma; dims declared=(); dims found=(93)

Operating System: Ubuntu 16.04
Interface Version: 2.17.3
Output of writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))):
This file doesn’t exist.

cannot open file ‘/home/rgiordan/.R/Makevars’: No such file or directory

Output of devtools::session_info("rstan”):
Session info ------------------------------------------------------------------
setting value
version R version 3.4.4 (2018-03-15)
system x86_64, linux-gnu
ui X11
language en_US
collate en_US.UTF-8
tz America/Los_Angeles
date 2018-04-10

Packages ----------------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.4.1)
BH 1.66.0-1 2018-02-13 cran (@1.66.0-)
cli 1.0.0 2017-11-05 CRAN (R 3.4.3)
colorspace 1.3-2 2016-12-14 CRAN (R 3.4.1)
crayon 1.3.4 2017-09-16 CRAN (R 3.4.2)
dichromat 2.0-0 2013-01-24 CRAN (R 3.4.1)
digest 0.6.12 2017-01-27 CRAN (R 3.4.2)
ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.1)
graphics * 3.4.4 2018-03-16 local
grDevices * 3.4.4 2018-03-16 local
grid 3.4.4 2018-03-16 local
gridExtra 2.3 2017-09-09 CRAN (R 3.4.1)
gtable 0.2.0 2016-02-26 CRAN (R 3.4.1)
inline 0.3.14 2015-04-13 CRAN (R 3.4.1)
labeling 0.3 2014-08-23 CRAN (R 3.4.1)
lattice 0.20-35 2017-03-25 CRAN (R 3.4.1)
lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.1)
magrittr 1.5 2014-11-22 CRAN (R 3.4.1)
MASS 7.3-47 2017-04-21 CRAN (R 3.4.1)
Matrix 1.2-11 2017-08-16 CRAN (R 3.4.1)
methods * 3.4.4 2018-03-16 local
munsell 0.4.3 2016-02-13 CRAN (R 3.4.1)
pillar 1.0.1 2017-11-27 CRAN (R 3.4.3)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.1)
R6 2.2.2 2017-06-17 CRAN (R 3.4.1)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.4.1)
Rcpp 0.12.15 2018-01-20 cran (@0.12.15)
RcppEigen 0.3.3.4.0 2018-02-07 cran (@0.3.3.4)
reshape2 1.4.3 2017-12-11 cran (@1.4.3)
rlang 0.1.6 2017-12-21 CRAN (R 3.4.3)
rstan * 2.17.3 2018-01-20 cran (@2.17.3)
scales 0.5.0 2017-08-24 CRAN (R 3.4.1)
StanHeaders * 2.17.2 2018-01-20 cran (@2.17.2)
stats * 3.4.4 2018-03-16 local
stats4 3.4.4 2018-03-16 local
stringi 1.1.5 2017-04-07 CRAN (R 3.4.1)
stringr 1.2.0 2017-02-18 CRAN (R 3.4.1)
tibble 1.4.1 2017-12-25 CRAN (R 3.4.3)
tools 3.4.4 2018-03-16 local
utf8 1.1.3 2018-01-03 CRAN (R 3.4.3)
utils * 3.4.4 2018-03-16 local
viridisLite 0.2.0 2017-03-24 CRAN (R 3.4.1)

Thanks for the report, Ryan. Would you mind posting this as an issue for Rstan? Those get tracked, whereas Discourse comments like this get lost in the shuffle.

I think this may be a known issue as there was always something wonky about the way ADVI got slotted into an existing interface (ADVI was pretty much an implementation hack all the way down as far as I can tell).

Will do!