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

[ITensors] Fix checkflux for QN ITensor with no blocks #1210

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/qn/flux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ function flux(T::Tensor)
return flux(T, block1)
end

function checkflux(T::Tensor, flux_check)
function checkflux(T::Tensor, flux_to_check)
for b in nzblocks(T)
fluxTb = flux(T, b)
if fluxTb != flux_check
if fluxTb != flux_to_check
error(
"Block $b has flux $fluxTb that is inconsistent with the desired flux $flux_check"
"Block $b has flux $fluxTb that is inconsistent with the desired flux $flux_to_check",
)
end
end
return nothing
end

function checkflux(T::Tensor)
b1 = first(nzblocks(T))
fluxTb1 = flux(T, b1)
nzb = nzblocks(T)
isempty(nzb) && return nothing
fluxTb1 = flux(T, first(nzb))
return checkflux(T, fluxTb1)
end
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions test/base/test_qnitensor.jl
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Random.seed!(1234)
]
@test_throws ErrorException ITensor(A, i', dag(i); tol=1e-8)
@test ITensor(A, i', dag(i); tol=1e-8, checkflux=false) isa ITensor

# Construct from zero matrix. Flux check should still pass
# (Regression test for issue #1209)
@test ITensor(zeros(3, 3), i', dag(i)) isa ITensor
end

@testset "similartype regression test" begin
Expand Down
Loading