Skip to content

Commit 195200c

Browse files
committed
simplify MPS printing
1 parent fbfe8b1 commit 195200c

File tree

1 file changed

+12
-46
lines changed

1 file changed

+12
-46
lines changed

src/states/finitemps.jl

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS)
450450
io = IOContext(io, :typeinfo => eltype(ψ), :compact => true)
451451
charset = (; start = "", mid = "", stop = "", ver = "", dash = "──")
452452
limit = get(io, :limit, true)::Bool
453-
lines_per_tensor = 4
454-
half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * lines_per_tensor) : typemax(Int)
453+
half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int)
455454
if !haskey(io, :compact)
456455
io = IOContext(io, :compact => true)
457456
end
@@ -461,66 +460,33 @@ function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS)
461460

462461
for site in HalfInt.(reverse((1 / 2):(1 / 2):(L + 1 / 2)))
463462
if site < half_screen_rows || site > L - half_screen_rows
463+
char = if isinteger(site)
464+
site == 1 ? charset.stop : (site == L && site > c) ? charset.start : charset.mid
465+
else
466+
site == HalfInt(L + 1 / 2) ? charset.start : site == HalfInt(1 / 2) ? charset.stop : charset.ver
467+
end
464468
if site > c # ARs
465469
if isinteger(site)
466-
print(
467-
io, Int(site) == L ? charset.start : charset.mid, charset.dash,
468-
" AR[$(Int(site))]: "
469-
)
470-
replace(io, sprint((x, y) -> show(x, mime, y), ψ.ARs[Int(site)]), "\n" => "\n" * charset.ver)
470+
print(io, char, charset.dash, " AR[$(Int(site))]: ", space.ARs[Int(site)]))
471471
site == 1 || println(io)
472472
end
473473
elseif site == c # AC or C
474474
if isinteger(c) # center is an AC
475-
print(
476-
io, if site == L
477-
charset.start
478-
elseif site == 1
479-
charset.stop
480-
else
481-
charset.mid
482-
end, charset.dash, " AC[$(Int(site))]: "
483-
)
484-
if site != 1
485-
replace(io, sprint((x, y) -> show(x, mime, y), ψ.ACs[Int(site)]), "\n" => "\n" * charset.ver)
486-
else
487-
show(io, mime, ψ.ACs[Int(site)])
488-
end
475+
print(io, char, charset.dash, " AC[$(Int(site))]: ", space.ACs[Int(site)]))
489476
site == 1 || println(io)
490477
else # center is a bond-tensor
491-
print(
492-
io, if site == HalfInt(L + 1 / 2)
493-
charset.start
494-
elseif site == HalfInt(1 / 2)
495-
charset.stop
496-
else
497-
charset.ver
498-
end, " C[$(Int(site - 1 / 2))]: "
499-
)
500-
if site != 1
501-
replace(io, sprint((x, y) -> show(x, mime, y), ψ.Cs[Int(site + 1 / 2)]), "\n" => "\n" * charset.ver)
502-
else
503-
show(io, mime, ψ.Cs[Int(site + 1 / 2)])
504-
end
478+
print(io, char, " C[$(Int(site - 1 / 2))]: ", space.Cs[Int(site + 1 / 2)]))
505479
site == 1 || println(io)
506480
end
507481
else
508482
if isinteger(site)
509-
print(
510-
io, site == 1 ? charset.stop : charset.mid, charset.dash,
511-
" AL[$(Int(site))]: ",
512-
)
513-
if site != 1
514-
replace(io, sprint((x, y) -> show(x, mime, y), ψ.ALs[Int(site)]), "\n" => "\n" * charset.ver)
515-
else
516-
show(io, mime, ψ.ALs[Int(site)])
517-
end
483+
print(io, char, charset.dash, " AL[$(Int(site))]: ", space.ALs[Int(site)]))
518484
site == 1 || println(io)
519485
end
520486
end
521487
elseif site == half_screen_rows
522-
println(io, charset.ver, "")
523-
println(io, charset.ver)
488+
println(io, charset.ver, "\n", charset.ver)
489+
site == 1 || println(io)
524490
end
525491
end
526492
return nothing

0 commit comments

Comments
 (0)