Skip to content

Define real, imag for LocalOperator #177

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

Merged
merged 4 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions examples/heisenberg_evol/simpleupdate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ trscheme_env = truncerr(1e-10) & truncdim(χenv)
Nr, Nc = 2, 2
# Heisenberg model Hamiltonian
# (already only includes nearest neighbor terms)
ham = heisenberg_XYZ(ComplexF64, symm, InfiniteSquare(Nr, Nc); Jx=1.0, Jy=1.0, Jz=1.0)
# convert to real tensors
ham = LocalOperator(ham.lattice, Tuple(ind => real(op) for (ind, op) in ham.terms)...)
ham = real(heisenberg_XYZ(ComplexF64, symm, InfiniteSquare(Nr, Nc); Jx=1.0, Jy=1.0, Jz=1.0))

# random initialization of 2x2 iPEPS with weights and CTMRGEnv (using real numbers)
if symm == Trivial
Expand Down
9 changes: 9 additions & 0 deletions src/operators/localoperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@
return LocalOperator(lattice, terms...)
end

# Real and imaginary part
# -----------------------
function Base.real(O::LocalOperator)
return LocalOperator(O.lattice, (ind => real(op) for (ind, op) in O.terms)...)

Check warning on line 102 in src/operators/localoperator.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/localoperator.jl#L101-L102

Added lines #L101 - L102 were not covered by tests
end
function Base.imag(O::LocalOperator)
return LocalOperator(O.lattice, (ind => imag(op) for (ind, op) in O.terms)...)

Check warning on line 105 in src/operators/localoperator.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/localoperator.jl#L104-L105

Added lines #L104 - L105 were not covered by tests
end

# Linear Algebra
# --------------
function Base.:*(α::Number, O::LocalOperator)
Expand Down
7 changes: 4 additions & 3 deletions test/examples/heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ end
for ind in CartesianIndices(wpeps.vertices)
wpeps.vertices[ind] /= norm(wpeps.vertices[ind], Inf)
end
# Heisenberg model Hamiltonian (already only includes nearest neighbor terms)
# Heisenberg model Hamiltonian
ham = heisenberg_XYZ(InfiniteSquare(N1, N2); Jx=1.0, Jy=1.0, Jz=1.0)
# convert to real tensors
ham = LocalOperator(ham.lattice, Tuple(ind => real(op) for (ind, op) in ham.terms)...)
# assert imaginary part is zero
@assert length(imag(ham).terms) == 0
ham = real(ham)

# simple update
dts = [1e-2, 1e-3, 1e-3, 1e-4]
Expand Down