@@ -31,37 +31,22 @@ struct CTMRGEnv{C, T}
3131 edges:: Array{T, 3}
3232end
3333
34- const ProductSpaceLike{N} = Union{
35- NTuple{N, Int}, NTuple{N, <: ElementarySpace }, ProductSpace{<: ElementarySpace , N},
36- }
37- const SpaceLike = Union{ElementarySpaceLike, ProductSpaceLike}
38-
39- _elementwise_dual (s:: NTuple{N, <:ElementarySpace} ) where {N} = dual .(s)
40-
41- _spacetype (:: Int ) = ComplexSpace
42- _spacetype (:: S ) where {S <: ElementarySpace } = S
43- _spacetype (s:: ProductSpaceLike ) = _spacetype (first (s))
44-
45- _to_space (χ:: Int ) = ℂ^ χ
46- _to_space (χ:: ElementarySpace ) = χ
47- _to_space (χ:: ProductSpaceLike ) = prod (_to_space, χ)
48-
4934function _corner_tensor (
5035 f, :: Type{T} , left_vspace:: S , right_vspace:: S = left_vspace
51- ) where {T, S <: ElementarySpaceLike }
52- return f (T, _to_space ( left_vspace) ← _to_space ( right_vspace) )
36+ ) where {T, S <: ElementarySpace }
37+ return f (T, left_vspace ← right_vspace)
5338end
5439
5540function _edge_tensor (
5641 f, :: Type{T} , left_vspace:: S , pspaces:: P , right_vspace:: S = left_vspace
57- ) where {T, S <: ElementarySpaceLike , P <: ProductSpaceLike }
58- return f (T, _to_space ( left_vspace) ⊗ _to_space ( pspaces), _to_space ( right_vspace) )
42+ ) where {T, S <: ElementarySpace , P <: ProductSpace }
43+ return f (T, left_vspace ⊗ pspaces, right_vspace)
5944end
6045
6146"""
6247 CTMRGEnv(
6348 [f=randn, T=ComplexF64], Ds_north::A, Ds_east::A, chis_north::B, [chis_east::B], [chis_south::B], [chis_west::B]
64- ) where {A<:AbstractMatrix{<:SpaceLike }, B<:AbstractMatrix{<:ElementarySpaceLike }}
49+ ) where {A<:AbstractMatrix{<:VectorSpace }, B<:AbstractMatrix{<:ElementarySpace }}
6550
6651Construct a CTMRG environment by specifying matrices of north and east virtual spaces of the
6752corresponding partition function and the north, east, south and west virtual spaces of the
@@ -76,32 +61,27 @@ of the corresponding edge tensor for each direction. Specifically, for a given s
7661`chis_west[r, c]` corresponds to the north space of the west edge tensor.
7762
7863Each entry of the `Ds_north` and `Ds_east` matrices corresponds to an effective local space
79- of the partition function, represented as a tuple of elementary spaces encoding a product
80- space. This can either contain a single elementary space for the case of a partition
81- function defined in terms of local rank-4 tensors, or a tuple of elementary spaces
82- representing a product space for the case of a partition function representing overlaps of
83- PEPSs and PEPOs.
64+ of the partition function, and can be represented as an `ElementarySpace` (e.g. for the case
65+ of a partition function defined in terms of local rank-4 tensors) or a `ProductSpace` (e.g.
66+ for the case of a network representing overlaps of PEPSs and PEPOs).
8467"""
8568function CTMRGEnv (
86- Ds_north:: A , Ds_east:: A ,
87- chis_north:: B , chis_east:: B = chis_north, chis_south:: B = chis_north, chis_west:: B = chis_north,
88- ) where {A <: AbstractMatrix{<:ProductSpaceLike} , B <: AbstractMatrix{<:ElementarySpaceLike} }
89- return CTMRGEnv (
90- randn, ComplexF64, N, Ds_north, Ds_east, chis_north, chis_east, chis_south, chis_west,
91- )
92- end
93- function CTMRGEnv (
94- f, T,
95- Ds_north:: A , Ds_east:: A ,
96- chis_north:: B , chis_east:: B = chis_north, chis_south:: B = chis_north, chis_west:: B = chis_north,
97- ) where {A <: AbstractMatrix{<:ProductSpaceLike} , B <: AbstractMatrix{<:ElementarySpaceLike} }
69+ f, T, Ds_north:: A , Ds_east:: A , chis_north:: B , chis_east:: B = chis_north,
70+ chis_south:: B = chis_north, chis_west:: B = chis_north,
71+ ) where {
72+ A <: AbstractMatrix{<:ProductSpace} , B <: AbstractMatrix{<:ElementarySpace} ,
73+ }
74+ # check all of the sizes
75+ size (Ds_north) == size (Ds_east) == size (chis_north) == size (chis_east) ==
76+ size (chis_south) == size (chis_west) || throw (ArgumentError (" Input spaces should have equal sizes." ))
77+
9878 # no recursive broadcasting?
9979 Ds_south = _elementwise_dual .(circshift (Ds_north, (- 1 , 0 )))
10080 Ds_west = _elementwise_dual .(circshift (Ds_east, (0 , 1 )))
10181
10282 # do the whole thing
10383 N = length (first (Ds_north))
104- st = _spacetype (first (Ds_north))
84+ st = spacetype (first (Ds_north))
10585 C_type = tensormaptype (st, 1 , 1 , T)
10686 T_type = tensormaptype (st, N + 1 , 1 , T)
10787
@@ -140,12 +120,37 @@ function CTMRGEnv(
140120 edges[:, :, :] ./= norm .(edges[:, :, :])
141121 return CTMRGEnv (corners, edges)
142122end
123+ function CTMRGEnv (D_north:: P , args... ; kwargs... ) where {P <: Union{Matrix{VectorSpace}, VectorSpace} }
124+ return CTMRGEnv (randn, ComplexF64, D_north, args... ; kwargs... )
125+ end
126+
127+ # expand physical edge spaces to unit cell size
128+ function _fill_edge_physical_spaces (
129+ D_north:: S , D_east:: S = D_north; unitcell:: Tuple{Int, Int} = (1 , 1 )
130+ ) where {S <: VectorSpace }
131+ return fill (ProductSpace (D_north), unitcell), fill (ProductSpace (D_east), unitcell)
132+ end
133+
134+ # expand virtual environment spaces to unit cell size
135+ function _fill_environment_virtual_spaces (
136+ chis_north:: S , chis_east:: S = chis_north, chis_south:: S = chis_north, chis_west:: S = chis_north;
137+ unitcell:: Tuple{Int, Int} = (1 , 1 )
138+ ) where {S <: ElementarySpace }
139+ return fill (chis_north, unitcell), fill (chis_east, unitcell), fill (chis_south, unitcell), fill (chis_west, unitcell)
140+ end
141+ function _fill_environment_virtual_spaces (
142+ chis_north:: M , chis_east:: M = chis_north, chis_south:: M = chis_north, chis_west:: M = chis_north;
143+ unitcell:: Tuple{Int, Int} = (1 , 1 )
144+ ) where {M <: AbstractMatrix{<:ElementarySpace} }
145+ @assert size (chis_north) == size (chis_east) == size (chis_south) == size (chis_west) == unitcell " Incompatible size"
146+ return chis_north, chis_east, chis_south, chis_west
147+ end
143148
144149"""
145150 CTMRGEnv(
146151 [f=randn, T=ComplexF64], D_north::P, D_east::P, chi_north::S, [chi_east::S], [chi_south::S], [chi_west::S];
147152 unitcell::Tuple{Int,Int}=(1, 1),
148- ) where {P<:ProductSpaceLike ,S<:ElementarySpaceLike }
153+ ) where {P<:VectorSpace ,S<:ElementarySpace }
149154
150155Construct a CTMRG environment by specifying the north and east virtual spaces of the
151156corresponding [`InfiniteSquareNetwork`](@ref) and the north, east, south and west virtual
@@ -156,122 +161,55 @@ same.
156161The environment virtual spaces for each site correspond to virtual space of the
157162corresponding edge tensor for each direction.
158163"""
159- function CTMRGEnv (
160- D_north:: P , D_east:: P ,
161- chi_north:: S , chi_east:: S = chi_north, chi_south:: S = chi_north, chi_west:: S = chi_north;
162- unitcell:: Tuple{Int, Int} = (1 , 1 ),
163- ) where {P <: ProductSpaceLike , S <: ElementarySpaceLike }
164- return CTMRGEnv (
165- randn, ComplexF64,
166- fill (D_north, unitcell), fill (D_east, unitcell),
167- fill (chi_north, unitcell), fill (chi_east, unitcell),
168- fill (chi_south, unitcell), fill (chi_west, unitcell),
169- )
170- end
171- function CTMRGEnv (
172- f, T,
173- D_north:: P , D_east:: P ,
174- chi_north:: S , chi_east:: S = chi_north,
175- chi_south:: S = chi_north, chi_west:: S = chi_north;
176- unitcell:: Tuple{Int, Int} = (1 , 1 ),
177- ) where {P <: ProductSpaceLike , S <: ElementarySpaceLike }
178- return CTMRGEnv (
179- f, T, N,
180- fill (D_north, unitcell), fill (D_east, unitcell),
181- fill (chi_north, unitcell), fill (chi_east, unitcell),
182- fill (chi_south, unitcell), fill (chi_west, unitcell),
183- )
184- end
185-
186- """
187- CTMRGEnv(
188- [f=randn, T=ComplexF64], network::InfiniteSquareNetwork, chis_north::A, [chis_east::A], [chis_south::A], [chis_west::A]
189- ) where {A<:AbstractMatrix{<:ElementarySpaceLike}}}
190-
191- Construct a CTMRG environment by specifying a corresponding [`InfiniteSquareNetwork`](@ref), and the
192- north, east, south and west virtual spaces of the environment as matrices. Each respective
193- matrix entry corresponds to a site in the unit cell. By default, the virtual spaces for all
194- directions are taken to be the same.
195-
196- The environment virtual spaces for each site correspond to the north or east virtual space
197- of the corresponding edge tensor for each direction. Specifically, for a given site
198- `(r, c)`, `chis_north[r, c]` corresponds to the east space of the north edge tensor,
199- `chis_east[r, c]` corresponds to the north space of the east edge tensor,
200- `chis_south[r, c]` corresponds to the east space of the south edge tensor, and
201- `chis_west[r, c]` corresponds to the north space of the west edge tensor.
202- """
203- function CTMRGEnv (
204- network:: InfiniteSquareNetwork ,
205- chis_north:: A , chis_east:: A = chis_north, chis_south:: A = chis_north, chis_west:: A = chis_north,
206- ) where {A <: AbstractMatrix{<:ElementarySpaceLike} }
207- Ds_north = _north_env_spaces (network)
208- Ds_east = _east_env_spaces (network)
209- return CTMRGEnv (
210- randn, scalartype (network),
211- Ds_north, Ds_east,
212- _to_space .(chis_north), _to_space .(chis_east), _to_space .(chis_south), _to_space .(chis_west),
213- )
214- end
215164function CTMRGEnv (
216165 f, T,
217- network:: InfiniteSquareNetwork ,
218- chis_north:: A , chis_east:: A = chis_north, chis_south:: A = chis_north, chis_west:: A = chis_north,
219- ) where {A <: AbstractMatrix{<:ElementarySpaceLike} }
220- Ds_north = _north_env_spaces (network)
221- Ds_east = _east_env_spaces (network)
166+ D_north:: S , D_east:: S , virtual_spaces... ; unitcell:: Tuple{Int, Int} = (1 , 1 ),
167+ ) where {S <: VectorSpace }
222168 return CTMRGEnv (
223169 f, T,
224- Ds_north, Ds_east ,
225- _to_space .(chis_north), _to_space .(chis_east), _to_space .(chis_south), _to_space .(chis_west) ,
170+ _fill_edge_physical_spaces (D_north, D_east; unitcell) ... ,
171+ _fill_environment_virtual_spaces (virtual_spaces ... ; unitcell) ... ,
226172 )
227173end
228174
229- function _north_env_spaces (network:: InfiniteSquareNetwork )
175+ # get edge physical spaces from network
176+ function _north_edge_physical_spaces (network:: InfiniteSquareNetwork )
230177 return map (ProductSpace ∘ _elementwise_dual ∘ north_virtualspace, unitcell (network))
231178end
232- function _east_env_spaces (network:: InfiniteSquareNetwork )
179+ function _east_edge_physical_spaces (network:: InfiniteSquareNetwork )
233180 return map (ProductSpace ∘ _elementwise_dual ∘ east_virtualspace, unitcell (network))
234181end
235182
236183"""
237184 CTMRGEnv(
238- [f=randn, T=ComplexF64,] network::InfiniteSquareNetwork, chi_north::S , [chi_east::S ], [chi_south::S ], [chi_west::S],
239- ) where {S<:ElementarySpaceLike }
185+ [f=randn, T=ComplexF64], network::InfiniteSquareNetwork, chis_north::A , [chis_east::A ], [chis_south::A ], [chis_west::A]
186+ ) where {A<:Union{AbstractMatrix{<:ElementarySpace}, ElementarySpace} }
240187
241188Construct a CTMRG environment by specifying a corresponding
242189[`InfiniteSquareNetwork`](@ref), and the north, east, south and west virtual spaces of the
243- environment. By default, the virtual spaces for all directions are taken to be the same.
190+ environment. The virtual spaces can either be specified as matrices of `ElementarySpace`s,
191+ or as individual `ElementarySpace`s which are then filled to match the size of the unit
192+ cell. Each respective matrix entry corresponds to a site in the unit cell. By default, the
193+ virtual spaces for all directions are taken to be the same.
244194
245- The environment virtual spaces for each site correspond to virtual space of the
246- corresponding edge tensor for each direction.
195+ The environment virtual spaces for each site correspond to the north or east virtual space
196+ of the corresponding edge tensor for each direction. Specifically, for a given site
197+ `(r, c)`, `chis_north[r, c]` corresponds to the east space of the north edge tensor,
198+ `chis_east[r, c]` corresponds to the north space of the east edge tensor,
199+ `chis_south[r, c]` corresponds to the east space of the south edge tensor, and
200+ `chis_west[r, c]` corresponds to the north space of the west edge tensor.
247201"""
248- function CTMRGEnv (
249- network:: InfiniteSquareNetwork ,
250- chi_north:: S , chi_east:: S = chi_north, chi_south:: S = chi_north, chi_west:: S = chi_north,
251- ) where {S <: ElementarySpaceLike }
252- return CTMRGEnv (
253- network,
254- fill (chi_north, size (network)), fill (chi_east, size (network)),
255- fill (chi_south, size (network)), fill (chi_west, size (network)),
256- )
202+ function CTMRGEnv (f, T, network:: InfiniteSquareNetwork , virtual_spaces... )
203+ Ds_north = _north_edge_physical_spaces (network)
204+ Ds_east = _east_edge_physical_spaces (network)
205+ virtual_spaces = _fill_environment_virtual_spaces (virtual_spaces... ; unitcell = size (network))
206+ return CTMRGEnv (f, T, Ds_north, Ds_east, virtual_spaces... )
257207end
258- function CTMRGEnv (
259- f, T,
260- network:: InfiniteSquareNetwork ,
261- chi_north:: S , chi_east:: S = chi_north, chi_south:: S = chi_north, chi_west:: S = chi_north,
262- ) where {S <: ElementarySpaceLike }
263- return CTMRGEnv (
264- f, T,
265- network,
266- fill (chi_north, size (network)), fill (chi_east, size (network)),
267- fill (chi_south, size (network)), fill (chi_west, size (network)),
268- )
208+ function CTMRGEnv (network:: Union{InfiniteSquareNetwork, InfinitePartitionFunction, InfinitePEPS} , virtual_spaces... )
209+ return CTMRGEnv (randn, scalartype (network), network, virtual_spaces... )
269210end
270211
271212# allow constructing environments for implicitly defined contractible networks
272- function CTMRGEnv (state:: Union{InfinitePartitionFunction, InfinitePEPS} , args... )
273- return CTMRGEnv (InfiniteSquareNetwork (state), args... )
274- end
275213function CTMRGEnv (f, T, state:: Union{InfinitePartitionFunction, InfinitePEPS} , args... )
276214 return CTMRGEnv (f, T, InfiniteSquareNetwork (state), args... )
277215end
0 commit comments