DynamicPPL.jl icon indicating copy to clipboard operation
DynamicPPL.jl copied to clipboard

Don't overload `rand` for test models

Open torfjelde opened this issue 2 years ago • 3 comments

In TestUtils we're currently overloading rand(rng, ::Type{NamedTuple}, model) which is supposed to represent a "ground truth sample from the prior", which, IMO, we shouldn't be doing.

The problem is that it will silently "do the right thing" for most models, even if we've forgotten to implement this method, e.g. as seen in #499. I remember this being part of our original discussion when TestUtils was introduced (I was in favour of what is suggested in this issue, but we ended up overloading rand instead).

torfjelde avatar Jul 17 '23 16:07 torfjelde

This just a bit me again trying to do condition on one of the test models and running rand...

@devmotion I believe we had a discussion about this in the original PR; you happy with me to go ahead with making this change?

torfjelde avatar Jul 19 '23 11:07 torfjelde

I don't remember the discussion 😅 Not completely clear to me from your comments what exactly the problem is but I'm happy with a PR that fixes current issues 🙂

devmotion avatar Jul 19 '23 12:07 devmotion

Not completely clear to me from your comments what exactly the problem is

If I want to test, say, the condition behavior, I might do something like:

model = DynamicPPL.TestUtils.DEMO_MODELS[1]
rand(model | (m = 1,))

and check that m is no longer present in the output of rand; currently this always produces the same result because rand is hard-coded for model :grimacing:

But bueno! Will do that then :+1:

torfjelde avatar Jul 19 '23 13:07 torfjelde

This has been removed at some point:)

torfjelde avatar Apr 19 '24 14:04 torfjelde