Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/MPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ include("operators/projection.jl")
include("operators/timedependence.jl")
include("operators/multipliedoperator.jl")
include("operators/lazysum.jl")
include("operators/utility.jl") # extra functions that need all of the above structs to be defined and fit nowhere else

include("transfermatrix/transfermatrix.jl")
include("transfermatrix/transfer.jl")
Expand Down
32 changes: 0 additions & 32 deletions src/operators/abstractmpo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,6 @@ function Base.show(io::IOContext, mpo::AbstractMPO)
return nothing
end

function braille(H::SparseMPO)
isfinite = (H isa FiniteMPO) || (H isa FiniteMPOHamiltonian)
dash = "🭻"
stride = 2 #amount of dashes between braille
L = length(H)

brailles = Vector{Vector{String}}(undef, L)
buffer = IOBuffer()
for (i, W) in enumerate(H)
BlockTensorKit.show_braille(buffer, W)
brailles[i] = split(String(take!(buffer)))
end

maxheight = maximum(length.(brailles))

for i in 1:maxheight
line = ""
line *= ((i == 1 && !isfinite) ? ("... " * dash) : " ")
line *= (i > 1 && !isfinite) ? " " : ""
for (j, braille) in enumerate(brailles)
line *= (checkbounds(Bool, braille, i) ? braille[i] :
repeat(" ", length(braille[1])))
if j < L
line *= repeat(((i == 1) ? dash : " "), stride)
end
end
line *= ((i == 1 && !isfinite) ? (dash * " ...") : " ")
println(line)
end
return nothing
end

# Linear Algebra
# --------------
Base.:+(mpo::AbstractMPO) = scale(mpo, One())
Expand Down
33 changes: 33 additions & 0 deletions src/operators/utility.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function braille(io::IO, H::Union{SparseMPO,MPOHamiltonian})
isfinite = (H isa FiniteMPO) || (H isa FiniteMPOHamiltonian)
dash = "🭻"
stride = 2 #amount of dashes between braille
L = length(H)

brailles = Vector{Vector{String}}(undef, L)
buffer = IOBuffer()
for (i, W) in enumerate(H)
BlockTensorKit.show_braille(buffer, W)
brailles[i] = split(String(take!(buffer)))
end

maxheight = maximum(length.(brailles))

for i in 1:maxheight
line = ""
line *= ((i == 1 && !isfinite) ? ("... " * dash) : " ")
line *= (i > 1 && !isfinite) ? " " : ""
for (j, braille) in enumerate(brailles)
line *= (checkbounds(Bool, braille, i) ? braille[i] :
repeat(" ", length(braille[1])))
if j < L
line *= repeat(((i == 1) ? dash : " "), stride)
end
end
line *= ((i == 1 && !isfinite) ? (dash * " ...") : " ")
println(io, line)
end
return nothing
end

braille(H::Union{SparseMPO,MPOHamiltonian}) = braille(stdout, H)

Check warning on line 33 in src/operators/utility.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/utility.jl#L33

Added line #L33 was not covered by tests
30 changes: 30 additions & 0 deletions test/other.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,34 @@ end
end
end

@testset "braille" begin
# Infinite Hamiltonians and MPOs
# -------------------------------
H = transverse_field_ising()
buffer = IOBuffer()
braille(buffer, H)
output = String(take!(buffer))
check = "... 🭻⎡⠉⢀⎤🭻 ...\n ⎣⠀⢀⎦ \n"
@test output == check

O = make_time_mpo(H, 1.0, TaylorCluster(3, false, false))
braille(buffer, O)
output = String(take!(buffer))
check = "... 🭻⎡⡏⠉⠒⠔⎤🭻 ...\n ⎣⡇⠀⠀⡂⎦ \n"
@test output == check

# Finite Hamiltonians and MPOs
# ----------------------------
H = open_boundary_conditions(H, 4)
braille(buffer, H)
output = String(take!(buffer))
check = " ⎡⠉⠀⎤🭻🭻⎡⠉⢀⎤🭻🭻⎡⠉⢀⎤🭻🭻⎡⡀⠀⎤ \n ⎣⠀⠀⎦ ⎣⠀⢀⎦ ⎣⠀⢀⎦ ⎣⡀⠀⎦ \n"
@test output == check

O = make_time_mpo(H, 1.0, TaylorCluster(3, false, false))
braille(buffer, O)
output = String(take!(buffer))
check = " ⎡⠉⠉⎤🭻🭻⎡⠍⠉⠤⠠⎤🭻🭻⎡⡏⠉⠒⠔⎤🭻🭻⎡⡇⠀⎤ \n ⎣⠀⠀⎦ ⎣⡂⠀⠀⠂⎦ ⎣⡇⠀⠀⡂⎦ ⎣⡇⠀⎦ \n"
@test output == check
end
end
Loading