Skip to content

Conversation

@lkdvos
Copy link
Member

@lkdvos lkdvos commented Oct 31, 2025

Some modifications to make sure everything is printing as it should be.

Examples:

Details
julia> psi = repeat(InfiniteMPS(2, 12), 2)
2-site InfiniteMPS(ComplexF64, ComplexSpace) with maximal dimension 12:
| 
|^12
├─[2]─ ℂ^2
│ ℂ^12
├─[1]─ ℂ^2
│ ℂ^12
| 


julia> H = repeat(InfiniteMPOHamiltonian(rand(ℂ^2^2, ℂ^2^2)), 2)
2-site InfiniteMPOHamiltonian(Float64, ComplexSpace) with maximal dimension 6:
| 
| (ℂ^1 ^4 ^1)
┼─[2]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[1]─ ℂ^2
│ (ℂ^1 ^4 ^1)
| 


julia> environments(psi, H)
2-site MPSKit.InfiniteEnvironments{BlockTensorKit.BlockTensorMap{TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, ComplexF64, ComplexSpace, 2, 1, 3}}:
GL[2]: ((ℂ^12)  ((ℂ^1)'  (ℂ^4)'  (ℂ^1)'))  (ℂ^12)
GL[1]: ((ℂ^12)  ((ℂ^1)'  (ℂ^4)'  (ℂ^1)'))  (ℂ^12)
GR[2]: ((ℂ^12)  (ℂ^1 ^4 ^1))  (ℂ^12)
GR[1]: ((ℂ^12)  (ℂ^1 ^4 ^1))  (ℂ^12)


julia> psi = FiniteMPS(6, ℂ^2, ℂ^4)
6-site FiniteMPS(ComplexF64, ComplexSpace) with maximal dimension 4 and center 13/2:
┌─[6]─ ℂ^2
│ ℂ^2
├─[5]─ ℂ^2
│ ℂ^4
├─[4]─ ℂ^2
│ ℂ^4
├─[3]─ ℂ^2
│ ℂ^4
├─[2]─ ℂ^2
│ ℂ^2
└─[1]─ ℂ^2


julia> H = open_boundary_conditions(H, length(psi))
6-site FiniteMPOHamiltonian(Float64, ComplexSpace) with maximal dimension 6:
┬─[6]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[5]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[4]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[3]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[2]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┴─[1]─ ℂ^2


julia> environments(psi, H)
7-site MPSKit.FiniteEnvironments{Nothing, FiniteMPOHamiltonian{JordanMPOTensorMap{Float64, ComplexSpace, Vector{Float64}}}, TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, BlockTensorKit.BlockTensorMap{TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, ComplexF64, ComplexSpace, 2, 1, 3}}:
GL[7]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[6]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[5]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[4]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[3]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[2]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[1]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GR[7]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[6]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[5]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[4]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[3]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[2]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[1]: ((ℂ^1)  (ℂ^1))  (ℂ^1)

@lkdvos lkdvos requested a review from VictorVanthilt October 31, 2025 14:11
@VictorVanthilt
Copy link
Member

I liked the old summary(TensorMap) so much more in this case:

10-site FiniteMPS (ComplexF64, ComplexSpace):
┌ C[10]: TensorMap(ℂ^1 ^1)
├── AL[10]: TensorMap((ℂ^2 ^2) ^1)
├── AL[9]: TensorMap((ℂ^4 ^2) ^2)
├── AL[8]: TensorMap((ℂ^8 ^2) ^4)
├── AL[7]: TensorMap((ℂ^16 ^2) ^8)
├── AL[6]: TensorMap((ℂ^32 ^2) ^16)
├── AL[5]: TensorMap((ℂ^16 ^2) ^32)
├── AL[4]: TensorMap((ℂ^8 ^2) ^16)
├── AL[3]: TensorMap((ℂ^4 ^2) ^8)
├── AL[2]: TensorMap((ℂ^2 ^2) ^4)
└── AL[1]: TensorMap((ℂ^1 ^2) ^2)

Way more concise :/

@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 14.54545% with 141 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/utility/show.jl 15.09% 135 Missing ⚠️
src/operators/jordanmpotensor.jl 0.00% 6 Missing ⚠️
Files with missing lines Coverage Δ
src/MPSKit.jl 100.00% <ø> (ø)
src/environments/finite_envs.jl 100.00% <ø> (ø)
src/states/finitemps.jl 94.20% <ø> (+12.05%) ⬆️
src/states/infinitemps.jl 76.11% <ø> (+11.56%) ⬆️
src/operators/jordanmpotensor.jl 84.11% <0.00%> (+1.16%) ⬆️
src/utility/show.jl 15.09% <15.09%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos
Copy link
Member Author

lkdvos commented Oct 31, 2025

Unfortunately, the new domain and codomain printing is hard to turn off, as we missed to not use any newlines in the show(io, MIME"text/plain", ::AbstractTensorMap) implementation when get(io, :compact) == true. I can try and update this later, but could use some help...

@Jutho
Copy link
Member

Jutho commented Oct 31, 2025

I didn't realise the domain and codomain suggestion was going to show up in showing the MPS. In that case, I would not have proposed it. It is indeed an oversight that we do now not even have a difference in showing tensors with and without :compact=>true.

@lkdvos
Copy link
Member Author

lkdvos commented Nov 6, 2025

Some updated suggestions:

Details

Here I've more or less restored the old approach by simply printing spaces instead:

julia> psi = FiniteMPS(5, ℂ^2, ℂ^10)
5-site FiniteMPS (ComplexF64, ComplexSpace) with maximal dimension 4:
┌ C[5]:^1 ^1
┌── AL[5]: (ℂ^2 ^2) ^1
├── AL[4]: (ℂ^4 ^2) ^2
├── AL[3]: (ℂ^4 ^2) ^4
├── AL[2]: (ℂ^2 ^2) ^4
└── AL[1]: (ℂ^1 ^2) ^2

Here I've condensed everything even further, avoiding printing the same virtualspace twice

julia> psi = FiniteMPS(40, ℂ^2, ℂ^50)
40-site FiniteMPS (ComplexF64, ComplexSpace) with center 81/2:
┌─[40]─ ℂ^2
│ ℂ^2
├─[39]─ ℂ^2
│ ℂ^4
├─[38]─ ℂ^2
│ ℂ^8
├─[37]─ ℂ^2
│ ℂ^16
├─[36]─ ℂ^2
│ ℂ^32
├─[35]─ ℂ^2
│ ℂ^50
├─[34]─ ℂ^2
│ ℂ^50
├─[33]─ ℂ^2
│ ℂ^50
├─[32]─ ℂ^2
│ ℂ^50
├─[31]─ ℂ^2
│ ℂ^50
├─[30]─ ℂ^2
│ ℂ^50
├─[29]─ ℂ^2
│ ℂ^50
├─[11]─ ℂ^2
│ ℂ^50
├─[10]─ ℂ^2
│ ℂ^50
├─[9]─ ℂ^2
│ ℂ^50
├─[8]─ ℂ^2
│ ℂ^50
├─[7]─ ℂ^2
│ ℂ^50
├─[6]─ ℂ^2
│ ℂ^32
├─[5]─ ℂ^2
│ ℂ^16
├─[4]─ ℂ^2
│ ℂ^8
├─[3]─ ℂ^2
│ ℂ^4
├─[2]─ ℂ^2
│ ℂ^2
└─[1]─ ℂ^2

julia> psi = FiniteMPS(40, SU2Space(1 => 1), SU2Space(i => 10 for i in 0:5))
40-site FiniteMPS (ComplexF64, Rep[SU₂]) with center 81/2:
┌─[40]─ (1=>1)
│ (1=>1)
├─[39]─ (1=>1)
│ (0=>1, 1=>1, 2=>1)
├─[38]─ (1=>1)
│ (0=>1, 1=>3, 2=>2, 3=>1)
├─[37]─ (1=>1)
│ (0=>3, 1=>6, 2=>6, 3=>3, 4=>1)
├─[36]─ (1=>1)
│ (0=>6, 1=>10, 2=>10, 3=>10, 4=>4, 5=>1)
├─[35]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>5)
├─[34]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[33]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[32]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[31]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[30]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[29]─ (1=>1)
│ 
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[11]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[10]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[9]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[8]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>10)
├─[7]─ (1=>1)
│ (0=>10, 1=>10, 2=>10, 3=>10, 4=>10, 5=>5)
├─[6]─ (1=>1)
│ (0=>6, 1=>10, 2=>10, 3=>10, 4=>4, 5=>1)
├─[5]─ (1=>1)
│ (0=>3, 1=>6, 2=>6, 3=>3, 4=>1)
├─[4]─ (1=>1)
│ (0=>1, 1=>3, 2=>2, 3=>1)
├─[3]─ (1=>1)
│ (0=>1, 1=>1, 2=>1)
├─[2]─ (1=>1)
│ (1=>1)
└─[1]─ (1=>1)

I quite like the last approach since I always had a hard time parsing the spaces, but it might not be super obvious what everything is anymore...
Let me know what you think, at least the code is simplifying 🙃

@VictorVanthilt
Copy link
Member

I like these examples very much. The last 2 are indeed way more clear, I do like the maximal dimension note shown in the first example.

@lkdvos
Copy link
Member Author

lkdvos commented Nov 6, 2025

Some (hopefully) final changes:

Details
julia> psi = repeat(InfiniteMPS(2, 12), 2)
2-site InfiniteMPS(ComplexF64, ComplexSpace) maxdim = 12:
| 
│ ℂ^12
├─[2]─ ℂ^2
│ ℂ^12
├─[1]─ ℂ^2
│ ℂ^12
| 

julia> H = repeat(InfiniteMPOHamiltonian(rand(ℂ^2^2, ℂ^2^2)), 2)
2-site InfiniteMPOHamiltonian(Float64, ComplexSpace) maxdim = 6:
| 
| (ℂ^1 ^4 ^1)
┼─[2]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[1]─ ℂ^2
│ (ℂ^1 ^4 ^1)
| 

julia> environments(psi, H)
2-site MPSKit.InfiniteEnvironments{BlockTensorKit.BlockTensorMap{TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, ComplexF64, ComplexSpace, 2, 1, 3}}:
GL[1]: ((ℂ^12)  ((ℂ^1)'  (ℂ^4)'  (ℂ^1)'))  (ℂ^12)
GL[2]: ((ℂ^12)  ((ℂ^1)'  (ℂ^4)'  (ℂ^1)'))  (ℂ^12)
GR[1]: ((ℂ^12)  (ℂ^1 ^4 ^1))  (ℂ^12)
GR[2]: ((ℂ^12)  (ℂ^1 ^4 ^1))  (ℂ^12)

julia> psi = FiniteMPS(6, ℂ^2, ℂ^4)
6-site FiniteMPS (ComplexF64, ComplexSpace) maxdim = 4  center = 13/2:
┌─[6]─ ℂ^2
│ ℂ^2
├─[5]─ ℂ^2
│ ℂ^4
├─[4]─ ℂ^2
│ ℂ^4
├─[3]─ ℂ^2
│ ℂ^4
├─[2]─ ℂ^2
│ ℂ^2
└─[1]─ ℂ^2

julia> H = open_boundary_conditions(H, length(psi))
6-site FiniteMPOHamiltonian(Float64, ComplexSpace) maxdim = 6:
┬─[6]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[5]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[4]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[3]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[2]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┴─[1]─ ℂ^2

julia> environments(psi, H)
7-site environments(state, ::FiniteMPOHamiltonian{JordanMPOTensorMap{Float64, ComplexSpace, Vector{Float64}}}):
GL[1]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[2]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[3]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[4]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[5]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[6]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[7]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GR[1]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[2]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[3]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[4]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[5]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[6]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[7]: ((ℂ^1)  (ℂ^1))  (ℂ^1)

@VictorVanthilt
Copy link
Member

Magnificent. Never thought i'd see the day where environments would be pretty printed :)

@lkdvos lkdvos requested a review from leburgel November 6, 2025 14:16
@leburgel
Copy link
Member

leburgel commented Nov 6, 2025

  • I don't really like 'maxdim'. I would prefer 'with maximal dimension = ..., center = ...', and actually even 'with maximal bond dimension ... and center ...', but the latter might be a bit long.
  • It's a bit strange that the operators and states are read bottom-to-top but the environments are read top-to-bottom. Given that we (at least I think) always have a left-to-right MPS with downward facing physical legs in mind, I prefer the bottom-to-top reading of the states and operators so I can tilt (quite literally) my head left and see the MPS of MPO I expect. So I would prefer to also show environments with site indices increasing bottom-to-top, so I can always tilt my head in the same direction.
  • The type printing for the finite environment is a bit weird compared to all the others: 7-site environments(state, ...) versus 2-site MPSKit.InfiniteEnvironments{...}. The type signature of the infinite one is a bit long (but doesn't really bother much I think). But the absence of a type for the finite environment really seems a bit off to me.

@leburgel
Copy link
Member

leburgel commented Nov 6, 2025

Also this one seems off to me, the virtual space being constant across the sites, and especially not matching the virtual space of the finite state or Hamiltonian above doesn't seem right?

julia> environments(psi, H)
7-site environments(state, ::FiniteMPOHamiltonian{JordanMPOTensorMap{Float64, ComplexSpace, Vector{Float64}}}):
GL[1]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GL[2]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GL[3]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GL[4]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GL[5]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GL[6]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GL[7]: (⊞(ℂ^1) ⊗ ⊞((ℂ^1)')) ← ⊞(ℂ^1)
GR[1]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)
GR[2]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)
GR[3]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)
GR[4]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)
GR[5]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)
GR[6]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)
GR[7]: (⊞(ℂ^1) ⊗ ⊞(ℂ^1)) ← ⊞(ℂ^1)

@lkdvos
Copy link
Member Author

lkdvos commented Nov 6, 2025

The spaces not matching is because environments(state, H) just puts dummy tensors there until you actually compute something, since the environments are actually a lazy representation.
The problem is that I don't actually know which environments are still valid until I start comparing with a state, so I can't use that information to print only the valid ones.

I think I've addressed the other comments.

Details
julia> psi = repeat(InfiniteMPS(2, 12), 2)
2-site InfiniteMPS(ComplexF64, ComplexSpace) with maximal dimension 12:
| 
|^12
├─[2]─ ℂ^2
│ ℂ^12
├─[1]─ ℂ^2
│ ℂ^12
| 


julia> H = repeat(InfiniteMPOHamiltonian(rand(ℂ^2^2, ℂ^2^2)), 2)
2-site InfiniteMPOHamiltonian(Float64, ComplexSpace) with maximal dimension 6:
| 
| (ℂ^1 ^4 ^1)
┼─[2]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[1]─ ℂ^2
│ (ℂ^1 ^4 ^1)
| 


julia> environments(psi, H)
2-site MPSKit.InfiniteEnvironments{BlockTensorKit.BlockTensorMap{TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, ComplexF64, ComplexSpace, 2, 1, 3}}:
GL[2]: ((ℂ^12)  ((ℂ^1)'  (ℂ^4)'  (ℂ^1)'))  (ℂ^12)
GL[1]: ((ℂ^12)  ((ℂ^1)'  (ℂ^4)'  (ℂ^1)'))  (ℂ^12)
GR[2]: ((ℂ^12)  (ℂ^1 ^4 ^1))  (ℂ^12)
GR[1]: ((ℂ^12)  (ℂ^1 ^4 ^1))  (ℂ^12)


julia> psi = FiniteMPS(6, ℂ^2, ℂ^4)
6-site FiniteMPS(ComplexF64, ComplexSpace) with maximal dimension 4 and center 13/2:
┌─[6]─ ℂ^2
│ ℂ^2
├─[5]─ ℂ^2
│ ℂ^4
├─[4]─ ℂ^2
│ ℂ^4
├─[3]─ ℂ^2
│ ℂ^4
├─[2]─ ℂ^2
│ ℂ^2
└─[1]─ ℂ^2


julia> H = open_boundary_conditions(H, length(psi))
6-site FiniteMPOHamiltonian(Float64, ComplexSpace) with maximal dimension 6:
┬─[6]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[5]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[4]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[3]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┼─[2]─ ℂ^2
│ (ℂ^1 ^4 ^1)
┴─[1]─ ℂ^2


julia> environments(psi, H)
7-site MPSKit.FiniteEnvironments{Nothing, FiniteMPOHamiltonian{JordanMPOTensorMap{Float64, ComplexSpace, Vector{Float64}}}, TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, BlockTensorKit.BlockTensorMap{TensorMap{ComplexF64, ComplexSpace, 2, 1, Vector{ComplexF64}}, ComplexF64, ComplexSpace, 2, 1, 3}}:
GL[7]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[6]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[5]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[4]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[3]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[2]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GL[1]: ((ℂ^1)  ((ℂ^1)'))  (ℂ^1)
GR[7]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[6]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[5]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[4]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[3]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[2]: ((ℂ^1)  (ℂ^1))  (ℂ^1)
GR[1]: ((ℂ^1)  (ℂ^1))  (ℂ^1)

@lkdvos lkdvos enabled auto-merge (squash) November 6, 2025 16:56
@lkdvos lkdvos merged commit aae67b5 into main Nov 6, 2025
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants