Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Fix truncation of 0s on evolve!
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Apr 17, 2024
1 parent c1eab27 commit e4b9ff8
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Truncate the dimension of the virtual `bond`` of the [`Chain`](@ref) Tensor Netw
- Either `threshold` or `maxdim` must be provided. If both are provided, `maxdim` is used.
- The bond must contain the Schmidt coefficients, i.e. a site canonization must be performed before calling `truncate!`.
"""
function truncate!(qtn::Chain, bond; threshold::Union{Nothing,Real} = nothing, maxdim::Union{Nothing,Int} = nothing)
function truncate!(qtn::Chain, bond; threshold::Real = 1e-16, maxdim::Union{Nothing,Int} = nothing)
# TODO replace for select(:between)
vind = rightindex(qtn, bond[1])
if vind != leftindex(qtn, bond[2])
Expand All @@ -332,12 +332,15 @@ function truncate!(qtn::Chain, bond; threshold::Union{Nothing,Real} = nothing, m
tensor = TensorNetwork(qtn)[vind]
spectrum = parent(tensor)

extent = if !isnothing(maxdim)
1:min(size(TensorNetwork(qtn), vind), maxdim)
elseif !isnothing(threshold)
findall(>(threshold) abs, spectrum)
extent = if isnothing(maxdim)
1:size(size(TensorNetwork(qtn), vind))
else
throw(ArgumentError("Either `threshold` or `maxdim` must be provided"))
1:min(size(TensorNetwork(qtn), vind), maxdim)
end |> collect

# remove 0s from spectrum
filter!(extent) do i
abs(spectrum[i]) > threshold
end

slice!(TensorNetwork(qtn), vind, extent)
Expand Down Expand Up @@ -461,14 +464,7 @@ end
Applies a local operator `gate` to the [`Chain`](@ref) tensor network.
"""
function evolve!(
qtn::Chain,
gate::Dense;
threshold = nothing,
maxdim = nothing,
iscanonical = false,
renormalize = false,
)
function evolve!(qtn::Chain, gate::Dense; threshold = 1e-16, maxdim = nothing, iscanonical = false, renormalize = false)
# check gate is a valid operator
if !(socket(gate) isa Operator)
throw(ArgumentError("Gate must be an operator, but got $(socket(gate))"))
Expand Down

0 comments on commit e4b9ff8

Please sign in to comment.