Skip to content

Commit

Permalink
[ITensorGaussianMPS] [Bug] Fix mismatched convention for single parti…
Browse files Browse the repository at this point in the history
…cle Hamiltonians (#1100)
  • Loading branch information
b-kloss authored Mar 24, 2023
1 parent f25e2be commit 990dfa9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/gmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function hopping_operator(os::OpSum; drop_pairing_terms_tol=nothing)
if !all(abs.(h[1:N, (N + 1):(2 * N)]) .< drop_pairing_terms_tol)
error("Trying to convert hamiltonian with pairing terms to hopping hamiltonian!")
end
return h[(N + 1):(2 * N), (N + 1):(2 * N)]
return 2 .* h[(N + 1):(2 * N), (N + 1):(2 * N)]
end

# Make a combined hopping Hamiltonian for spin up and down
Expand All @@ -249,7 +249,7 @@ function hopping_operator(os_up::OpSum, os_dn::OpSum; drop_pairing_terms_tol=not
if !all(abs.(h[1:N, (N + 1):(2 * N)]) .< drop_pairing_terms_tol)
error("Trying to convert hamiltonian with pairing terms to hopping hamiltonian!")
end
return h[(N + 1):(2 * N), (N + 1):(2 * N)]
return 2 .* h[(N + 1):(2 * N), (N + 1):(2 * N)]
end

function hopping_hamiltonian(os::OpSum; drop_pairing_terms_tol=nothing)
Expand Down
2 changes: 1 addition & 1 deletion test/electron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ end
Φ_up = slater_determinant_matrix(h_up, Nf_up)
Φ_dn = slater_determinant_matrix(h_dn, Nf_dn)
ψ = slater_determinant_to_mps(s, Φ_up, Φ_dn; eigval_cutoff=0.0, cutoff=0.0)
@test inner', H, ψ) tr(Φ_up'h_up * Φ_up) + tr(Φ_dn'h_dn * Φ_dn)
@test inner', H, ψ) tr(Φ_up' * h_up * Φ_up) + tr(Φ_dn' * h_dn * Φ_dn)
@test maxlinkdim(ψ) == 2
@test flux(ψ) == QN(("Nf", 1, -1), ("Sz", 1))
ns_up = expect_compat(ψ, "Nup")
Expand Down
8 changes: 5 additions & 3 deletions test/gmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ end

@test all(
abs.(
ITensorGaussianMPS.reverse_interleave(Matrix(h_hopandpair))[
(N + 1):end, (N + 1):end
] - h_hop
(
2 .* ITensorGaussianMPS.reverse_interleave(Matrix(h_hopandpair))[
(N + 1):end, (N + 1):end
]
) - h_hop
) .< eps(Float32),
)
end
Expand Down

0 comments on commit 990dfa9

Please sign in to comment.