Skip to content

Commit aae67b5

Browse files
authored
[Feature] Update show methods to reflect new TensorKit printing (#341)
* update finitemps printing * update infinitemps printing * update MPO printing * simplify MPS printing * another show attempt * one more show update * also include infinitemps * some reorganization * Also fix environments * export JordanMPO + type alias to shorten printing * address comments
1 parent 666f2d3 commit aae67b5

File tree

7 files changed

+256
-205
lines changed

7 files changed

+256
-205
lines changed

src/MPSKit.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export QP, LeftGaugedQP, RightGaugedQP
1818
# operators:
1919
export AbstractMPO
2020
export MPO, FiniteMPO, InfiniteMPO
21+
export JordanMPOTensor, JordanMPOTensorMap
2122
export MPOHamiltonian, FiniteMPOHamiltonian, InfiniteMPOHamiltonian
2223
export MultilineMPO
2324
export UntimedOperator, TimedOperator, MultipliedOperator, LazySum
@@ -123,7 +124,6 @@ include("operators/projection.jl")
123124
include("operators/timedependence.jl")
124125
include("operators/multipliedoperator.jl")
125126
include("operators/lazysum.jl")
126-
include("operators/show.jl")
127127

128128
include("transfermatrix/transfermatrix.jl")
129129
include("transfermatrix/transfer.jl")
@@ -189,6 +189,8 @@ include("algorithms/ED.jl")
189189

190190
include("algorithms/unionalg.jl")
191191

192+
include("utility/show.jl")
193+
192194
function __init__()
193195
Defaults.set_scheduler!()
194196
return nothing

src/environments/finite_envs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
struct FiniteEnvironments <: AbstractMPSEnvironments
33
4-
Environment manager for `FiniteMPS` and `WindowMPS`. This structure is responsable for automatically checking
4+
Environment manager for `FiniteMPS` and `WindowMPS`. This structure is responsible for automatically checking
55
if the queried environment is still correctly cached and if not recalculates.
66
"""
77
struct FiniteEnvironments{A, B, C, D} <: AbstractMPSEnvironments

src/operators/jordanmpotensor.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ struct JordanMPOTensor{
5858
end
5959
end
6060

61+
const JordanMPOTensorMap{T, S, A <: DenseVector{T}} = JordanMPOTensor{
62+
T, S,
63+
Union{TensorMap{T, S, 2, 2, A}, BraidingTensor{T, S}},
64+
TensorMap{T, S, 2, 1, A},
65+
TensorMap{T, S, 1, 2, A},
66+
TensorMap{T, S, 1, 1, A},
67+
}
68+
6169
function JordanMPOTensor{E, S}(::UndefInitializer, V::TensorMapSumSpace{S}) where {E, S}
6270
return jordanmpotensortype(S, E)(undef, V)
6371
end
@@ -378,15 +386,12 @@ function Base.isapprox(W1::JordanMPOTensor, W2::JordanMPOTensor; kwargs...)
378386
isapprox(W1.D, W2.D; kwargs...)
379387
end
380388

381-
function Base.summary(io::IO, W::JordanMPOTensor)
382-
szstring = Base.dims2string(size(W))
383-
TT = eltype(W)
384-
typeinfo = get(io, :typeinfo, Any)
385-
if typeinfo <: typeof(W) || typeinfo <: TT
386-
typestring = ""
387-
else
388-
typestring = "{$TT}"
389-
end
390-
V = space(W)
391-
return print(io, "$szstring JordanMPOTensor$typestring($V)")
389+
function Base.showarg(io::IO, W::JordanMPOTensor, toplevel::Bool)
390+
!toplevel && print(io, "::")
391+
print(io, TensorKit.type_repr(typeof(W)))
392+
return nothing
393+
end
394+
395+
function TensorKit.type_repr(::Type{<:JordanMPOTensor{E, S}}) where {E, S}
396+
return "JordanMPOTensor{$E, " * TensorKit.type_repr(S) * ", …}"
392397
end

src/operators/show.jl

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/states/finitemps.jl

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -439,71 +439,6 @@ Compute the dimension of the maximal virtual space at a given site.
439439
"""
440440
max_Ds::FiniteMPS) = dim.(max_virtualspaces(ψ))
441441

442-
function Base.summary(io::IO, ψ::FiniteMPS)
443-
return print(io, "$(length(ψ))-site FiniteMPS ($(scalartype(ψ)), $(spacetype(ψ)))")
444-
end
445-
function Base.show(io::IO, ::MIME"text/plain", ψ::FiniteMPS)
446-
println(io, summary(ψ), ":")
447-
context = IOContext(io, :typeinfo => eltype(ψ), :compact => true)
448-
return show(context, ψ)
449-
end
450-
Base.show(io::IO, ψ::FiniteMPS) = show(convert(IOContext, io), ψ)
451-
function Base.show(io::IOContext, ψ::FiniteMPS)
452-
charset = (; start = "", mid = "", stop = "", ver = "", dash = "──")
453-
limit = get(io, :limit, false)::Bool
454-
half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int)
455-
if !haskey(io, :compact)
456-
io = IOContext(io, :compact => true)
457-
end
458-
459-
L = length(ψ)
460-
c = ψ.center
461-
462-
for site in HalfInt.(reverse((1 / 2):(1 / 2):(L + 1 / 2)))
463-
if site < half_screen_rows || site > L - half_screen_rows
464-
if site > c # ARs
465-
if isinteger(site)
466-
println(
467-
io, Int(site) == L ? charset.start : charset.mid, charset.dash,
468-
" AR[$(Int(site))]: ", ψ.ARs[Int(site)]
469-
)
470-
end
471-
elseif site == c # AC or C
472-
if isinteger(c) # center is an AC
473-
println(
474-
io, if site == L
475-
charset.start
476-
elseif site == 1
477-
charset.stop
478-
else
479-
charset.mid
480-
end, charset.dash, " AC[$(Int(site))]: ", ψ.ACs[Int(site)]
481-
)
482-
else # center is a bond-tensor
483-
println(
484-
io, if site == HalfInt(L + 1 / 2)
485-
charset.start
486-
elseif site == HalfInt(1 / 2)
487-
charset.stop
488-
else
489-
charset.ver
490-
end, " C[$(Int(site - 1 / 2))]: ", ψ.Cs[Int(site + 1 / 2)]
491-
)
492-
end
493-
else
494-
if isinteger(site)
495-
println(
496-
io, site == 1 ? charset.stop : charset.mid, charset.dash,
497-
" AL[$(Int(site))]: ", ψ.ALs[Int(site)]
498-
)
499-
end
500-
end
501-
elseif site == half_screen_rows
502-
println(io, charset.ver, "")
503-
end
504-
end
505-
return nothing
506-
end
507442

508443
#===========================================================================================
509444
Linear Algebra

src/states/infinitemps.jl

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,36 +311,6 @@ function Base.isapprox(ψ₁::InfiniteMPS, ψ₂::InfiniteMPS; kwargs...)
311311
return isapprox(dot(ψ₁, ψ₂), 1; kwargs...)
312312
end
313313

314-
function Base.show(io::IO, ::MIME"text/plain", ψ::InfiniteMPS)
315-
L = length(ψ)
316-
println(io, L == 1 ? "single site" : "$L-site", " InfiniteMPS:")
317-
context = IOContext(io, :typeinfo => eltype(ψ), :compact => true)
318-
return show(context, ψ)
319-
end
320-
Base.show(io::IO, ψ::InfiniteMPS) = show(convert(IOContext, io), ψ)
321-
function Base.show(io::IOContext, ψ::InfiniteMPS)
322-
charset = (; mid = "", ver = "", dash = "──")
323-
limit = get(io, :limit, false)::Bool
324-
half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int)
325-
if !haskey(io, :compact)
326-
io = IOContext(io, :compact => true)
327-
end
328-
L = length(ψ)
329-
println(io, charset.ver, "")
330-
for site in reverse(1:L)
331-
if site < half_screen_rows || site > L - half_screen_rows
332-
if site == L
333-
println(io, charset.ver, " C[$site]: ", ψ.C[site])
334-
end
335-
println(io, charset.mid, charset.dash, " AL[$site]: ", ψ.AL[site])
336-
elseif site == half_screen_rows
337-
println(io, charset.ver, "")
338-
end
339-
end
340-
println(io, charset.ver, "")
341-
return nothing
342-
end
343-
344314
#===========================================================================================
345315
Fixedpoints
346316
===========================================================================================#

0 commit comments

Comments
 (0)