What is the intended use for `Turing.returned(model)`?

There are no examples in the documentation, but based on its description,

Return a model wrapper indicating that it is a model over its return-values.

I assumed that this would allow me to do something like

chain = sample(returned(mymodel), ...)

or to use it as a submodel, but having it so that the parameters that are shown by Turing with describe(chain) would be the returned values (potentially given a nicer user-facing output for models where parameters of interest are transformations of what actually gets sampled).

I am familiar with the discussion on how the generality of return statements would make it so that this kind of operation cannot be expected to work in general, but this still leaves me wondering how to interpret the explanation given by the documentation and the intended use of such a function.

Looks like for now that method is used by to_submodel which you use inside models to make submodels, marking their returned values sampleable with ~. To put intermediates/transformations into the chain, you can use walrus := instead of assignment =.

1 Like

I see, thank you!

1 Like

Just wanted to add, this method was only really for internal use but I have a PR getting rid of it (because, IMO, it didn’t accomplish much).

1 Like

Thanks for the additional context! It did feel like it was just an internal thing when looking through the codebase but I guess the fact that it was documented threw me off a bit. :slight_smile:

1 Like