From 990dfa93a46faf13a47b9766e3b6e80d0d98dfd2 Mon Sep 17 00:00:00 2001 From: b-kloss Date: Fri, 24 Mar 2023 15:07:17 -0400 Subject: [PATCH] [ITensorGaussianMPS] [Bug] Fix mismatched convention for single particle Hamiltonians (#1100) --- src/gmps.jl | 4 ++-- test/electron.jl | 2 +- test/gmps.jl | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gmps.jl b/src/gmps.jl index 6ffaa89..2cd4cfd 100644 --- a/src/gmps.jl +++ b/src/gmps.jl @@ -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 @@ -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) diff --git a/test/electron.jl b/test/electron.jl index 0b5db89..8441259 100644 --- a/test/electron.jl +++ b/test/electron.jl @@ -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") diff --git a/test/gmps.jl b/test/gmps.jl index ab5daa4..80ac4a0 100644 --- a/test/gmps.jl +++ b/test/gmps.jl @@ -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