Skip to content

Commit f8dd69f

Browse files
authored
Fix show for finite multifusion MPS/MPOs (#538)
1 parent 08ffba4 commit f8dd69f

11 files changed

Lines changed: 19 additions & 18 deletions

File tree

‎benchmark/MPSKitBenchmarks/scripts/setup_heisenberg.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function initial_state(H)
2323
@assert allequal(physicalspace(H))
2424

2525
pspace = physicalspace(H, 1)
26-
A = rand(oneunit(pspace) ⊗ pspace^2 ← oneunit(pspace))
26+
A = rand(unitspace(pspace) ⊗ pspace^2 ← unitspace(pspace))
2727
As = MPSKit.decompose_localmps(A)
2828
return FiniteMPS(repeat(As, length(H) ÷ 2))
2929
end

‎docs/src/changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
3434
### Fixed
3535

3636
- `convert(TensorMap, H)` for single-site `FiniteMPOHamiltonian`s no longer contracts the site tensor with itself. ([#252](https://github.com/QuantumKitHub/MPSKit.jl/pull/252))
37+
- `show` methods for finite MPS/MPOs no longer check unit space condition through `oneunit`, which is not defined for multifusion spaces. ([#538](https://github.com/QuantumKitHub/MPSKit.jl/pull/538))
3738

3839
### Performance
3940

‎docs/src/examples/quantum1d/6.hubbard/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ charges = fill(FermionParity(1) ⊠ U1Irrep(1) ⊠ SU2Irrep(0), 2);
184184
H_u1_su2 = MPSKit.add_physical_charge(H_u1_su2, charges);
185185

186186
pspaces = physicalspace.(Ref(H_u1_su2), 1:2)
187-
vspaces = [oneunit(eltype(pspaces)), first(pspaces)]
187+
vspaces = [unitspace(eltype(pspaces)), first(pspaces)]
188188
psi = InfiniteMPS(pspaces, vspaces)
189189
psi = compute_groundstate(psi, H_u1_su2; expansionfactor = 1 / 3)
190190
E = real(expectation_value(psi, H_u1_su2)) / 2

‎docs/src/examples/quantum1d/6.hubbard/main.ipynb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
"H_u1_su2 = MPSKit.add_physical_charge(H_u1_su2, charges);\n",
262262
"\n",
263263
"pspaces = physicalspace.(Ref(H_u1_su2), 1:2)\n",
264-
"vspaces = [oneunit(eltype(pspaces)), first(pspaces)]\n",
264+
"vspaces = [unitspace(eltype(pspaces)), first(pspaces)]\n",
265265
"psi = InfiniteMPS(pspaces, vspaces)\n",
266266
"psi = compute_groundstate(psi, H_u1_su2; expansionfactor = 1 / 3)\n",
267267
"E = real(expectation_value(psi, H_u1_su2)) / 2\n",
@@ -499,4 +499,4 @@
499499
},
500500
"nbformat": 4,
501501
"nbformat_minor": 3
502-
}
502+
}

‎examples/quantum1d/6.hubbard/main.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ charges = fill(FermionParity(1) ⊠ U1Irrep(1) ⊠ SU2Irrep(0), 2);
122122
H_u1_su2 = MPSKit.add_physical_charge(H_u1_su2, charges);
123123

124124
pspaces = physicalspace.(Ref(H_u1_su2), 1:2)
125-
vspaces = [oneunit(eltype(pspaces)), first(pspaces)]
125+
vspaces = [unitspace(eltype(pspaces)), first(pspaces)]
126126
psi = InfiniteMPS(pspaces, vspaces)
127127
psi = compute_groundstate(psi, H_u1_su2; expansionfactor = 1 / 3)
128128
E = real(expectation_value(psi, H_u1_su2)) / 2

‎src/algorithms/timestep/clusterexpansion.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ end
9595

9696
function exponentiate_onsite_tensor(ham_tensor, τ, ::Type{A}) where {A}
9797
physical_space = physicalspace(ham_tensor)
98-
levels = ⊞(oneunit(physical_space))
98+
levels = ⊞(rightunitspace(physical_space))
9999
blocktype = tensormaptype(spacetype(physical_space), 2, 2, A)
100100
tensor = SparseBlockTensorMap{blocktype}(undef, levels ⊗ physical_space ← physical_space ⊗ levels)
101101
onsite = removeunit(removeunit(ham_tensor[1, 1, 1, end], 4), 1)

‎src/utility/show.jl‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ function Base.show(io::IO, ::MIME"text/plain", ψ::FiniteMPS)
3636

3737
# special handling of edge spaces => don't print if trivial
3838
Vright = right_virtualspace(ψ, L)
39-
right_trivial = Vright == oneunit(Vright)
39+
right_trivial = isunitspace(Vright)
4040
Vleft = left_virtualspace(ψ, 1)
41-
left_trivial = Vleft == oneunit(Vleft)
41+
left_trivial = isunitspace(Vleft)
4242

4343

4444
right_trivial || println(io, "│ ", Vright)
@@ -122,9 +122,9 @@ function Base.show(io::IO, ::MIME"text/plain", mpo::AbstractMPO)
122122
if isfinite(mpo)
123123
# special handling of edge spaces => don't print if trivial
124124
Vright = right_virtualspace(mpo, L)
125-
right_trivial = Vright == oneunit(Vright)
125+
right_trivial = isunitspace(Vright)
126126
Vleft = left_virtualspace(mpo, 1)
127-
left_trivial = Vleft == oneunit(Vleft)
127+
left_trivial = isunitspace(Vleft)
128128

129129
right_trivial || println(io, "│ ", Vright)
130130
for i in reverse(1:L)

‎test/algorithms/changebonds.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ end
113113
H = kitaev_model(ComplexF64, Trivial; t = 1.0, mu = 0, Delta = 0, L = L)
114114
P = physicalspace(H)[1]
115115
S = typeof(P)
116-
Vtriv = oneunit(P)
116+
Vtriv = unitspace(P)
117117
Vodd = S(c => dim(P, c) for c in sectors(P) if !isone(c))
118118
# single particle created on the last site: interior bonds carry only the even sector, so
119119
# the expansion content on them is exactly zero

‎test/groundstate/approximate.jl‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
function _random_mpo_mps(pspace, Dspace, L; elt = ComplexF64)
2424
Random.seed!(1357)
2525
Wspace = Dspace
26-
Vspaces = [oneunit(Wspace); fill(Wspace, L - 1); oneunit(Wspace)]
26+
Vspaces = [unitspace(Wspace); fill(Wspace, L - 1); unitspace(Wspace)]
2727
O = FiniteMPO(
2828
[rand(ComplexF64, Vspaces[i] ⊗ pspace ← pspace ⊗ Vspaces[i + 1]) for i in 1:L]
2929
)
@@ -211,7 +211,7 @@ end
211211
@test info.truncation_errors ≈ info_ref.truncation_errors
212212

213213
# a destination with unrelated contents is overwritten entirely
214-
dst = FiniteMPS(rand, ComplexF64, length(ψ), pspace, oneunit(Dspace) ⊕ Dspace ⊕ Dspace)
214+
dst = FiniteMPS(rand, ComplexF64, length(ψ), pspace, unitspace(Dspace) ⊕ Dspace ⊕ Dspace)
215215
got, info = approximate!(dst, (O, ψ), alg)
216216
@test norm(ref - got) / norm(ref) < 1.0e-12
217217
@test info.truncation_errors ≈ info_ref.truncation_errors
@@ -248,8 +248,8 @@ end
248248
@testset "Zip-up with non-square MPO $(spacetype(pspace))" for (pspace, Dspace, _) in zipup_spacelist
249249
Random.seed!(1357)
250250
L = 4
251-
pspace′ = pspace ⊕ oneunit(pspace) # output physical space, different from the input one
252-
Vspaces = [oneunit(Dspace); fill(Dspace, L - 1); oneunit(Dspace)]
251+
pspace′ = pspace ⊕ unitspace(pspace) # output physical space, different from the input one
252+
Vspaces = [unitspace(Dspace); fill(Dspace, L - 1); unitspace(Dspace)]
253253
O = FiniteMPO(
254254
[rand(ComplexF64, Vspaces[i] ⊗ pspace′ ← pspace ⊗ Vspaces[i + 1]) for i in 1:L]
255255
)

‎test/hamiltonian/mixed.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Ts = fast_tests ? (Float64,) : (Float64, ComplexF64)
9191
((i, i + 2) => h for i in 1:(L - 2))...,
9292
((i, i + 3) => h for i in 1:(L - 3))...,
9393
)
94-
mps1 = FiniteMPS(physicalspace(H1), oneunit(V))
94+
mps1 = FiniteMPS(physicalspace(H1), unitspace(V))
9595

9696
for T in Ts
9797
H2 = if VERSION <= v"1.12"
@@ -106,7 +106,7 @@ Ts = fast_tests ? (Float64,) : (Float64, ComplexF64)
106106
end
107107

108108
H3 = InfiniteMPOHamiltonian(fill(V, L), (1, 2) => h, (1, 3) => h, (1, 4) => h)
109-
mps2 = InfiniteMPS(physicalspace(H3), [oneunit(V)])
109+
mps2 = InfiniteMPS(physicalspace(H3), [unitspace(V)])
110110
for T in Ts
111111
H4 = if VERSION <= v"1.12"
112112
# this is type unstable for LTS for some reason

0 commit comments

Comments
 (0)