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

Add getmodel and setmodel from/to LogDensityFunction #626

Merged
merged 13 commits into from
Jul 22, 2024
Prev Previous commit
Next Next commit
add some test
  • Loading branch information
sunxd3 committed Jul 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 66367a7710921896cb5d1dd1eff5fccc1ce6dced
18 changes: 18 additions & 0 deletions test/logdensityfunction.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
using Test, DynamicPPL, LogDensityProblems

@testset "`getmodel` and `setmodel`" begin
# TODO: does it worth to test all demo models?
model = DynamicPPL.TestUtils.DEMO_MODELS[1]
ℓ = DynamicPPL.LogDensityFunction(model)
@test DynamicPPL.getmodel(ℓ) == model
@test DynamicPPL.setmodel(ℓ, model).model == model

# ReverseDiff related
∇ℓ = LogDensityProblems.ADgradient(:ReverseDiff, ℓ; compile=Val(false))
@test DynamicPPL.getmodel(∇ℓ) == model
@test getmodel(DynamicPPL.setmodel(∇ℓ, model)) == model

∇ℓ = LogDensityProblems.ADgradient(:ReverseDiff, ℓ; compile=Val(true))
new_∇ℓ = DynamicPPL.setmodel(∇ℓ, model)
@test DynamicPPL.getmodel(new_∇ℓ) == model
@test new_∇ℓ.ℓ.compiledtape != ∇ℓ.ℓ.compiledtape
end

@testset "LogDensityFunction" begin
@testset "$(nameof(model))" for model in DynamicPPL.TestUtils.DEMO_MODELS
example_values = DynamicPPL.TestUtils.rand_prior_true(model)
Loading