From 58151002885023d5deb720dbd4ba08072e512741 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Fri, 31 Oct 2025 09:30:44 -0400 Subject: [PATCH 01/11] update finitemps printing --- src/states/finitemps.jl | 61 +++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/src/states/finitemps.jl b/src/states/finitemps.jl index 9d0fe986a..fc30692c5 100644 --- a/src/states/finitemps.jl +++ b/src/states/finitemps.jl @@ -440,18 +440,18 @@ Compute the dimension of the maximal virtual space at a given site. max_Ds(ψ::FiniteMPS) = dim.(max_virtualspaces(ψ)) function Base.summary(io::IO, ψ::FiniteMPS) - return print(io, "$(length(ψ))-site FiniteMPS ($(scalartype(ψ)), $(spacetype(ψ)))") -end -function Base.show(io::IO, ::MIME"text/plain", ψ::FiniteMPS) - println(io, summary(ψ), ":") - context = IOContext(io, :typeinfo => eltype(ψ), :compact => true) - return show(context, ψ) -end -Base.show(io::IO, ψ::FiniteMPS) = show(convert(IOContext, io), ψ) -function Base.show(io::IOContext, ψ::FiniteMPS) + D = maximum(dim, left_virtualspace(ψ)) + return print(io, "$(length(ψ))-site FiniteMPS ($(scalartype(ψ)), $(spacetype(ψ))) with maximal dimension $D") +end +function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS) + summary(io, ψ) + get(io, :compact, false)::Bool && return nothing + println(io, ":") + io = IOContext(io, :typeinfo => eltype(ψ), :compact => true) charset = (; start = "┌", mid = "├", stop = "└", ver = "│", dash = "──") - limit = get(io, :limit, false)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) + limit = get(io, :limit, true)::Bool + lines_per_tensor = 4 + half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * lines_per_tensor) : typemax(Int) if !haskey(io, :compact) io = IOContext(io, :compact => true) end @@ -463,43 +463,64 @@ function Base.show(io::IOContext, ψ::FiniteMPS) if site < half_screen_rows || site > L - half_screen_rows if site > c # ARs if isinteger(site) - println( + print( io, Int(site) == L ? charset.start : charset.mid, charset.dash, - " AR[$(Int(site))]: ", ψ.ARs[Int(site)] + " AR[$(Int(site))]: " ) + replace(io, sprint((x, y) -> show(x, mime, y), ψ.ARs[Int(site)]), "\n" => "\n" * charset.ver) + site == 1 || println(io) end elseif site == c # AC or C if isinteger(c) # center is an AC - println( + print( io, if site == L charset.start elseif site == 1 charset.stop else charset.mid - end, charset.dash, " AC[$(Int(site))]: ", ψ.ACs[Int(site)] + end, charset.dash, " AC[$(Int(site))]: " ) + if site != 1 + replace(io, sprint((x, y) -> show(x, mime, y), ψ.ACs[Int(site)]), "\n" => "\n" * charset.ver) + else + show(io, mime, ψ.ACs[Int(site)]) + end + site == 1 || println(io) else # center is a bond-tensor - println( + print( io, if site == HalfInt(L + 1 / 2) charset.start elseif site == HalfInt(1 / 2) charset.stop else charset.ver - end, " C[$(Int(site - 1 / 2))]: ", ψ.Cs[Int(site + 1 / 2)] + end, " C[$(Int(site - 1 / 2))]: " ) + if site != 1 + replace(io, sprint((x, y) -> show(x, mime, y), ψ.Cs[Int(site + 1 / 2)]), "\n" => "\n" * charset.ver) + else + show(io, mime, ψ.Cs[Int(site + 1 / 2)]) + end + site == 1 || println(io) end else if isinteger(site) - println( + print( io, site == 1 ? charset.stop : charset.mid, charset.dash, - " AL[$(Int(site))]: ", ψ.ALs[Int(site)] + " AL[$(Int(site))]: ", ) + if site != 1 + replace(io, sprint((x, y) -> show(x, mime, y), ψ.ALs[Int(site)]), "\n" => "\n" * charset.ver) + else + show(io, mime, ψ.ALs[Int(site)]) + end + site == 1 || println(io) end end elseif site == half_screen_rows - println(io, charset.ver, "⋮") + println(io, charset.ver, " ⋮") + println(io, charset.ver) end end return nothing From 725a1edf659bac3e4b64fca6d5b0d4587a5abe54 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Fri, 31 Oct 2025 09:40:43 -0400 Subject: [PATCH 02/11] update infinitemps printing --- src/states/infinitemps.jl | 44 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/states/infinitemps.jl b/src/states/infinitemps.jl index c9a4cf906..394442ca0 100644 --- a/src/states/infinitemps.jl +++ b/src/states/infinitemps.jl @@ -311,33 +311,43 @@ function Base.isapprox(ψ₁::InfiniteMPS, ψ₂::InfiniteMPS; kwargs...) return isapprox(dot(ψ₁, ψ₂), 1; kwargs...) end -function Base.show(io::IO, ::MIME"text/plain", ψ::InfiniteMPS) +function Base.summary(io::IO, ψ::InfiniteMPS) + D = maximum(dim, left_virtualspace(ψ)) L = length(ψ) - println(io, L == 1 ? "single site" : "$L-site", " InfiniteMPS:") - context = IOContext(io, :typeinfo => eltype(ψ), :compact => true) - return show(context, ψ) + return print(io, "$L-site InfiniteMPS ($(scalartype(ψ)), $(spacetype(ψ))) with maximal dimension $D") end -Base.show(io::IO, ψ::InfiniteMPS) = show(convert(IOContext, io), ψ) -function Base.show(io::IOContext, ψ::InfiniteMPS) - charset = (; mid = "├", ver = "│", dash = "──") - limit = get(io, :limit, false)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) - if !haskey(io, :compact) - io = IOContext(io, :compact => true) - end + +function Base.show(io::IO, mime::MIME"text/plain", ψ::InfiniteMPS) + summary(io, ψ) + get(io, :compact, false)::Bool && return nothing + println(io, ":") + io = IOContext(io, :typeinfo => eltype(ψ), :compact => true) + L = length(ψ) - println(io, charset.ver, " ⋮") + charset = (; mid = "├", ver = "│", dash = "──") + limit = get(io, :limit, true)::Bool + lines_per_tensor = 4 + half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * lines_per_tensor) : typemax(Int) + + println(io, charset.ver, " ⋮") + println(io, charset.ver) for site in reverse(1:L) if site < half_screen_rows || site > L - half_screen_rows if site == L - println(io, charset.ver, " C[$site]: ", ψ.C[site]) + print(io, charset.ver, " C[$site]: ") + replace(io, sprint((x, y) -> show(x, mime, y), ψ.C[site]), "\n" => "\n" * charset.ver) + println(io) end - println(io, charset.mid, charset.dash, " AL[$site]: ", ψ.AL[site]) + print(io, charset.mid, charset.dash, " AL[$site]: ") + replace(io, sprint((x, y) -> show(x, mime, y), ψ.AL[site]), "\n" => "\n" * charset.ver) + println(io) elseif site == half_screen_rows - println(io, charset.ver, "⋮") + println(io, charset.ver, " ⋮") + println(io, charset.ver) end end - println(io, charset.ver, " ⋮") + println(io, charset.ver, " ⋮") + return nothing end From 5276348c44a1da82704037a6cce8be6be6df6494 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Fri, 31 Oct 2025 10:03:50 -0400 Subject: [PATCH 03/11] update MPO printing --- src/operators/jordanmpotensor.jl | 19 ++++++------- src/operators/show.jl | 49 ++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/operators/jordanmpotensor.jl b/src/operators/jordanmpotensor.jl index 6688b8182..80be3dea1 100644 --- a/src/operators/jordanmpotensor.jl +++ b/src/operators/jordanmpotensor.jl @@ -378,15 +378,12 @@ function Base.isapprox(W1::JordanMPOTensor, W2::JordanMPOTensor; kwargs...) isapprox(W1.D, W2.D; kwargs...) end -function Base.summary(io::IO, W::JordanMPOTensor) - szstring = Base.dims2string(size(W)) - TT = eltype(W) - typeinfo = get(io, :typeinfo, Any) - if typeinfo <: typeof(W) || typeinfo <: TT - typestring = "" - else - typestring = "{$TT}" - end - V = space(W) - return print(io, "$szstring JordanMPOTensor$typestring($V)") +function Base.showarg(io::IO, W::JordanMPOTensor, toplevel::Bool) + !toplevel && print(io, "::") + print(io, TensorKit.type_repr(typeof(W))) + return nothing +end + +function TensorKit.type_repr(::Type{<:JordanMPOTensor{E, S}}) where {E, S} + return "JordanMPOTensor{$E, " * TensorKit.type_repr(S) * ", …}" end diff --git a/src/operators/show.jl b/src/operators/show.jl index 020ad895f..c81c02bc7 100644 --- a/src/operators/show.jl +++ b/src/operators/show.jl @@ -1,17 +1,24 @@ # AbstractMPO # ----------- -function Base.show(io::IO, ::MIME"text/plain", W::AbstractMPO) - L = length(W) - println(io, L == 1 ? "single site " : "$L-site ", typeof(W), ":") - context = IOContext(io, :typeinfo => eltype(W), :compact => true) - return show(context, W) + +function Base.summary(io::IO, mpo::AbstractMPO) + L = length(mpo) + D = maximum(dim, left_virtualspace(mpo)) + print(io, "$L-site $(typeof(mpo)) with maximal dimension $D") + return nothing end -Base.show(io::IO, mpo::AbstractMPO) = show(convert(IOContext, io), mpo) -function Base.show(io::IOContext, mpo::AbstractMPO) +function Base.show(io::IO, mime::MIME"text/plain", mpo::AbstractMPO) + summary(io, mpo) + + get(io, :compact, false)::Bool && return nothing + println(io, ":") + io = IOContext(io, :typeinfo => eltype(mpo)) + context = :compact => (get(io, :compact, false)::Bool) + charset = (; top = "┬", bot = "┴", mid = "┼", ver = "│", dash = "──") limit = get(io, :limit, false)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) + half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * 8) : typemax(Int) L = length(mpo) # used to align all mposite infos regardless of the length of the mpo (100 takes up more space than 5) @@ -23,23 +30,35 @@ function Base.show(io::IOContext, mpo::AbstractMPO) for site in reverse(1:L) if site < half_screen_rows || site > L - half_screen_rows if site == L && isfinite - println( + print( io, charset.top, " $mpoletter[$site]: ", - repeat(" ", npad - floor(Int, log10(site))), mpo[site] + repeat(" ", npad - floor(Int, log10(site))) ) + replace(io, sprint((x, y) -> show(x, mime, y), mpo[site]; context), "\n" => "\n" * charset.ver) + println(io) elseif (site == 1) && isfinite - println( + print( io, charset.bot, " $mpoletter[$site]: ", - repeat(" ", npad - floor(Int, log10(site))), mpo[site] + repeat(" ", npad - floor(Int, log10(site))) ) + replace(io, sprint((x, y) -> show(x, mime, y), mpo[site]; context), "\n" => "\n" * charset.ver) + println(io) else - println( + print( io, charset.mid, " $mpoletter[$site]: ", - repeat(" ", npad - floor(Int, log10(site))), mpo[site] + repeat(" ", npad - floor(Int, log10(site))) ) + if site == 1 + show(io, mime, mpo[site]) + else + replace(io, sprint((x, y) -> show(x, mime, y), mpo[site]; context), "\n" => "\n" * charset.ver) + end + println(io) end elseif site == half_screen_rows - println(io, " ", "⋮") + println(io, charset.ver) + println(io, charset.ver, " ⋮") + println(io, charset.ver) end end !isfinite && println(io, "╵ ⋮") From 2e2b15c3fe37bd38d0f3cc3f897c723c877ecea1 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 5 Nov 2025 20:18:22 -0500 Subject: [PATCH 04/11] simplify MPS printing --- src/states/finitemps.jl | 58 +++++++++-------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/src/states/finitemps.jl b/src/states/finitemps.jl index fc30692c5..6d582ede4 100644 --- a/src/states/finitemps.jl +++ b/src/states/finitemps.jl @@ -450,8 +450,7 @@ function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS) io = IOContext(io, :typeinfo => eltype(ψ), :compact => true) charset = (; start = "┌", mid = "├", stop = "└", ver = "│", dash = "──") limit = get(io, :limit, true)::Bool - lines_per_tensor = 4 - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * lines_per_tensor) : typemax(Int) + half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) if !haskey(io, :compact) io = IOContext(io, :compact => true) end @@ -461,66 +460,33 @@ function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS) for site in HalfInt.(reverse((1 / 2):(1 / 2):(L + 1 / 2))) if site < half_screen_rows || site > L - half_screen_rows + char = if isinteger(site) + site == 1 ? charset.stop : (site == L && site > c) ? charset.start : charset.mid + else + site == HalfInt(L + 1 / 2) ? charset.start : site == HalfInt(1 / 2) ? charset.stop : charset.ver + end if site > c # ARs if isinteger(site) - print( - io, Int(site) == L ? charset.start : charset.mid, charset.dash, - " AR[$(Int(site))]: " - ) - replace(io, sprint((x, y) -> show(x, mime, y), ψ.ARs[Int(site)]), "\n" => "\n" * charset.ver) + print(io, char, charset.dash, " AR[$(Int(site))]: ", space(ψ.ARs[Int(site)])) site == 1 || println(io) end elseif site == c # AC or C if isinteger(c) # center is an AC - print( - io, if site == L - charset.start - elseif site == 1 - charset.stop - else - charset.mid - end, charset.dash, " AC[$(Int(site))]: " - ) - if site != 1 - replace(io, sprint((x, y) -> show(x, mime, y), ψ.ACs[Int(site)]), "\n" => "\n" * charset.ver) - else - show(io, mime, ψ.ACs[Int(site)]) - end + print(io, char, charset.dash, " AC[$(Int(site))]: ", space(ψ.ACs[Int(site)])) site == 1 || println(io) else # center is a bond-tensor - print( - io, if site == HalfInt(L + 1 / 2) - charset.start - elseif site == HalfInt(1 / 2) - charset.stop - else - charset.ver - end, " C[$(Int(site - 1 / 2))]: " - ) - if site != 1 - replace(io, sprint((x, y) -> show(x, mime, y), ψ.Cs[Int(site + 1 / 2)]), "\n" => "\n" * charset.ver) - else - show(io, mime, ψ.Cs[Int(site + 1 / 2)]) - end + print(io, char, " C[$(Int(site - 1 / 2))]: ", space(ψ.Cs[Int(site + 1 / 2)])) site == 1 || println(io) end else if isinteger(site) - print( - io, site == 1 ? charset.stop : charset.mid, charset.dash, - " AL[$(Int(site))]: ", - ) - if site != 1 - replace(io, sprint((x, y) -> show(x, mime, y), ψ.ALs[Int(site)]), "\n" => "\n" * charset.ver) - else - show(io, mime, ψ.ALs[Int(site)]) - end + print(io, char, charset.dash, " AL[$(Int(site))]: ", space(ψ.ALs[Int(site)])) site == 1 || println(io) end end elseif site == half_screen_rows - println(io, charset.ver, " ⋮") - println(io, charset.ver) + println(io, charset.ver, " ⋮\n", charset.ver) + site == 1 || println(io) end end return nothing From 75787eb21a8baa7efe0c1f511cdcc74564df3b05 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Wed, 5 Nov 2025 20:44:35 -0500 Subject: [PATCH 05/11] another show attempt --- src/states/finitemps.jl | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/states/finitemps.jl b/src/states/finitemps.jl index 6d582ede4..6f7061838 100644 --- a/src/states/finitemps.jl +++ b/src/states/finitemps.jl @@ -441,23 +441,43 @@ max_Ds(ψ::FiniteMPS) = dim.(max_virtualspaces(ψ)) function Base.summary(io::IO, ψ::FiniteMPS) D = maximum(dim, left_virtualspace(ψ)) - return print(io, "$(length(ψ))-site FiniteMPS ($(scalartype(ψ)), $(spacetype(ψ))) with maximal dimension $D") + return print(io, "$(length(ψ))-site FiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ))))") end function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS) summary(io, ψ) + print(io, " with center $(ψ.center)") get(io, :compact, false)::Bool && return nothing println(io, ":") - io = IOContext(io, :typeinfo => eltype(ψ), :compact => true) + io = IOContext(io, :typeinfo => spacetype(ψ), :compact => true) charset = (; start = "┌", mid = "├", stop = "└", ver = "│", dash = "──") limit = get(io, :limit, true)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int) - if !haskey(io, :compact) - io = IOContext(io, :compact => true) - end + half_screen_rows = limit ? div(displaysize(io)[1] - 8, 4) : typemax(Int) L = length(ψ) - c = ψ.center + for i in reverse(1:L) + if i < half_screen_rows || i > L - half_screen_rows + Vr = right_virtualspace(ψ, i) + if i == L && Vr == oneunit(Vr) + println(io, "┌─[$i]─ ", physicalspace(ψ, i)) + elseif i == 1 + println(io, "│ ", Vr) + Vl = left_virtualspace(ψ, 1) + if Vl == oneunit(Vr) + println(io, "└─[$i]─ ", physicalspace(ψ, i)) + else + println(io, "├─[$i]─ ", physicalspace(ψ, i)) + println(io, "│ ", Vl) + end + else + println(io, "│ ", Vr) + println(io, "├─[$i]─ ", physicalspace(ψ, i)) + end + elseif i == half_screen_rows + println(io, "│ ⋮") + end + end + return nothing for site in HalfInt.(reverse((1 / 2):(1 / 2):(L + 1 / 2))) if site < half_screen_rows || site > L - half_screen_rows char = if isinteger(site) From 507178f560100573daa1676dc30c64af023a6535 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Thu, 6 Nov 2025 07:09:00 -0500 Subject: [PATCH 06/11] one more show update --- src/states/finitemps.jl | 89 ++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 51 deletions(-) diff --git a/src/states/finitemps.jl b/src/states/finitemps.jl index 6f7061838..fe1500f6d 100644 --- a/src/states/finitemps.jl +++ b/src/states/finitemps.jl @@ -440,75 +440,62 @@ Compute the dimension of the maximal virtual space at a given site. max_Ds(ψ::FiniteMPS) = dim.(max_virtualspaces(ψ)) function Base.summary(io::IO, ψ::FiniteMPS) + L = length(ψ) D = maximum(dim, left_virtualspace(ψ)) - return print(io, "$(length(ψ))-site FiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ))))") + return print(io, "$L-site FiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ)))) maxdim: ", D, "\tcenter: ", ψ.center) end -function Base.show(io::IO, mime::MIME"text/plain", ψ::FiniteMPS) +function Base.show(io::IO, ::MIME"text/plain", ψ::FiniteMPS) summary(io, ψ) - print(io, " with center $(ψ.center)") get(io, :compact, false)::Bool && return nothing + println(io, ":") - io = IOContext(io, :typeinfo => spacetype(ψ), :compact => true) - charset = (; start = "┌", mid = "├", stop = "└", ver = "│", dash = "──") - limit = get(io, :limit, true)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 4) : typemax(Int) + io = IOContext(io, :typeinfo => spacetype(ψ)) + limit = get(io, :limit, true)::Bool + half_screen_rows = limit ? div(displaysize(io)[1] - 2, 4) : typemax(Int) L = length(ψ) + if L <= 2 * half_screen_rows # everything fits! + half_screen_rows = typemax(Int) + end + + # special handling of edge spaces => don't print if trivial + Vright = right_virtualspace(ψ, L) + right_trivial = Vright == oneunit(Vright) + Vleft = left_virtualspace(ψ, 1) + left_trivial = Vleft == oneunit(Vleft) + + + right_trivial || println(io, "│ ", Vright) for i in reverse(1:L) - if i < half_screen_rows || i > L - half_screen_rows - Vr = right_virtualspace(ψ, i) - if i == L && Vr == oneunit(Vr) - println(io, "┌─[$i]─ ", physicalspace(ψ, i)) + if i > L - half_screen_rows + if i == L + connector = right_trivial ? "┌" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) elseif i == 1 - println(io, "│ ", Vr) - Vl = left_virtualspace(ψ, 1) - if Vl == oneunit(Vr) - println(io, "└─[$i]─ ", physicalspace(ψ, i)) - else - println(io, "├─[$i]─ ", physicalspace(ψ, i)) - println(io, "│ ", Vl) - end + connector = left_trivial ? "└" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) else - println(io, "│ ", Vr) println(io, "├─[$i]─ ", physicalspace(ψ, i)) end + + i != 1 && println(io, "│ ", left_virtualspace(ψ, i)) elseif i == half_screen_rows println(io, "│ ⋮") - end - end - - return nothing - for site in HalfInt.(reverse((1 / 2):(1 / 2):(L + 1 / 2))) - if site < half_screen_rows || site > L - half_screen_rows - char = if isinteger(site) - site == 1 ? charset.stop : (site == L && site > c) ? charset.start : charset.mid - else - site == HalfInt(L + 1 / 2) ? charset.start : site == HalfInt(1 / 2) ? charset.stop : charset.ver - end - if site > c # ARs - if isinteger(site) - print(io, char, charset.dash, " AR[$(Int(site))]: ", space(ψ.ARs[Int(site)])) - site == 1 || println(io) - end - elseif site == c # AC or C - if isinteger(c) # center is an AC - print(io, char, charset.dash, " AC[$(Int(site))]: ", space(ψ.ACs[Int(site)])) - site == 1 || println(io) - else # center is a bond-tensor - print(io, char, " C[$(Int(site - 1 / 2))]: ", space(ψ.Cs[Int(site + 1 / 2)])) - site == 1 || println(io) - end + elseif i < half_screen_rows + i != L && println(io, "│ ", right_virtualspace(ψ, i)) + if i == L + connector = right_trivial ? "┌" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) + elseif i == 1 + connector = left_trivial ? "└" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) else - if isinteger(site) - print(io, char, charset.dash, " AL[$(Int(site))]: ", space(ψ.ALs[Int(site)])) - site == 1 || println(io) - end + println(io, "├─[$i]─ ", physicalspace(ψ, i)) end - elseif site == half_screen_rows - println(io, charset.ver, " ⋮\n", charset.ver) - site == 1 || println(io) end end + left_trivial || println(io, "│ ", Vleft) + return nothing end From e6ac2ce66c4b8235724ecf34a79378ae8bb0df51 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Thu, 6 Nov 2025 07:37:20 -0500 Subject: [PATCH 07/11] also include infinitemps --- src/states/infinitemps.jl | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/states/infinitemps.jl b/src/states/infinitemps.jl index 394442ca0..8e16a4c10 100644 --- a/src/states/infinitemps.jl +++ b/src/states/infinitemps.jl @@ -314,39 +314,35 @@ end function Base.summary(io::IO, ψ::InfiniteMPS) D = maximum(dim, left_virtualspace(ψ)) L = length(ψ) - return print(io, "$L-site InfiniteMPS ($(scalartype(ψ)), $(spacetype(ψ))) with maximal dimension $D") + return print(io, "$L-site InfiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ)))) maxdim: ", D) end -function Base.show(io::IO, mime::MIME"text/plain", ψ::InfiniteMPS) +function Base.show(io::IO, ::MIME"text/plain", ψ::InfiniteMPS) summary(io, ψ) get(io, :compact, false)::Bool && return nothing + println(io, ":") - io = IOContext(io, :typeinfo => eltype(ψ), :compact => true) + io = IOContext(io, :typeinfo => eltype(ψ)) - L = length(ψ) - charset = (; mid = "├", ver = "│", dash = "──") limit = get(io, :limit, true)::Bool - lines_per_tensor = 4 - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * lines_per_tensor) : typemax(Int) - - println(io, charset.ver, " ⋮") - println(io, charset.ver) - for site in reverse(1:L) - if site < half_screen_rows || site > L - half_screen_rows - if site == L - print(io, charset.ver, " C[$site]: ") - replace(io, sprint((x, y) -> show(x, mime, y), ψ.C[site]), "\n" => "\n" * charset.ver) - println(io) - end - print(io, charset.mid, charset.dash, " AL[$site]: ") - replace(io, sprint((x, y) -> show(x, mime, y), ψ.AL[site]), "\n" => "\n" * charset.ver) - println(io) - elseif site == half_screen_rows - println(io, charset.ver, " ⋮") - println(io, charset.ver) + half_screen_rows = limit ? div(displaysize(io)[1] - 6, 4) : typemax(Int) + L = length(ψ) + if L <= 2 * half_screen_rows # everything fits! + half_screen_rows = typemax(Int) + end + + println(io, "| ⋮") + println(io, "| ", right_virtualspace(ψ, L)) + for i in reverse(1:L) + if i > L - half_screen_rows || i < half_screen_rows + println(io, "├─[$i]─ ", physicalspace(ψ, i)) + println(io, "│ ", left_virtualspace(ψ, i)) + elseif i == half_screen_rows + println(io, "│ ⋮") + println(io, "│ ", left_virtualspace(ψ, i)) end end - println(io, charset.ver, " ⋮") + println(io, "| ⋮") return nothing end From b4b916d00d9e8bacf8fffab84dc52f17c1912453 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Thu, 6 Nov 2025 08:08:42 -0500 Subject: [PATCH 08/11] some reorganization --- src/MPSKit.jl | 3 +- src/operators/show.jl | 116 -------------------- src/states/finitemps.jl | 59 ---------- src/states/infinitemps.jl | 36 ------- src/utility/show.jl | 220 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 222 insertions(+), 212 deletions(-) delete mode 100644 src/operators/show.jl create mode 100644 src/utility/show.jl diff --git a/src/MPSKit.jl b/src/MPSKit.jl index a6c586144..e56e75088 100644 --- a/src/MPSKit.jl +++ b/src/MPSKit.jl @@ -123,7 +123,6 @@ include("operators/projection.jl") include("operators/timedependence.jl") include("operators/multipliedoperator.jl") include("operators/lazysum.jl") -include("operators/show.jl") include("transfermatrix/transfermatrix.jl") include("transfermatrix/transfer.jl") @@ -189,6 +188,8 @@ include("algorithms/ED.jl") include("algorithms/unionalg.jl") +include("utility/show.jl") + function __init__() Defaults.set_scheduler!() return nothing diff --git a/src/operators/show.jl b/src/operators/show.jl deleted file mode 100644 index c81c02bc7..000000000 --- a/src/operators/show.jl +++ /dev/null @@ -1,116 +0,0 @@ -# AbstractMPO -# ----------- - -function Base.summary(io::IO, mpo::AbstractMPO) - L = length(mpo) - D = maximum(dim, left_virtualspace(mpo)) - print(io, "$L-site $(typeof(mpo)) with maximal dimension $D") - return nothing -end - -function Base.show(io::IO, mime::MIME"text/plain", mpo::AbstractMPO) - summary(io, mpo) - - get(io, :compact, false)::Bool && return nothing - println(io, ":") - io = IOContext(io, :typeinfo => eltype(mpo)) - context = :compact => (get(io, :compact, false)::Bool) - - charset = (; top = "┬", bot = "┴", mid = "┼", ver = "│", dash = "──") - limit = get(io, :limit, false)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2 * 8) : typemax(Int) - L = length(mpo) - - # used to align all mposite infos regardless of the length of the mpo (100 takes up more space than 5) - npad = floor(Int, log10(L)) - mpoletter = mpo isa MPOHamiltonian ? "W" : "O" - isfinite = (mpo isa FiniteMPO) || (mpo isa FiniteMPOHamiltonian) - - !isfinite && println(io, "╷ ⋮") - for site in reverse(1:L) - if site < half_screen_rows || site > L - half_screen_rows - if site == L && isfinite - print( - io, charset.top, " $mpoletter[$site]: ", - repeat(" ", npad - floor(Int, log10(site))) - ) - replace(io, sprint((x, y) -> show(x, mime, y), mpo[site]; context), "\n" => "\n" * charset.ver) - println(io) - elseif (site == 1) && isfinite - print( - io, charset.bot, " $mpoletter[$site]: ", - repeat(" ", npad - floor(Int, log10(site))) - ) - replace(io, sprint((x, y) -> show(x, mime, y), mpo[site]; context), "\n" => "\n" * charset.ver) - println(io) - else - print( - io, charset.mid, " $mpoletter[$site]: ", - repeat(" ", npad - floor(Int, log10(site))) - ) - if site == 1 - show(io, mime, mpo[site]) - else - replace(io, sprint((x, y) -> show(x, mime, y), mpo[site]; context), "\n" => "\n" * charset.ver) - end - println(io) - end - elseif site == half_screen_rows - println(io, charset.ver) - println(io, charset.ver, " ⋮") - println(io, charset.ver) - end - end - !isfinite && println(io, "╵ ⋮") - return nothing -end - -# braille -# ------- -""" - braille(io::IO, H::Union{SparseMPO, MPOHamiltonian}) - braille(H::Union{SparseMPO, MPOHamiltonian}) - -Prints a compact, human-readable "braille" visualization of a sparseMPO or MPOHamiltonian. -Each site of the MPO is represented as a block of Unicode braille characters, with sites separated by dashes. -This visualization is useful for quickly inspecting the structure and sparsity pattern of MPOs. - -# Arguments -- `io::IO`: The output stream to print to (e.g., `stdout`). -- `H::Union{SparseMPO, MPOHamiltonian}`: The `SparseMPO` or `MPOHamiltonian` to visualize. - -If called without an `io` argument, output is printed to `stdout`. -""" -function braille(io::IO, H::Union{SparseMPO, MPOHamiltonian}) - 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(H)) ? ("... " * dash) : " ") - line *= (i > 1 && !isfinite(H)) ? " " : "" - 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(H)) ? (dash * " ...") : " ") - println(io, line) - end - return nothing -end - -braille(H::Union{SparseMPO, MPOHamiltonian}) = braille(stdout, H) diff --git a/src/states/finitemps.jl b/src/states/finitemps.jl index fe1500f6d..4c6b6a0c4 100644 --- a/src/states/finitemps.jl +++ b/src/states/finitemps.jl @@ -439,65 +439,6 @@ Compute the dimension of the maximal virtual space at a given site. """ max_Ds(ψ::FiniteMPS) = dim.(max_virtualspaces(ψ)) -function Base.summary(io::IO, ψ::FiniteMPS) - L = length(ψ) - D = maximum(dim, left_virtualspace(ψ)) - return print(io, "$L-site FiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ)))) maxdim: ", D, "\tcenter: ", ψ.center) -end -function Base.show(io::IO, ::MIME"text/plain", ψ::FiniteMPS) - summary(io, ψ) - get(io, :compact, false)::Bool && return nothing - - println(io, ":") - io = IOContext(io, :typeinfo => spacetype(ψ)) - - limit = get(io, :limit, true)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 2, 4) : typemax(Int) - L = length(ψ) - if L <= 2 * half_screen_rows # everything fits! - half_screen_rows = typemax(Int) - end - - # special handling of edge spaces => don't print if trivial - Vright = right_virtualspace(ψ, L) - right_trivial = Vright == oneunit(Vright) - Vleft = left_virtualspace(ψ, 1) - left_trivial = Vleft == oneunit(Vleft) - - - right_trivial || println(io, "│ ", Vright) - for i in reverse(1:L) - if i > L - half_screen_rows - if i == L - connector = right_trivial ? "┌" : "├" - println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) - elseif i == 1 - connector = left_trivial ? "└" : "├" - println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) - else - println(io, "├─[$i]─ ", physicalspace(ψ, i)) - end - - i != 1 && println(io, "│ ", left_virtualspace(ψ, i)) - elseif i == half_screen_rows - println(io, "│ ⋮") - elseif i < half_screen_rows - i != L && println(io, "│ ", right_virtualspace(ψ, i)) - if i == L - connector = right_trivial ? "┌" : "├" - println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) - elseif i == 1 - connector = left_trivial ? "└" : "├" - println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) - else - println(io, "├─[$i]─ ", physicalspace(ψ, i)) - end - end - end - left_trivial || println(io, "│ ", Vleft) - - return nothing -end #=========================================================================================== Linear Algebra diff --git a/src/states/infinitemps.jl b/src/states/infinitemps.jl index 8e16a4c10..989aa114b 100644 --- a/src/states/infinitemps.jl +++ b/src/states/infinitemps.jl @@ -311,42 +311,6 @@ function Base.isapprox(ψ₁::InfiniteMPS, ψ₂::InfiniteMPS; kwargs...) return isapprox(dot(ψ₁, ψ₂), 1; kwargs...) end -function Base.summary(io::IO, ψ::InfiniteMPS) - D = maximum(dim, left_virtualspace(ψ)) - L = length(ψ) - return print(io, "$L-site InfiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ)))) maxdim: ", D) -end - -function Base.show(io::IO, ::MIME"text/plain", ψ::InfiniteMPS) - summary(io, ψ) - get(io, :compact, false)::Bool && return nothing - - println(io, ":") - io = IOContext(io, :typeinfo => eltype(ψ)) - - limit = get(io, :limit, true)::Bool - half_screen_rows = limit ? div(displaysize(io)[1] - 6, 4) : typemax(Int) - L = length(ψ) - if L <= 2 * half_screen_rows # everything fits! - half_screen_rows = typemax(Int) - end - - println(io, "| ⋮") - println(io, "| ", right_virtualspace(ψ, L)) - for i in reverse(1:L) - if i > L - half_screen_rows || i < half_screen_rows - println(io, "├─[$i]─ ", physicalspace(ψ, i)) - println(io, "│ ", left_virtualspace(ψ, i)) - elseif i == half_screen_rows - println(io, "│ ⋮") - println(io, "│ ", left_virtualspace(ψ, i)) - end - end - println(io, "| ⋮") - - return nothing -end - #=========================================================================================== Fixedpoints ===========================================================================================# diff --git a/src/utility/show.jl b/src/utility/show.jl new file mode 100644 index 000000000..1ec0c8a1c --- /dev/null +++ b/src/utility/show.jl @@ -0,0 +1,220 @@ +function Base.summary(io::IO, ψ::FiniteMPS) + L = length(ψ) + D = maximum(dim, left_virtualspace(ψ)) + return print(io, "$L-site FiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ)))) maxdim = ", D, "\tcenter = ", ψ.center) +end + +for T in (:InfiniteMPS, :FiniteMPO, :InfiniteMPO, :FiniteMPOHamiltonian, :InfiniteMPOHamiltonian) + @eval function Base.summary(io::IO, mpo::$T) + L = length(mpo) + D = maximum(dim, left_virtualspace(mpo)) + T = scalartype(mpo) + S = TensorKit.type_repr(spacetype(mpo)) + print(io, L, "-site ", $(string(T)), "(", scalartype(mpo), ", ", S, ") maxdim = ", D) + return nothing + end +end + +function Base.show(io::IO, ::MIME"text/plain", ψ::FiniteMPS) + summary(io, ψ) + get(io, :compact, false)::Bool && return nothing + + println(io, ":") + io = IOContext(io, :typeinfo => spacetype(ψ)) + + limit = get(io, :limit, true)::Bool + half_screen_rows = limit ? div(displaysize(io)[1] - 2, 4) : typemax(Int) + L = length(ψ) + if L <= 2 * half_screen_rows # everything fits! + half_screen_rows = typemax(Int) + end + + # special handling of edge spaces => don't print if trivial + Vright = right_virtualspace(ψ, L) + right_trivial = Vright == oneunit(Vright) + Vleft = left_virtualspace(ψ, 1) + left_trivial = Vleft == oneunit(Vleft) + + + right_trivial || println(io, "│ ", Vright) + for i in reverse(1:L) + if i > L - half_screen_rows + if i == L + connector = right_trivial ? "┌" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) + elseif i == 1 + connector = left_trivial ? "└" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) + else + println(io, "├─[$i]─ ", physicalspace(ψ, i)) + end + + i != 1 && println(io, "│ ", left_virtualspace(ψ, i)) + elseif i == half_screen_rows + println(io, "│ ⋮") + elseif i < half_screen_rows + i != L && println(io, "│ ", right_virtualspace(ψ, i)) + if i == L + connector = right_trivial ? "┌" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) + elseif i == 1 + connector = left_trivial ? "└" : "├" + println(io, connector, "─[$i]─ ", physicalspace(ψ, i)) + else + println(io, "├─[$i]─ ", physicalspace(ψ, i)) + end + end + end + left_trivial || println(io, "│ ", Vleft) + + return nothing +end + +function Base.show(io::IO, ::MIME"text/plain", ψ::InfiniteMPS) + summary(io, ψ) + get(io, :compact, false)::Bool && return nothing + + println(io, ":") + io = IOContext(io, :typeinfo => spacetype(ψ)) + + limit = get(io, :limit, true)::Bool + half_screen_rows = limit ? div(displaysize(io)[1] - 6, 4) : typemax(Int) + L = length(ψ) + if L <= 2 * half_screen_rows # everything fits! + half_screen_rows = typemax(Int) + end + + println(io, "| ⋮") + println(io, "| ", right_virtualspace(ψ, L)) + for i in reverse(1:L) + if i > L - half_screen_rows || i < half_screen_rows + println(io, "├─[$i]─ ", physicalspace(ψ, i)) + println(io, "│ ", left_virtualspace(ψ, i)) + elseif i == half_screen_rows + println(io, "│ ⋮") + println(io, "│ ", left_virtualspace(ψ, i)) + end + end + println(io, "| ⋮") + + return nothing +end + +function Base.show(io::IO, ::MIME"text/plain", mpo::AbstractMPO) + summary(io, mpo) + get(io, :compact, false)::Bool && return nothing + + println(io, ":") + io = IOContext(io, :typeinfo => spacetype(mpo)) + + limit = get(io, :limit, true)::Bool + half_screen_rows = limit ? div(displaysize(io)[1] - 6, 4) : typemax(Int) + L = length(mpo) + if L <= 2 * half_screen_rows # everything fits! + half_screen_rows = typemax(Int) + end + + if isfinite(mpo) + # special handling of edge spaces => don't print if trivial + Vright = right_virtualspace(mpo, L) + right_trivial = Vright == oneunit(Vright) + Vleft = left_virtualspace(mpo, 1) + left_trivial = Vleft == oneunit(Vleft) + + right_trivial || println(io, "│ ", Vright) + for i in reverse(1:L) + if i > L - half_screen_rows + if i == L + connector = right_trivial ? "┬" : "┼" + println(io, connector, "─[$i]─ ", physicalspace(mpo, i)) + elseif i == 1 + connector = left_trivial ? "┴" : "┼" + println(io, connector, "─[$i]─ ", physicalspace(mpo, i)) + else + println(io, "┼─[$i]─ ", physicalspace(mpo, i)) + end + + i != 1 && println(io, "│ ", left_virtualspace(mpo, i)) + elseif i == half_screen_rows + println(io, "│ ⋮") + elseif i < half_screen_rows + i != L && println(io, "│ ", right_virtualspace(mpo, i)) + if i == L + connector = right_trivial ? "┬" : "┼" + println(io, connector, "─[$i]─ ", physicalspace(mpo, i)) + elseif i == 1 + connector = left_trivial ? "┴" : "┼" + println(io, connector, "─[$i]─ ", physicalspace(mpo, i)) + else + println(io, "┼─[$i]─ ", physicalspace(mpo, i)) + end + end + end + left_trivial || println(io, "│ ", Vleft) + else + println(io, "| ⋮") + println(io, "| ", right_virtualspace(mpo, L)) + for i in reverse(1:L) + if i > L - half_screen_rows || i < half_screen_rows + println(io, "┼─[$i]─ ", physicalspace(mpo, i)) + println(io, "│ ", left_virtualspace(mpo, i)) + elseif i == half_screen_rows + println(io, "│ ⋮") + println(io, "│ ", left_virtualspace(mpo, i)) + end + end + println(io, "| ⋮") + end + + return nothing +end + +# braille +# ------- +""" + braille(io::IO, H::Union{SparseMPO, MPOHamiltonian}) + braille(H::Union{SparseMPO, MPOHamiltonian}) + +Prints a compact, human-readable "braille" visualization of a sparseMPO or MPOHamiltonian. +Each site of the MPO is represented as a block of Unicode braille characters, with sites separated by dashes. +This visualization is useful for quickly inspecting the structure and sparsity pattern of MPOs. + +# Arguments +- `io::IO`: The output stream to print to (e.g., `stdout`). +- `H::Union{SparseMPO, MPOHamiltonian}`: The `SparseMPO` or `MPOHamiltonian` to visualize. + +If called without an `io` argument, output is printed to `stdout`. +""" +function braille(io::IO, H::Union{SparseMPO, MPOHamiltonian}) + 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(H)) ? ("... " * dash) : " ") + line *= (i > 1 && !isfinite(H)) ? " " : "" + 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(H)) ? (dash * " ...") : " ") + println(io, line) + end + return nothing +end + +braille(H::Union{SparseMPO, MPOHamiltonian}) = braille(stdout, H) From a3d6ccc1526bde0211b0ad9a1017de8b5e3df122 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Thu, 6 Nov 2025 08:59:15 -0500 Subject: [PATCH 09/11] Also fix environments --- src/environments/finite_envs.jl | 2 +- src/utility/show.jl | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/environments/finite_envs.jl b/src/environments/finite_envs.jl index 7f26c8ddf..6372f65ab 100644 --- a/src/environments/finite_envs.jl +++ b/src/environments/finite_envs.jl @@ -1,7 +1,7 @@ """ struct FiniteEnvironments <: AbstractMPSEnvironments -Environment manager for `FiniteMPS` and `WindowMPS`. This structure is responsable for automatically checking +Environment manager for `FiniteMPS` and `WindowMPS`. This structure is responsible for automatically checking if the queried environment is still correctly cached and if not recalculates. """ struct FiniteEnvironments{A, B, C, D} <: AbstractMPSEnvironments diff --git a/src/utility/show.jl b/src/utility/show.jl index 1ec0c8a1c..a1b1a37d2 100644 --- a/src/utility/show.jl +++ b/src/utility/show.jl @@ -169,6 +169,40 @@ function Base.show(io::IO, ::MIME"text/plain", mpo::AbstractMPO) return nothing end +function Base.showarg(io::IO, envs::FiniteEnvironments, toplevel::Bool) + print(io, "environments(state, ") + Base.showarg(io, envs.operator, false) + if isnothing(envs.above) + print(io, ")") + else + print(io, ", ") + Base.showarg(io, envs.above, false) + print(io, ")") + end + return nothing +end + +function Base.summary(io::IO, envs::Union{FiniteEnvironments, InfiniteEnvironments}) + print(io, length(envs.GLs), "-site ") + Base.showarg(io, envs, true) + return nothing +end + +function Base.show(io::IO, ::MIME"text/plain", envs::Union{InfiniteEnvironments, FiniteEnvironments}) + Base.summary(io, envs) + get(io, :compact, false)::Bool && return nothing + println(io, ":") + + for (i, gl) in enumerate(envs.GLs) + println(io, "GL[$i]: ", space(gl)) + end + for (i, gr) in enumerate(envs.GRs) + println(io, "GR[$i]: ", space(gr)) + end + + return nothing +end + # braille # ------- """ From 1aadc586b917df762096eccc00b7254edb515b49 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Thu, 6 Nov 2025 08:59:35 -0500 Subject: [PATCH 10/11] export JordanMPO + type alias to shorten printing --- src/MPSKit.jl | 1 + src/operators/jordanmpotensor.jl | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/MPSKit.jl b/src/MPSKit.jl index e56e75088..8e96d607d 100644 --- a/src/MPSKit.jl +++ b/src/MPSKit.jl @@ -18,6 +18,7 @@ export QP, LeftGaugedQP, RightGaugedQP # operators: export AbstractMPO export MPO, FiniteMPO, InfiniteMPO +export JordanMPOTensor, JordanMPOTensorMap export MPOHamiltonian, FiniteMPOHamiltonian, InfiniteMPOHamiltonian export MultilineMPO export UntimedOperator, TimedOperator, MultipliedOperator, LazySum diff --git a/src/operators/jordanmpotensor.jl b/src/operators/jordanmpotensor.jl index 80be3dea1..4a3dbe798 100644 --- a/src/operators/jordanmpotensor.jl +++ b/src/operators/jordanmpotensor.jl @@ -58,6 +58,14 @@ struct JordanMPOTensor{ end end +const JordanMPOTensorMap{T, S, A <: DenseVector{T}} = JordanMPOTensor{ + T, S, + Union{TensorMap{T, S, 2, 2, A}, BraidingTensor{T, S}}, + TensorMap{T, S, 2, 1, A}, + TensorMap{T, S, 1, 2, A}, + TensorMap{T, S, 1, 1, A}, +} + function JordanMPOTensor{E, S}(::UndefInitializer, V::TensorMapSumSpace{S}) where {E, S} return jordanmpotensortype(S, E)(undef, V) end From 94e8a36fdea66d744b4b1f151dd4e84dd04cbfca Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Thu, 6 Nov 2025 11:06:16 -0500 Subject: [PATCH 11/11] address comments --- src/utility/show.jl | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/utility/show.jl b/src/utility/show.jl index a1b1a37d2..bd132dd6c 100644 --- a/src/utility/show.jl +++ b/src/utility/show.jl @@ -1,16 +1,11 @@ -function Base.summary(io::IO, ψ::FiniteMPS) - L = length(ψ) - D = maximum(dim, left_virtualspace(ψ)) - return print(io, "$L-site FiniteMPS ($(scalartype(ψ)), $(TensorKit.type_repr(spacetype(ψ)))) maxdim = ", D, "\tcenter = ", ψ.center) -end - -for T in (:InfiniteMPS, :FiniteMPO, :InfiniteMPO, :FiniteMPOHamiltonian, :InfiniteMPOHamiltonian) - @eval function Base.summary(io::IO, mpo::$T) - L = length(mpo) - D = maximum(dim, left_virtualspace(mpo)) - T = scalartype(mpo) - S = TensorKit.type_repr(spacetype(mpo)) - print(io, L, "-site ", $(string(T)), "(", scalartype(mpo), ", ", S, ") maxdim = ", D) +for T in (:FiniteMPS, :InfiniteMPS, :FiniteMPO, :InfiniteMPO, :FiniteMPOHamiltonian, :InfiniteMPOHamiltonian) + @eval function Base.summary(io::IO, x::$T) + L = length(x) + D = maximum(dim, left_virtualspace(x)) + E = scalartype(x) + S = TensorKit.type_repr(spacetype(x)) + print(io, L, "-site ", $(string(T)), "(", E, ", ", S, ") with maximal dimension ", D) + $(T === :FiniteMPS) && print(io, " and center ", x.center) return nothing end end @@ -169,19 +164,6 @@ function Base.show(io::IO, ::MIME"text/plain", mpo::AbstractMPO) return nothing end -function Base.showarg(io::IO, envs::FiniteEnvironments, toplevel::Bool) - print(io, "environments(state, ") - Base.showarg(io, envs.operator, false) - if isnothing(envs.above) - print(io, ")") - else - print(io, ", ") - Base.showarg(io, envs.above, false) - print(io, ")") - end - return nothing -end - function Base.summary(io::IO, envs::Union{FiniteEnvironments, InfiniteEnvironments}) print(io, length(envs.GLs), "-site ") Base.showarg(io, envs, true) @@ -193,11 +175,11 @@ function Base.show(io::IO, ::MIME"text/plain", envs::Union{InfiniteEnvironments, get(io, :compact, false)::Bool && return nothing println(io, ":") - for (i, gl) in enumerate(envs.GLs) - println(io, "GL[$i]: ", space(gl)) + for i in reverse(eachindex(envs.GLs)) + println(io, "GL[$i]: ", space(envs.GLs[i])) end - for (i, gr) in enumerate(envs.GRs) - println(io, "GR[$i]: ", space(gr)) + for i in reverse(eachindex(envs.GRs)) + println(io, "GR[$i]: ", space(envs.GRs[i])) end return nothing