Tuple in cmdstanpy

I’m trying to use tuples in a model, but I’m having difficulty initializing a tuple. I’m using cmdstanpy. Here’s a minimal example. My stan model (from documentation):

generated quantities {
  tuple(int, real) ab;
  ab.1 = 123;
  ab.2 = 12.9;
}

My code for compiling the program:

 model = stan.CmdStanModel(stan_file='program.stan')
 fit = model.sample(iter_sampling=1, show_console=True)

I get the error:

ValueError: Failed to get source info for Stan model 'program.stan'. Console:
Syntax error in 'program.stan', line 2, column 8 to column 11, parsing error:
   -------------------------------------------------
     1:  generated quantities {
     2:    tuple(int, real) ab;
                 ^
     3:    ab.1 = 123;
     4:    ab.2 = 12.9;
   -------------------------------------------------

Ill-formed function application. Expect comma-separated list of expressions followed by ")" after "(".

Thanks in advance for any help!

@mitzimorris @WardBrian

What version of cmdstan are you using?

cmdstanpy 1.2.0

Can you paste the output of cmdstanpy.show_versions()?

1.2.0
INSTALLED VERSIONS

python: 3.11.5 (v3.11.5:cce6ba91b3, Aug 24 2023, 10:50:31) [Clang 13.0.0 (clang-1300.0.29.30)]
python-bits: 64
OS: Darwin
OS-release: 22.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: (‘en_US’, ‘UTF-8’)
cmdstan_folder: /Users/ramin/.cmdstan/cmdstan-2.31.0
cmdstan: (2, 31)
cmdstanpy: 1.2.0
pandas: 1.5.3
xarray: 2023.11.0
tqdm: 4.66.1
numpy: 1.25.2

Tuples are only supported if you’re using CmdStan 2.33 (currently the latest release). If you update CmdStan you should be good to go

1 Like