@@ -81,29 +81,18 @@ If the bond dimension of a SubDomainMPS exceeds `maxdim`, perform patching.
8181function adaptive_patching (
8282 subdmps:: SubDomainMPS , patchorder; cutoff= 0.0 , maxdim= typemax (Int)
8383):: Vector{SubDomainMPS}
84- if maxbonddim (subdmps) <= maxdim
84+ prjidx = _next_projindex (subdmps. projector, patchorder)
85+ if maxbonddim (subdmps) <= maxdim || prjidx === nothing
8586 return [subdmps]
8687 end
8788
88- # If the bond dimension exceeds maxdim, perform patching
89- refined_subdmpss = SubDomainMPS[]
90- nextprjidx = _next_projindex (subdmps. projector, patchorder)
91- if nextprjidx === nothing
92- return [subdmps]
93- end
94-
95- for prjval in 1 : ITensors. dim (nextprjidx)
96- prj_ = subdmps. projector & Projector (nextprjidx => prjval)
97- subdmps_ = truncate (project (subdmps, prj_); cutoff, maxdim)
98- if maxbonddim (subdmps_) <= maxdim
99- push! (refined_subdmpss, subdmps_)
100- else
101- append! (
102- refined_subdmpss, adaptive_patching (subdmps_, patchorder; cutoff, maxdim)
103- )
104- end
89+ # The bond dimension exceeds maxdim and there's an index to be projected, so perform patching
90+ prjvals = 1 : ITensors. dim (prjidx)
91+ return mapreduce (vcat, prjvals) do prjval
92+ prj_ = subdmps. projector & Projector (prjidx => prjval)
93+ subdmps_ = truncate (project (subdmps, prj_); cutoff)
94+ adaptive_patching (subdmps_, patchorder; cutoff, maxdim)
10595 end
106- return refined_subdmpss
10796end
10897
10998"""
@@ -113,14 +102,14 @@ Do patching recursively to reduce the bond dimension.
113102If the bond dimension of a SubDomainMPS exceeds `maxdim`, perform patching.
114103"""
115104function adaptive_patching (
116- prjmpss :: PartitionedMPS , patchorder; cutoff= 0.0 , maxdim= typemax (Int)
105+ prjmps :: PartitionedMPS , patchorder; cutoff= 0.0 , maxdim= typemax (Int)
117106):: PartitionedMPS
118107 return PartitionedMPS (
119108 collect (
120- Iterators. flatten ((
121- apdaptive_patching (prjmps ; cutoff, maxdim, patchorder ) for
122- prjmps in values (prjmpss )
123- )) ,
109+ Iterators. flatten (
110+ adaptive_patching (subdmps, patchorder ; cutoff, maxdim) for
111+ subdmps in values (prjmps )
112+ ),
124113 ),
125114 )
126115end
0 commit comments