stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
138 stars 44 forks source link

[FR] get_param_names should be able to only return object names in parameters block #1240

Closed SteveBronder closed 1 year ago

SteveBronder commented 1 year ago

Current Behavior:

get_param_names() defined in the model returns all Program.outvars, but it should only return the stan programs parameters declared in the parameters block.

This is important for a bug I found recently in initialization where trying to set hard coded used [-2, 2] random sampling for initialization. At the line here if the user has any values in generated quantities, unless the user knew about this bug and created values for the variables declared in generated quantities then that check fails and it tries over and over again with the user specified values.

To fix this I think we need a separate Program section holding the names of the parameters

Model Code

All models

WardBrian commented 1 year ago

This is the intended behavior according to the doc string in model_base:

  /**
   * Set the specified argument to sequence of parameters, transformed
   * parameters, and generated quantities in the order in which they
   * were declared.

so I think changing this would be a breaking change. We wouldn’t need a new part in Program though, since we store the block as part of the outvars

Would adding bools to list the transformed params and GQs work? I believe if we defaulted them to True it would be backwards compatible, right? I know @roualdes recently wanted this ability

WardBrian commented 1 year ago

I was able to confirm that changing the signature in model base and changing the generated signature in stanc did not require any changes to the call sites, so I think we can do that if we want to

roualdes commented 1 year ago

Thanks, y'all. I do think this will help BridgeStan. Cheers.