Skip to content

Commit 962d7e0

Browse files
committed
Merge branch 'master' of github.com:quantumghent/PEPSKit.jl
2 parents 526ec8b + 0c86e39 commit 962d7e0

6 files changed

Lines changed: 45 additions & 15 deletions

File tree

examples/heisenberg_evol/simpleupdate.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ trscheme_env = truncerr(1e-10) & truncdim(χenv)
77
Nr, Nc = 2, 2
88
# Heisenberg model Hamiltonian
99
# (already only includes nearest neighbor terms)
10-
ham = heisenberg_XYZ(ComplexF64, symm, InfiniteSquare(Nr, Nc); Jx=1.0, Jy=1.0, Jz=1.0)
11-
# convert to real tensors
12-
ham = LocalOperator(ham.lattice, Tuple(ind => real(op) for (ind, op) in ham.terms)...)
10+
ham = real(heisenberg_XYZ(ComplexF64, symm, InfiniteSquare(Nr, Nc); Jx=1.0, Jy=1.0, Jz=1.0))
1311

1412
# random initialization of 2x2 iPEPS with weights and CTMRGEnv (using real numbers)
1513
if symm == Trivial

src/algorithms/optimization/peps_optimization.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ The optimization parameters can be supplied via the keyword arguments or directl
112112
* `tol::Real=$(Defaults.optimizer_tol)` : Overall tolerance for gradient norm convergence of the optimizer. Sets related tolerance such as the boundary and boundary-gradient tolerances to sensible defaults unless they are explictly specified.
113113
* `verbosity::Int=1` : Overall output information verbosity level, should be one of the following:
114114
0. Suppress all output
115-
1. Optimizer output and warnings
116-
2. Additionally print boundary information
117-
3. All information including AD debug outputs
115+
1. Only print warnings
116+
2. Initialization and convergence info
117+
3. Iteration info
118+
4. Debug info including AD outputs
118119
* `reuse_env::Bool=$(Defaults.reuse_env)` : If `true`, the current optimization step is initialized on the previous environment, otherwise a random environment is used.
119120
* `symmetrization::Union{Nothing,SymmetrizationStyle}=nothing` : Accepts `nothing` or a `SymmetrizationStyle`, in which case the PEPS and PEPS gradient are symmetrized after each optimization iteration.
120121
* `(finalize!)=OptimKit._finalize!` : Inserts a `finalize!` function call after each optimization step by utilizing the `finalize!` kwarg of `OptimKit.optimize`. The function maps `(peps, env), f, g = finalize!((peps, env), f, g, numiter)`.

src/algorithms/select_algorithm.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ function select_algorithm(
2121
::typeof(fixedpoint),
2222
env₀::CTMRGEnv;
2323
tol=Defaults.optimizer_tol, # top-level tolerance
24-
verbosity=2, # top-level verbosity
24+
verbosity=3, # top-level verbosity
2525
boundary_alg=(;),
2626
gradient_alg=(;),
2727
optimizer_alg=(;),
2828
kwargs...,
2929
)
3030
# adjust CTMRG tols and verbosity
3131
if boundary_alg isa NamedTuple
32-
defaults = (; verbosity=verbosity 1 ? -1 : verbosity, tol=1e-4tol)
32+
defaults = (; verbosity=verbosity 3 ? -1 : 3, tol=1e-4tol)
3333
boundary_kwargs = merge(defaults, boundary_alg)
3434
boundary_alg = select_algorithm(leading_boundary, env₀; boundary_kwargs...)
3535
end
3636

3737
# adjust gradient verbosity
3838
if gradient_alg isa NamedTuple
3939
# TODO: check this:
40-
defaults = (; verbosity=verbosity 2 ? -1 : 3, tol=1e-2tol)
40+
defaults = (; verbosity=verbosity 3 ? -1 : 3, tol=1e-2tol)
4141
gradient_alg = merge(defaults, gradient_alg)
4242
end
4343

4444
# adjust optimizer tol and verbosity
4545
if optimizer_alg isa NamedTuple
46-
defaults = (; tol, verbosity=verbosity 1 ? -1 : 3)
46+
defaults = (; tol, verbosity)
4747
optimizer_alg = merge(defaults, optimizer_alg)
4848
end
4949

src/operators/localoperator.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and the terms are stored as a tuple of pairs of indices and operators.
1414
# Constructors
1515
1616
LocalOperator(lattice::Matrix{S}, terms::Pair...)
17-
LocalOperator{T,S}(lattice::Matrix{S}, terms::T) where {T,S} # expert mode
17+
LocalOperator{T,S}(lattice::Matrix{S}, terms::T) where {T,S}
1818
1919
# Examples
2020
@@ -31,6 +31,7 @@ struct LocalOperator{T<:Tuple,S}
3131
# Check if the indices of the operator are valid with themselves and the lattice
3232
for (inds, operator) in terms
3333
@assert operator isa AbstractTensorMap
34+
@assert eltype(inds) <: CartesianIndex
3435
@assert numout(operator) == numin(operator) == length(inds)
3536
@assert spacetype(operator) == S
3637

@@ -52,7 +53,12 @@ function LocalOperator(
5253
relevant_terms = []
5354
for inds in unique(allinds)
5455
operator = sum(alloperators[findall(==(inds), allinds)])
55-
norm(operator) > atol && push!(relevant_terms, inds => operator)
56+
cinds = if !(eltype(inds) <: CartesianIndex) # force indices to be CartesianIndices
57+
map(CartesianIndex, inds)
58+
else
59+
inds
60+
end
61+
norm(operator) > atol && push!(relevant_terms, cinds => operator)
5662
end
5763

5864
terms_tuple = Tuple(relevant_terms)
@@ -90,6 +96,15 @@ function Base.repeat(O::LocalOperator, m::Int, n::Int)
9096
return LocalOperator(lattice, terms...)
9197
end
9298

99+
# Real and imaginary part
100+
# -----------------------
101+
function Base.real(O::LocalOperator)
102+
return LocalOperator(O.lattice, (ind => real(op) for (ind, op) in O.terms)...)
103+
end
104+
function Base.imag(O::LocalOperator)
105+
return LocalOperator(O.lattice, (ind => imag(op) for (ind, op) in O.terms)...)
106+
end
107+
93108
# Linear Algebra
94109
# --------------
95110
function Base.:*::Number, O::LocalOperator)

src/states/infiniteweightpeps.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ function InfinitePEPS(peps::InfiniteWeightPEPS)
267267
)
268268
end
269269

270+
"""
271+
InfiniteWeightPEPS(peps::InfinitePEPS)
272+
273+
Create `InfiniteWeightPEPS` from `InfinitePEPS` by initializing the bond weights as identity matrices of element type `Float64`.
274+
"""
275+
function InfiniteWeightPEPS(peps::InfinitePEPS)
276+
Nr, Nc = size(peps)
277+
weights = map(Iterators.product(1:2, 1:Nr, 1:Nc)) do (d, r, c)
278+
V = (d == 1 ? domain(peps[r, c])[2] : domain(peps[r, c])[1])
279+
@assert !isdual(V)
280+
DiagonalTensorMap(ones(reduceddim(V)), V)
281+
end
282+
return InfiniteWeightPEPS(peps.A, SUWeight(weights))
283+
end
284+
270285
"""
271286
mirror_antidiag(peps::InfiniteWeightPEPS)
272287

test/examples/heisenberg.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ end
5959
for ind in CartesianIndices(wpeps.vertices)
6060
wpeps.vertices[ind] /= norm(wpeps.vertices[ind], Inf)
6161
end
62-
# Heisenberg model Hamiltonian (already only includes nearest neighbor terms)
62+
# Heisenberg model Hamiltonian
6363
ham = heisenberg_XYZ(InfiniteSquare(N1, N2); Jx=1.0, Jy=1.0, Jz=1.0)
64-
# convert to real tensors
65-
ham = LocalOperator(ham.lattice, Tuple(ind => real(op) for (ind, op) in ham.terms)...)
64+
# assert imaginary part is zero
65+
@assert length(imag(ham).terms) == 0
66+
ham = real(ham)
6667

6768
# simple update
6869
dts = [1e-2, 1e-3, 1e-3, 1e-4]

0 commit comments

Comments
 (0)