Skip to content

Commit 0ab6e4a

Browse files
Define real, imag for LocalOperator (#177)
* Define `real`, `imag` for `LocalOperator` * Add test on `imag` for `LocalOperator` * Minor improvement on `real`, `imag` for `LocalOperator`
1 parent 4802481 commit 0ab6e4a

3 files changed

Lines changed: 14 additions & 6 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/operators/localoperator.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ function Base.repeat(O::LocalOperator, m::Int, n::Int)
9696
return LocalOperator(lattice, terms...)
9797
end
9898

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+
99108
# Linear Algebra
100109
# --------------
101110
function Base.:*::Number, O::LocalOperator)

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)