Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMC samplers no longer support usage of keyword arguments in models #2007

Open
torfjelde opened this issue Jun 12, 2023 · 2 comments
Open

SMC samplers no longer support usage of keyword arguments in models #2007

torfjelde opened this issue Jun 12, 2023 · 2 comments

Comments

@torfjelde
Copy link
Member

torfjelde commented Jun 12, 2023

After #2001 , sampling models with keyword argument using SMC samplers will no longer be supported.

This issue is a reminder + to keep track of the progress towards addressing this.

Related issues and PRs:

@joelem
Copy link

joelem commented Apr 30, 2024

Hi Turing team,

First, just wanted to thank you for such an awesome package, we are using it for one of our projects. Specifically, we were using an SMC sampler that sampled a function we created that takes in a matrix as an input.

something like:

{code here that creates a matrix}
result = sample(OurFunction(matrix), SMC(), 5000);

We successfully ran these analyses before this #2007 update. I recently revisited this part of our analysis pipeline and the sampling code does not work anymore (keyword argument error). I tried other samplers, but unsuccessfully.

Is there a different way that we should now be feeding data (like a matrix) into a sampled function? How might we solve this issue?

Thank you so much for any help!
Joel

@torfjelde
Copy link
Member Author

Hey! Glad to hear you like it:)

At the moment, I think the best approach is unfortunately to implement OurFunction without keyword arguments, or alternatively provide a wrapper around it. For example if we have the following model

@model function demo(arg1, arg2, kwargs::NamedTuple)
    kwarg1 = kwargs.kwarg1
    kwarg2 = kwargs.kwarg2
    x ~ Normal(kwarg1, kwarg2)
end

you can define another version by hand like this:

function demo(arg1, arg2; kwargs...)
    return demo(arg1, arg2, NamedTuple(kwargs))
end

Then you can continue using the method with keyword arguments, but it will all still work:)

Does that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants