Skip to content

stan_sample defaults depend on state of SampleModel (as potentially modified by previous stan_sample calls) #82

Description

@nsiccha

I've found that behaviour confusing, as it's also not documented "anywhere" (where it's immediately obvious to the user).

Example code:

sm = Stan.SampleModel(...)
# This runs with engaged=true
Stan.stan_sample(sm; data, num_chains=1) |> display
Stan.stan_sample(sm; data, num_chains=1, engaged=false)
# This runs with engaged=false
Stan.stan_sample(sm; data, num_chains=1) |> display

Output (note engaged=true in the first line and engaged=false in the second line).

Process(`/tmp/jl_K1HcGM/nc_eight_schools_no_gq method=sample adapt engaged=true algorithm=hmc id=1 data file=/tmp/jl_K1HcGM/nc_eight_schools_no_gq_data_1.json output file=/tmp/jl_K1HcGM/nc_eight_schools_no_gq_chain_1.csv`, ProcessExited(0))
Process(`/tmp/jl_K1HcGM/nc_eight_schools_no_gq method=sample adapt engaged=false algorithm=hmc id=1 data file=/tmp/jl_K1HcGM/nc_eight_schools_no_gq_data_1.json output file=/tmp/jl_K1HcGM/nc_eight_schools_no_gq_chain_1.csv`, ProcessExited(0))

Activity

  1. self-assigned this
    on Dec 19, 2025
  2. penelopeysm commented on Apr 5, 2026

    @penelopeysm

    I ran into this issue with thinning as well -- I also find this behaviour really confusing. In most reasonable interfaces, keyword arguments that aren't specified have a fixed default. The current design departs from that convention in two ways:

    1. the default value is inherited from the positional argument
    2. the positional argument is a mutable object, causing the default value to change from call to call

    I would have expected an interface where:

    • SampleModel is a struct that contains (a path to) the compiled model, but not much other info
    • Calling stan_sample on that should not mutate the SampleModel, but instead return a new object, let's call it SampleResults
    • This object could wrap the SampleModel along with all the configuration values that are pertinent to this particular sampling call.
  3. bparbhu commented on Apr 19, 2026

    @bparbhu
    Contributor

    Understood, and thanks again for filing this. We're in the middle of updating to CmdStan 2.37. We'll take a look into this as soon as that is finished.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions