-
Notifications
You must be signed in to change notification settings - Fork 28
improve Simpleupdate performances #361
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
base: master
Are you sure you want to change the base?
Changes from all commits
a572e07
9e0222b
c8798e2
dd7c58b
d2b37af
ada6ba7
83faeff
8a5c196
75cfad4
e3dc4ed
23ea6c0
63db27c
b166ef2
2c30b62
f52f6f1
aee67d1
c0f7070
e96c515
3b53deb
8430286
6b29aa9
650ac76
c431a00
b35a54a
78946df
61d14ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """ | ||
| absorb_weight(t::Union{PEPSTensor, PEPOTensor}, weights::SUWeight, rowcol::CartesianIndex{2}, virt_axes::NTuple{N, Int}; inv::Bool = false) | ||
| absorb_weight(t::Union{PEPSTensor, PEPOTensor}, weights::SUWeight, row::Int, col::Int, virt_axes::NTuple{N, Int}; inv::Bool = false) | ||
|
|
||
| Absorb or remove (in a twist-free way) the square root of environment weight | ||
| on an axis of the PEPS/PEPO tensor `t` known to be at position (`row`, `col`) | ||
| in the unit cell of an InfinitePEPS/InfinitePEPO. The involved weights are | ||
| ``` | ||
| | | ||
| [2,r,c] | ||
| | | ||
| - [1,r,c-1] - T[r,c] - [1,r,c] - | ||
| | | ||
| [2,r+1,c] | ||
| | | ||
| ``` | ||
|
|
||
| ## Arguments | ||
|
|
||
| - `t::Union{PEPSTensor, PEPOTensor}` : PEPSTensor or PEPOTensor to which the weight will be absorbed. | ||
| - `weights::SUWeight` : All simple update weights. | ||
| - `row::Int` : The row index specifying the position in the tensor network. | ||
| - `col::Int` : The column index specifying the position in the tensor network. | ||
| - `virt_axes::Int` : The axis into which the weight is absorbed, taking values from 1 to 4, standing for north, east, south, west respectively. | ||
|
|
||
| ## Keyword arguments | ||
|
|
||
| - `inv::Bool=false` : If `true`, the inverse square root of the weight is absorbed. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```julia | ||
| # Absorb the weight into the north axis of tensor at position (2, 3) | ||
| absorb_weight(t, weights, 2, 3, (1,)) | ||
|
|
||
| # Absorb the inverse of (i.e. remove) the weight into the east axis | ||
| absorb_weight(t, weights, 2, 3, (2,); inv=true) | ||
| ``` | ||
| """ | ||
| function absorb_weight( | ||
| t::Union{PEPSTensor, PEPOTensor}, weights::SUWeight, | ||
| rowcol::CartesianIndex{2}, virt_axes::NTuple{N, Int}; inv::Bool = false | ||
| ) where {N} | ||
| return absorb_weight(t, weights, rowcol[1], rowcol[2], virt_axes; inv) | ||
| end | ||
|
|
||
| function absorb_weight( | ||
| t::Union{PEPSTensor, PEPOTensor}, weights::SUWeight, | ||
| row::Int, col::Int, virt_axes::NTuple{N, Int}; inv::Bool = false | ||
| ) where {N} | ||
| vax = first(virt_axes) | ||
| weight_vax = weight_to_absorb(weights, row, col, vax; inv) | ||
| legs, t2 = absorb_first_weight(t, weight_vax, vax) | ||
| for vax in Base.tail(virt_axes) | ||
| legs, biperm = biperm_absorb_weight(legs, vax) | ||
| weight_vax = weight_to_absorb(weights, row, col, vax; inv) | ||
| t2 = permute(t2, biperm) * weight_vax | ||
| end | ||
| perm_back = invperm(legs) | ||
| return permute(t2, (perm_back[begin:numout(t)], perm_back[(numout(t) + 1):end])) | ||
| end | ||
|
|
||
| function weight_to_absorb( | ||
| weights::SUWeight, row::Int, col::Int, ax::Int; inv::Bool = false | ||
| ) | ||
| _, Nr, Nc = size(weights) | ||
| @assert 1 <= row <= Nr && 1 <= col <= Nc | ||
| pow = inv ? -1 / 2 : 1 / 2 | ||
| wt = sdiag_pow( | ||
| if ax == NORTH | ||
| weights[2, row, col] | ||
| elseif ax == EAST | ||
| weights[1, row, col] | ||
| elseif ax == SOUTH | ||
| weights[2, _next(row, Nr), col] | ||
| else # WEST | ||
| weights[1, row, _prev(col, Nc)] | ||
| end, | ||
| pow, | ||
| ) | ||
| # make absorption/removal twist-free | ||
| twistdual!(wt, 1) | ||
| (ax == SOUTH || ax == WEST) && return transpose(wt) # not sure this can be factorized due to twistdual | ||
| return wt | ||
| end | ||
|
|
||
| function biperm_absorb_weight(legs::NTuple{N, Int}, vax::Int) where {N} | ||
| @assert N == 5 || N == 6 | ||
| nin = N - 4 | ||
| a = vax + nin | ||
| codomain_axes = TupleTools.deleteat(ntuple(identity, N), a) | ||
| q = invperm(legs) | ||
| biperm = (map(i -> q[i], codomain_axes), (q[a],)) | ||
| new_legs = (ntuple(i -> legs[biperm[1][i]], N - 1)..., a) | ||
| return new_legs, biperm | ||
| end | ||
|
|
||
| function absorb_first_weight(t::Union{PEPSTensor, PEPOTensor}, wt, vax) | ||
| legs = ntuple(identity, numind(t)) | ||
| new_legs, biperm = biperm_absorb_weight(legs, vax) | ||
| t2 = permute(t, biperm) * wt | ||
| return new_legs, t2 | ||
| end | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,15 @@ function _apply_sitegate( | |
| return a′ | ||
| end | ||
|
|
||
| function _get_biperms(::PEPSTensor, ::Integer) | ||
| return ((2, 4, 5), (1, 3)), ((2, 3, 4), (1, 5)), (1, 4, 2, 3), ntuple(identity, 4) | ||
| end | ||
| function _get_biperms(::PEPOTensor, gate_ax::Integer) | ||
| if gate_ax == 1 | ||
| return ((2, 3, 5, 6), (1, 4)), ((2, 3, 4, 5), (1, 6)), (1, 2, 5, 3, 4), ntuple(identity, 5) | ||
| end | ||
| return ((1, 3, 5, 6), (2, 4)), ((1, 3, 4, 5), (2, 6)), (1, 2, 5, 3, 4), ntuple(identity, 5) | ||
| end | ||
| """ | ||
| $(SIGNATURES) | ||
|
|
||
|
|
@@ -48,17 +57,10 @@ When `A`, `B` are PEPOTensors, | |
| 5 1 4 1 4 1 | ||
| ``` | ||
| """ | ||
| function _qr_bond(A::PT, B::PT; gate_ax::Int = 1, kwargs...) where {PT <: Union{PEPSTensor, PEPOTensor}} | ||
| function _qr_bond(A::PT, B::PT; gate_ax::Integer = 1, kwargs...) where {PT <: Union{PEPSTensor, PEPOTensor}} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these functions, both for type stability and human readability, I would really prefer to just use dispatch and write out the two cases manually.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @assert 1 <= gate_ax <= numout(A) | ||
| permA, permB, permX, permY = if A isa PEPSTensor | ||
| ((2, 4, 5), (1, 3)), ((2, 3, 4), (1, 5)), (1, 4, 2, 3), Tuple(1:4) | ||
| else | ||
| if gate_ax == 1 | ||
| ((2, 3, 5, 6), (1, 4)), ((2, 3, 4, 5), (1, 6)), (1, 2, 5, 3, 4), Tuple(1:5) | ||
| else | ||
| ((1, 3, 5, 6), (2, 4)), ((1, 3, 4, 5), (2, 6)), (1, 2, 5, 3, 4), Tuple(1:5) | ||
| end | ||
| end | ||
| permA, permB, permX, permY = _get_biperms(A, gate_ax) | ||
|
|
||
| X, a = left_orth!(permute(A, permA; copy = true); kwargs...) | ||
| Y, b = left_orth!(permute(B, permB; copy = true); kwargs...) | ||
| X, Y = permute(X, permX), permute(Y, permY) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.