Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsch committed Aug 28, 2024
1 parent 8a720e1 commit b3564d1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/Gutzwiller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ using SpecialFunctions
using Tables
using VectorInterface

import Rimu.Hamiltonians.extended_hubbard_interaction as ebh

export num_parameters, val_and_grad
include("ansatz/abstract.jl")
export VectorAnsatz
Expand Down
12 changes: 7 additions & 5 deletions src/ansatz/extgutzwiller.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Rimu.Hamiltonians: extended_hubbard_interaction

"""
ExtendedGutzwillerAnsatz(hamiltonian) <: AbstractAnsatz
Expand All @@ -24,17 +26,17 @@ Rimu.build_basis(gv::ExtendedGutzwillerAnsatz) = build_basis(gv.hamiltonian)

function val_and_grad(gv::ExtendedGutzwillerAnsatz, addr, params)
g1, g2 = params
ebh_interaction, diag = ebh(addr)
ebh_interaction, diag = extended_hubbard_interaction(addr)

val = exp(-g1 * diag + -g2*ebh_interaction)
val = exp(-g1 * diag + -g2 * extended_hubbard_interaction_interaction)
der_g1 = -diag * val
der_g2 = -ebh_interaction * val
der_g2 = -extended_hubbard_interaction_interaction * val

return val, SVector(der_g1, der_g2)
end

function (gv::ExtendedGutzwillerAnsatz)(addr, params)
g1,g2 = params
ebh_int, bh_int = ebh(addr)
return exp(-g1*bh_int + -g2*ebh_int)
ebh_int, bh_int = extended_hubbard_interaction(addr)
return exp(-g1 * bh_int + -g2 * ebh_int)
end
12 changes: 6 additions & 6 deletions test/ansatz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Rimu
using ForwardDiff

function check_ansatz(H, ansatz, params)
@testset "$H / $ansatz" begin
@testset "$H / $(nameof(typeof(ansatz)))" begin
# these tests look dumb, but assuming H and params are selected properly, they do
# make sense.
@testset "properties" begin
Expand Down Expand Up @@ -49,16 +49,16 @@ end
)
M = num_modes(starting_address(H))

check_ansatz(H, GutzwillerAnsatz(H), [0.4])
check_ansatz(H, GutzwillerAnsatz(H), rand(1))
if H isa ExtendedHubbardReal1D
check_ansatz(H, ExtendedGutzwillerAnsatz(H), [0.4, 0.5])
#check_ansatz(H, ExtendedGutzwillerAnsatz(H), rand(2))
end
if starting_address(H) isa BoseFS
check_ansatz(H, MultinomialAnsatz(H), [0.5])
check_ansatz(H, GutzwillerAnsatz(H) + MultinomialAnsatz(H), [0.5, 0.4, 0.2])
check_ansatz(H, MultinomialAnsatz(H), rand(1))
check_ansatz(H, GutzwillerAnsatz(H) + MultinomialAnsatz(H), rand(3))
end
if starting_address(H) isa SingleComponentFockAddress
check_ansatz(H, JastrowAnsatz(H), rand(M * (M - 2)))
check_ansatz(H, JastrowAnsatz(H), rand((M * (M + 1)) ÷ 2))
check_ansatz(H, RelativeJastrowAnsatz(H), rand(cld(M, 2)))
check_ansatz(H, DensityProfileAnsatz(H), rand(M))
end
Expand Down

0 comments on commit b3564d1

Please sign in to comment.