-
Notifications
You must be signed in to change notification settings - Fork 31
Environment initialization for CTMRG + ProductStateEnv
#264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
cb6b2a3
Add `initialize_environment`
leburgel 2b32182
Merge branch 'master' into lb/initialize_env
leburgel c1216f4
Add test
leburgel 2a6f121
Not converging isn't really passing though
leburgel 78cef7c
Pass virtual space specification through to `CTMRGEnv` constructor
leburgel c20aab3
Slurp, make an actual product state, and increase coverage
leburgel 11d8535
Better optional alg specification
leburgel 10ea2ef
Merge branch 'master' into lb/initialize_env
lkdvos 991ecc7
Apply suggestions from code review
leburgel 707728d
Merge branch 'master' into lb/initialize_env
leburgel 4996e1b
Add initialization function to `ProductStateInitialization` struct
leburgel c5855c0
Merge branch 'master' into lb/initialize_env
leburgel 7e4dd21
Merge remote-tracking branch 'upstream/master' into lb/initialize_env
Yue-Zhengyuan f4a9afb
Change `trscheme` to `trunc`
Yue-Zhengyuan 12f4b0f
Merge branch 'master' into lb/initialize_env
leburgel e12b527
Merge branch 'master' into lb/initialize_env
Yue-Zhengyuan 5a7605b
Stash update
leburgel 854aa77
Merge branch 'master' into lb/initialize_env
leburgel a767c94
Merge remote-tracking branch 'upstream/master' into lb/initialize_env
Yue-Zhengyuan 2502615
Update env init in finite-T SU tests
Yue-Zhengyuan 885faaf
Update test/ctmrg/initialization.jl
leburgel ad77085
Merge branch 'main' into lb/initialize_env
leburgel d56074a
Some fixes, and add environment initialization for PEPS using identit…
leburgel fa0d980
No longer use `@insert`
leburgel 203266a
Remove `bipartite_id`, add dedicated initialization from identity, ad…
leburgel ae9abe0
Merge branch 'main' into lb/initialize_env
leburgel 4c844f9
Reduce boilerplate a bit, add test for starting from specific product…
leburgel e05f662
Small cleanup for `BPEnv`
leburgel 9123bb3
Merge remote-tracking branch 'origin/main' into lb/initialize_env
leburgel af90a13
TensorMap data should be a matrix
leburgel 9dfd6b3
Forgot import
leburgel d0ec8d9
Actually use seed
leburgel 9a72484
Only seed at the start
leburgel f5f25ae
Merge remote-tracking branch 'origin/main' into lb/initialize_env
leburgel f51ed73
Update src/environments/product_state_environments.jl
leburgel b8a36dd
Define `TensorKit.storagetype` for `ProductStateEnv`
leburgel bed9c2f
Add actual `CTMRGEnv(::CTMRGEnv)` constructor
leburgel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
lkdvos marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """ | ||
| initialize_ctmrg_environment([elt::Type{<:Number},] n::InfiniteSquareNetwork, alg::RandomInitialization, virtual_spaces...) | ||
|
|
||
| Initialize a fully random `CTMRGEnv` using the given environment virtual spaces. See | ||
| [`CTMRGEnv`](@ref) for details on the expected format of the virtual spaces. | ||
| """ | ||
| function initialize_ctmrg_environment( | ||
| elt::Type{<:Number}, | ||
| n::InfiniteSquareNetwork, | ||
| alg::RandomInitialization, | ||
| virtual_spaces... = oneunit(spacetype(n)), | ||
|
leburgel marked this conversation as resolved.
|
||
| ) | ||
| return CTMRGEnv(alg.f, elt, n, virtual_spaces...) | ||
| end | ||
|
|
||
| """ | ||
| initialize_ctmrg_environment([elt::Type{<:Number},] n::InfiniteSquareNetwork, alg::RandomInitialization) | ||
|
|
||
| Initialize a `CTMRGEnv` corresponding to a product state with trivial virtual spaces and | ||
| corners. The product state edge tensors are initialized as `alg.f(elt, V::ProductSpace)`. | ||
| """ | ||
| function initialize_ctmrg_environment( | ||
| elt::Type{<:Number}, | ||
| n::InfiniteSquareNetwork, | ||
| alg::ProductStateInitialization, | ||
| ) | ||
| env = CTMRGEnv(ProductStateEnv(alg.f, elt, n)) | ||
| return env | ||
| end | ||
|
|
||
| """ | ||
| initialize_ctmrg_environment([elt::Type{<:Number},] n::InfiniteSquareNetwork, alg::RandomInitialization, [env0]) | ||
|
|
||
| Initialize a `CTMRGEnv` by applying a single untruncated iteration of | ||
| [`SimultaneousCTMRG`](@ref) to a given initial environment. By default, the starting | ||
| environment is chosen as a random product state. | ||
| """ | ||
| function initialize_ctmrg_environment( | ||
| elt::Type{<:Number}, | ||
| n::InfiniteSquareNetwork, | ||
| alg::ApplicationInitialization, | ||
| env0 = ProductStateEnv(alg.f, elt, n) | ||
| ) | ||
| dummy_alg = SimultaneousCTMRG(trunc = (; alg = :notrunc)) | ||
| env, = ctmrg_iteration(n, CTMRGEnv(env0), dummy_alg) | ||
| return env | ||
| end | ||
|
|
||
| _check_two_layer(::InfiniteSquareNetwork) = false | ||
| _check_two_layer(::InfiniteSquareNetwork{<:PEPSSandwich}) = true | ||
|
|
||
| """ | ||
| initialize_ctmrg_environment([elt::Type{<:Number},] n::InfiniteSquareNetwork, alg::RandomInitialization, [env0]) | ||
|
|
||
| Initialize a `CTMRGEnv` corresponding to a product state acting as an identity between the | ||
| virtual spaces of a two-layer network, for example | ||
| ``` | ||
| ╱ | ||
| ┌-----ket----- | ||
| | ╱ | | ||
| | | | ||
| | | ╱ | ||
| └-----bra----- | ||
| ╱ | ||
| ``` | ||
| """ | ||
| function initialize_ctmrg_environment( | ||
| elt::Type{<:Number}, | ||
| n::InfiniteSquareNetwork, | ||
| ::IdentityInitialization, | ||
| ) | ||
| _check_two_layer(n) || | ||
| throw(ArgumentError("Identity initialization is only defined for two-layer networks.")) | ||
| bp_env = BPEnv(isomorphism, elt, n) | ||
| env = CTMRGEnv(bp_env) | ||
| return env | ||
| end | ||
|
|
||
| function initialize_ctmrg_environment( | ||
| A::Union{InfiniteSquareNetwork, InfinitePEPS, InfinitePartitionFunction}, args...; | ||
| kwargs... | ||
| ) | ||
| return initialize_ctmrg_environment(scalartype(A), A, args...; kwargs...) | ||
| end | ||
| function initialize_ctmrg_environment( | ||
| elt::Type{<:Number}, A::Union{InfinitePEPS, InfinitePartitionFunction}, args...; | ||
| kwargs... | ||
| ) | ||
| return initialize_ctmrg_environment(elt, InfiniteSquareNetwork(A), args...; kwargs...) | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """ | ||
| $(TYPEDEF) | ||
|
|
||
| Tensor product environment for an infinite square network, containing a 4 x rows x cols | ||
| array of tensors, defined for each nearest neighbor bond in the network. | ||
|
|
||
| The product state tensors `p` connect to the network tensors | ||
| `P` at site `[r,c]` in the unit cell as: | ||
| ``` | ||
| p[1,r-1,c] | ||
| | | ||
| p[4,r,c-1]------P[r,c]------p[2,r,c+1] | ||
| | | ||
| p[3,r+1,c] | ||
| ``` | ||
| ## Fields | ||
|
|
||
| $(TYPEDFIELDS) | ||
| """ | ||
| struct ProductStateEnv{T} | ||
| "4 x rows x cols array of edge tensors making up a product state environment, where the | ||
| first dimension specifies the spatial direction" | ||
| edges::Array{T, 3} | ||
| ProductStateEnv{T}(edges::Array{T, 3}) where {T} = new{T}(edges) | ||
| function ProductStateEnv(edges::Array{T, 3}) where {T} | ||
| foreach(Iterators.product(axes(edges)[2:3]...)) do (d, w) | ||
| codomain(edges[NORTH, d, w]) == _elementwise_dual(codomain(edges[SOUTH, _prev(d, end), w])) || | ||
| throw( | ||
| SpaceMismatch("North virtual space at site $((d, w)) does not match: $(space(edges[NORTH, d, w])) vs $(space(edges[SOUTH, _prev(d, end), w])).") | ||
| ) | ||
| codomain(edges[EAST, d, w]) == _elementwise_dual(codomain(edges[WEST, d, _next(w, end)])) || | ||
| throw(SpaceMismatch("East virtual space at site $((d, w)) does not match: $(space(edges[EAST, d, w])) vs $(space(edges[WEST, d, _next(w, end)])).")) | ||
| end | ||
| foreach(Iterators.product(axes(edges)...)) do (dir, d, w) | ||
| dim(space(edges[dir, d, w])) > 0 || @warn "no fusion channels for edge ($dir, $d, $w)" | ||
| end | ||
| return new{T}(edges) | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| ProductStateEnv( | ||
| [f=randn, T=ComplexF64], Ds_north::A, Ds_east::A | ||
| ) where {A <: AbstractMatrix{<:ProductSpace}} | ||
|
|
||
| Construct a product state environment by specifying matrices of north and east virtual spaces of the | ||
| corresponding [`InfiniteSquareNetwork`](@ref). Each matrix entry corresponds to a site in the unit cell. | ||
|
|
||
| Each entry of the `Ds_north` and `Ds_east` matrices corresponds to an effective local space | ||
| of the network, and can be represented as a `ProductSpace` (e.g. | ||
| for the case of a network representing overlaps of PEPSs). | ||
| """ | ||
| function ProductStateEnv( | ||
| f, T, Ds_north::A, Ds_east::A | ||
| ) where {A <: AbstractMatrix{<:ProductSpace}} | ||
| Ds_south = _elementwise_dual.(circshift(Ds_north, (-1, 0))) | ||
| Ds_west = _elementwise_dual.(circshift(Ds_east, (0, 1))) | ||
| edges = map(Iterators.product(1:4, axes(Ds_north, 1), axes(Ds_north, 2))) do (dir, r, c) | ||
| msg = if dir == NORTH | ||
| f(T, Ds_north[_next(r, end), c]) | ||
| elseif dir == EAST | ||
| f(T, Ds_east[r, _prev(c, end)]) | ||
| elseif dir == SOUTH | ||
| f(T, Ds_south[_prev(r, end), c]) | ||
| else # WEST | ||
| f(T, Ds_west[r, _next(c, end)]) | ||
| end | ||
| return msg | ||
| end | ||
| normalize!.(edges) | ||
| return ProductStateEnv(edges) | ||
| end | ||
| function ProductStateEnv(Ds_north::A, args...; kwargs...) where {A <: AbstractMatrix{<:VectorSpace}} | ||
| return ProductStateEnv(randn, ComplexF64, Ds_north, args...; kwargs...) | ||
| end | ||
|
|
||
| """ | ||
| ProductStateEnv([f=randn, T=ComplexF64], network::InfiniteSquareNetwork) | ||
|
|
||
| Construct a product state environment by specifying a corresponding [`InfiniteSquareNetwork`](@ref). | ||
| """ | ||
| function ProductStateEnv(f, T, network::InfiniteSquareNetwork) | ||
| Ds_north = _north_edge_physical_spaces(network) | ||
| Ds_east = _east_edge_physical_spaces(network) | ||
| return ProductStateEnv(f, T, Ds_north, Ds_east) | ||
| end | ||
| function ProductStateEnv(network::Union{InfiniteSquareNetwork, InfinitePartitionFunction, InfinitePEPS}) | ||
| return ProductStateEnv(randn, scalartype(network), network) | ||
| end | ||
| function ProductStateEnv(f, T, state::Union{InfinitePartitionFunction, InfinitePEPS}, args...) | ||
| return ProductStateEnv(f, T, InfiniteSquareNetwork(state), args...) | ||
| end | ||
|
|
||
| Base.eltype(::Type{ProductStateEnv{T}}) where {T} = T | ||
| Base.size(env::ProductStateEnv, args...) = size(env.edges, args...) | ||
| Base.getindex(env::ProductStateEnv, args...) = Base.getindex(env.edges, args...) | ||
| Base.eachindex(index_style, env::ProductStateEnv) = eachindex(index_style, env.edges) | ||
| VectorInterface.scalartype(::Type{ProductStateEnv{T}}) where {T} = scalartype(T) | ||
| TensorKit.storagetype(::Type{ProductStateEnv{T}}) where {T} = storagetype(T) | ||
| TensorKit.spacetype(::Type{ProductStateEnv{T}}) where {T} = spacetype(T) | ||
|
|
||
| # conversion to CTMRGEnv | ||
| """ | ||
| CTMRGEnv(prod_env::ProductStateEnv) | ||
|
|
||
| Construct a CTMRG environment with a trivial virtual space of bond dimension χ = 1 | ||
| from the product state environment `prod_env`. | ||
| """ | ||
| function CTMRGEnv(prod_env::ProductStateEnv) | ||
| edges = map(eachindex(IndexCartesian(), prod_env)) do idx | ||
| return insertleftunit(insertleftunit(prod_env[idx]), 1) | ||
|
lkdvos marked this conversation as resolved.
|
||
| end | ||
| corners = map(eachindex(IndexCartesian(), prod_env)) do _ | ||
| return TensorKit.id(storagetype(prod_env), oneunit(spacetype(prod_env))) | ||
| end | ||
| return CTMRGEnv(corners, edges) | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.