Repository navigation
Add randomized full-environment CTMRG projector #464
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
Closed
Yue-Zhengyuan
wants to merge
1
commit into
QuantumKitHub:main
from
Yue-Zhengyuan:codex/pr-263-randomized-projector
Closed
Changes from all commits
Commits
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
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,95 @@ | ||
| """Full-environment randomized SVD projector from PR 263.""" | ||
|
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. I think the "from PR 263" should be removed here |
||
| struct RandomizedProjector{S, T, R} <: ProjectorAlgorithm | ||
| decomposition_alg::S | ||
| trunc::T | ||
| rng::R | ||
| oversampling::Int | ||
| max_full::Int | ||
| n_subspace_iter::Int | ||
| verbosity::Int | ||
| end | ||
|
|
||
| PROJECTOR_SYMBOLS[:randomized] = RandomizedProjector | ||
|
|
||
| decomposition_algorithm(alg::RandomizedProjector) = alg.decomposition_alg | ||
|
|
||
| _default_randomized_oversampling = 10 | ||
| _default_randomized_max_full = 100 | ||
| _default_n_subspace_iter = 2 | ||
|
|
||
| # needed as default interface in PEPSKit.ProjectorAlgorithm | ||
| """Construct the randomized projector with the original PR defaults.""" | ||
| function RandomizedProjector(decomposition_alg, trunc, verbosity) | ||
| return RandomizedProjector( | ||
| decomposition_alg, trunc, Random.default_rng(), _default_randomized_oversampling, | ||
| _default_randomized_max_full, _default_n_subspace_iter, verbosity | ||
| ) | ||
| end | ||
|
|
||
| """Choose exact or oversampled sector dimensions using the previous environment space.""" | ||
| function random_domain(alg::RandomizedProjector, full_space, last_space) | ||
| sector_dims = map(sectors(full_space)) do s | ||
| if dim(full_space, s) <= alg.max_full | ||
| n = dim(full_space, s) | ||
| else | ||
| n = dim(last_space, s) + alg.oversampling | ||
| end | ||
| return s => n | ||
| end | ||
| return Vect[sectortype(last_space)](sector_dims) | ||
| end | ||
|
|
||
|
|
||
| """Find each block range using exact bases for small blocks and randomized iteration otherwise.""" | ||
| function randomized_range_finder(A::AbstractTensorMap, alg::RandomizedProjector, randomized_space) | ||
| Q = TensorMap{eltype(A)}(undef, domain(A) ← randomized_space) | ||
| foreach(blocks(Q)) do (s, b) | ||
| Aad = A' | ||
| m, n = size(b) | ||
| if m <= alg.max_full | ||
| b .= LinearAlgebra.I(m) | ||
| else | ||
| Ω = randn(alg.rng, eltype(A), domain(A) ← Vect[sectortype(A)](s => n)) | ||
| for _ in 1:alg.n_subspace_iter | ||
| Y = A * Ω | ||
| Qs, _ = left_orth!(Y) | ||
| Ω, _ = left_orth!(Aad * Qs) | ||
| end | ||
| Y = A * Ω | ||
| Qs, _ = left_orth!(Y) | ||
| b .= block(Qs, s) | ||
| end | ||
| end | ||
| return Q | ||
| end | ||
|
|
||
| # impose full env, could also be defined for half_infinite_environment, little gain | ||
| """Build the CTMRG projectors from the lazy randomized full-environment SVD.""" | ||
| function compute_projector(fq::FourQuadrants, last_space, alg::RandomizedProjector) | ||
| full_space = fuse(domain(fq)) | ||
| randomized_space = random_domain(alg, full_space, last_space) | ||
| Q = randomized_range_finder(fq, alg, randomized_space) | ||
| B = Q' * fq | ||
| normalize!(B) # TODO better way? | ||
|
|
||
| decomposition_alg = decomposition_algorithm(alg) | ||
| U′, S, V, truncation_error = svd_trunc!(B, decomposition_alg) | ||
| U = Q * U′ | ||
| foreach(blocks(S)) do (s, b) | ||
| if size(b, 1) == dim(randomized_space, s) && size(b, 1) < dim(full_space, s) | ||
| @warn("Sector is too small, kept all computed values: ", s) | ||
| end | ||
| end | ||
|
|
||
| # Check for degenerate singular values; still needed for exact blocks | ||
| Zygote.isderiving() && ignore_derivatives() do | ||
| if alg.verbosity > 0 && is_degenerate_spectrum(S) | ||
| svals = TensorKit.SectorDict(c => diag(b) for (c, b) in blocks(S)) | ||
| @warn("degenerate singular values detected: ", svals) | ||
| end | ||
| end | ||
|
|
||
| truncation_error = truncation_error / norm(S) # normalize truncation error | ||
| P_left, P_right = contract_projectors(U, S, V, fq) | ||
| return (P_left, P_right), (; U, S, V, truncation_error) | ||
| 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should randomized have capital R for consistency