Skip to content

Commit 98fb536

Browse files
pbrehmerleburgellkdvos
authored
fixedpoint improvements (#337)
* Add `check_input` method for `fixedpoint` * Add `contraction_metrics` tuple to returned `info` * Add tests for real C4v optimization and QR-CTMRG optimizations * Fix `truncation_error` in sequential mode and catch `:fixed` mode error for real tensors in tests * Use type parameters in `check_input` and use old seed again * Use `:linsolver` by default for C4v CTMRG * Update changelog * Rerender Heisenberg example * Alter seed to make QR-CTMRG not hickup * Update src/algorithms/optimization/peps_optimization.jl Co-authored-by: Lukas Devos <ldevos98@gmail.com> * Add symmetrization to `_check_algorithm_combination` --------- Co-authored-by: Lander Burgelman <39218680+leburgel@users.noreply.github.com> Co-authored-by: Lukas Devos <ldevos98@gmail.com>
1 parent 7a4c1a1 commit 98fb536

13 files changed

Lines changed: 224 additions & 193 deletions

File tree

docs/src/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
2525
### Changed
2626

2727
- Bump OptimKit.jl compatibility to v0.4
28+
- Move `info.truncation_error` and `info.condition_number` into the `info.contraction_metrics` named tuple for `leading_boundary` and `fixedpoint`
2829

2930
### Deprecated
3031

docs/src/examples/heisenberg/index.md

Lines changed: 100 additions & 95 deletions
Large diffs are not rendered by default.

docs/src/examples/heisenberg/main.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,19 @@
204204
"cell_type": "markdown",
205205
"source": [
206206
"Besides the converged environment, `leading_boundary` also returns a `NamedTuple` of\n",
207-
"informational quantities such as the last maximal truncation error - that is, the SVD\n",
208-
"approximation error incurred in the last CTMRG iteration, maximized over all spatial\n",
209-
"directions and unit cell entries:"
207+
"informational quantities which contains, among other things, a `contraction_metric` tuple.\n",
208+
"This may contain different quantities depending on the method of contraction, and for this\n",
209+
"CTMRG variant we return the last maximal truncation error (the SVD approximation\n",
210+
"error maximized over all spatial directions and unit cell entries) as well as the condition\n",
211+
"number of the decomposition (the ratio of largest to smallest singular value):"
210212
],
211213
"metadata": {}
212214
},
213215
{
214216
"outputs": [],
215217
"cell_type": "code",
216218
"source": [
217-
"@show info_ctmrg.truncation_error;"
219+
"@show info_ctmrg.contraction_metrics;"
218220
],
219221
"metadata": {},
220222
"execution_count": null
@@ -382,11 +384,11 @@
382384
"file_extension": ".jl",
383385
"mimetype": "application/julia",
384386
"name": "julia",
385-
"version": "1.11.7"
387+
"version": "1.12.5"
386388
},
387389
"kernelspec": {
388-
"name": "julia-1.11",
389-
"display_name": "Julia 1.11.7",
390+
"name": "julia-1.12",
391+
"display_name": "Julia 1.12.5",
390392
"language": "julia"
391393
}
392394
},

examples/Cache.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ heisenberg_su = "3eb8556d949c0e47e39c679e9e438bc04d3e2a3ffe73e0a682963b37b05f9e9
77
xxz = "0231f0c1af2013e8edd9e5c192b108e1ab19a7dca22251c3bde525e3eee2a6aa"
88
fermi_hubbard = "4997680c826e555557c661e605e1d7d363e0cee15522d0895fa0cfd53b1de001"
99
j1j2_su = "c00fd13c0be323ab5825af59f3e7b31c3e51d3f65211d3836657b64274504c1c"
10-
heisenberg = "d610c92223d41e296348f9858fab52eacbfe2a578f64f4f8ac4c70d486fb4da2"
10+
heisenberg = "80bb9cc57ed85297b1b789a6c5f09494dac81b23631f48c6600ede9424c5d248"

examples/heisenberg/main.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ env₀, info_ctmrg = leading_boundary(env_random, peps₀; boundary_alg...);
102102

103103
md"""
104104
Besides the converged environment, `leading_boundary` also returns a `NamedTuple` of
105-
informational quantities such as the last maximal truncation error - that is, the SVD
106-
approximation error incurred in the last CTMRG iteration, maximized over all spatial
107-
directions and unit cell entries:
105+
informational quantities which contains, among other things, a `contraction_metric` tuple.
106+
This may contain different quantities depending on the method of contraction, and for this
107+
CTMRG variant we return the last maximal truncation error (the SVD approximation
108+
error maximized over all spatial directions and unit cell entries) as well as the condition
109+
number of the decomposition (the ratio of largest to smallest singular value):
108110
"""
109111

110-
@show info_ctmrg.truncation_error;
112+
@show info_ctmrg.contraction_metrics;
111113

112114
md"""
113115
## Ground state search

src/algorithms/ctmrg/c4v.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ $(TYPEDFIELDS)
8686
8787
C4vQRProjector(; kwargs...)
8888
89-
Construct the C₄ᵥ `qr`-based projector algorithm
90-
based on the following keyword arguments:
89+
Construct the C₄ᵥ `qr`-based projector algorithm based on the following keyword arguments:
9190
9291
* `decomposition_alg=QRAdjoint()` : `left_orth` algorithm including the reverse rule. See [`QRAdjoint`](@ref).
9392
"""
@@ -104,7 +103,7 @@ PROJECTOR_SYMBOLS[:c4v_qr] = C4vQRProjector
104103
_set_truncation(alg::C4vQRProjector, ::TruncationStrategy) = alg
105104

106105
function check_input(
107-
network::InfiniteSquareNetwork, env::CTMRGEnv, alg::C4vCTMRG; atol = 1.0e-10
106+
::typeof(leading_boundary), network::InfiniteSquareNetwork, env::CTMRGEnv, alg::C4vCTMRG; atol = 1.0e-10
108107
)
109108
# check unit cell size
110109
length(network) == 1 || throw(ArgumentError("C4v CTMRG is only compatible with single-site unit cells."))
@@ -144,6 +143,10 @@ function ctmrg_iteration(
144143
enlarged_corner = c4v_enlarge(network, env, alg.projector_alg)
145144
corner′, projector, info = c4v_projector!(enlarged_corner, alg.projector_alg)
146145
edge′ = c4v_renormalize_edge(network, env, projector)
146+
info = (;
147+
contraction_metrics = (; info.truncation_error, info.condition_number),
148+
info.D, info.V, info.D_full, info.V_full, info.truncation_indices,
149+
)
147150
return CTMRGEnv(corner′, edge′), info
148151
end
149152
function ctmrg_iteration(
@@ -155,6 +158,7 @@ function ctmrg_iteration(
155158
projector, info = c4v_projector!(enlarged_corner, alg.projector_alg)
156159
edge′ = c4v_renormalize_edge(network, env, projector)
157160
corner′ = c4v_qr_renormalize_corner(edge′, projector, info.R)
161+
info = (; contraction_metrics = (;), info.Q, info.R)
158162
return CTMRGEnv(corner′, edge′), info
159163
end
160164

src/algorithms/ctmrg/ctmrg.jl

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ Perform a single CTMRG iteration in which all directions are being grown and ren
4444
"""
4545
function ctmrg_iteration(network, env, alg::CTMRGAlgorithm) end
4646

47-
"""
48-
check_input(network, env, alg::CTMRGAlgorithm)
49-
50-
Check compatibility of a given network and environment with a specified CTMRG algorithm.
51-
"""
52-
function check_input(network, env, alg::CTMRGAlgorithm) end
53-
@non_differentiable check_input(args...)
54-
5547
"""
5648
leading_boundary(env₀, network; kwargs...) -> env, info
5749
# expert version:
@@ -91,30 +83,15 @@ supplied via the keyword arguments or directly as an [`CTMRGAlgorithm`](@ref) st
9183
* `projector_alg::Symbol=:$(Defaults.projector_alg)` : Variant of the projector algorithm. See also [`ProjectorAlgorithm`](@ref).
9284
- `:halfinfinite` : Projection via SVDs of half-infinite (two enlarged corners) CTMRG environments.
9385
- `:fullinfinite` : Projection via SVDs of full-infinite (all four enlarged corners) CTMRG environments.
94-
- `:c4v_eigh` : Projection via `eigh` of the Hermitian enlarged corner.
86+
- `:c4v_eigh` : Projection via `eigh` of the Hermitian enlarged corner, works only for [`C4vCTMRG`](@ref).
87+
- `:c4v_qr` : Projection via QR decomposition of the lower-rank column-enlarged corner, works only for [`C4vCTMRG`](@ref).
9588
9689
## Return values
9790
98-
The CTMRG routine returns the final CTMRG environment as well as an information `NamedTuple`
99-
containing the following fields:
100-
101-
* `truncation_error` : Last (maximal) SVD truncation error of the CTMRG projectors.
102-
* `condition_number` : Last (maximal) condition number of the enlarged CTMRG environment.
103-
104-
In case the `alg` is a `SimultaneousCTMRG`, the last SVD will also be returned:
105-
106-
* `U` : Last unit cell of left singular vectors.
107-
* `S` : Last unit cell of singular values.
108-
* `V` : Last unit cell of right singular vectors.
109-
110-
If, in addition, the specified SVD algorithm computes the full, untruncated SVD, the full
111-
set of vectors and values will be returned as well:
112-
113-
* `U_full` : Last unit cell of all left singular vectors.
114-
* `S_full` : Last unit cell of all singular values.
115-
* `V_full` : Last unit cell of all right singular vectors.
116-
117-
For `C4vCTMRG` instead the last eigendecomposition `V` and `D` (and `V_full`, `D_full`) will be returned.
91+
The `leading_boundary` routine returns the final environment as well as an information `NamedTuple`
92+
that generally contains a `contraction_metrics` `NamedTuple` storing different contents depending
93+
on the chosen `alg`. Depending on the contraction method, the information tuple may also contain
94+
the final tensor decomposition (used in the projectors) including its truncation indices.
11895
"""
11996
function leading_boundary(env₀::CTMRGEnv, network::InfiniteSquareNetwork; kwargs...)
12097
alg = select_algorithm(leading_boundary, env₀; kwargs...)
@@ -123,7 +100,7 @@ end
123100
function leading_boundary(
124101
env₀::CTMRGEnv, network::InfiniteSquareNetwork, alg::CTMRGAlgorithm
125102
)
126-
check_input(network, env₀, alg)
103+
check_input(leading_boundary, network, env₀, alg)
127104
log = ignore_derivatives(() -> MPSKit.IterLog("CTMRG"))
128105
return LoggingExtras.withlevel(; alg.verbosity) do
129106
env = deepcopy(env₀)
@@ -154,6 +131,14 @@ function leading_boundary(env₀::CTMRGEnv, state, args...; kwargs...)
154131
return leading_boundary(env₀, InfiniteSquareNetwork(state), args...; kwargs...)
155132
end
156133

134+
"""
135+
check_input(::typeof(leading_boundary), network, env, alg::CTMRGAlgorithm)
136+
137+
Check compatibility of a given network and environment with a specified CTMRG algorithm.
138+
"""
139+
function check_input(::typeof(leading_boundary), network, env, alg::CTMRGAlgorithm) end
140+
@non_differentiable check_input(args...)
141+
157142
# custom CTMRG logging
158143
function ctmrg_loginit!(log, η, network, env)
159144
return @infov 2 loginit!(log, η, network_value(network, env))

src/algorithms/ctmrg/sequential.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function ctmrg_iteration(network, env::CTMRGEnv, alg::SequentialCTMRG)
6969
network = rotate_north(network, EAST)
7070
env = rotate_north(env, EAST)
7171
end
72-
return env, (; truncation_error, condition_number)
72+
return env, (; contraction_metrics = (; truncation_error, condition_number))
7373
end
7474

7575
"""

src/algorithms/ctmrg/simultaneous.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ function ctmrg_iteration(network, env::CTMRGEnv, alg::SimultaneousCTMRG)
4848
end # expand environment
4949
projectors, info = simultaneous_projectors(enlarged_corners, env, alg.projector_alg) # compute projectors on all coordinates
5050
env′ = renormalize_simultaneously(enlarged_corners, projectors, network, env) # renormalize enlarged corners
51+
info = (;
52+
contraction_metrics = (; info.truncation_error, info.condition_number),
53+
info.U, info.S, info.V, info.U_full, info.S_full, info.V_full, info.truncation_indices,
54+
)
5155
return env′, info
5256
end
5357

src/algorithms/optimization/fixed_point_differentiation.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,19 @@ EigSolver(; kwargs...) = GradMode(; alg = :eigsolver, kwargs...)
201201
GRADIENT_MODE_SYMBOLS[:eigsolver] = EigSolver
202202

203203
"""
204-
_check_algorithm_combination(boundary_alg, gradient_alg)
204+
_check_algorithm_combination(boundary_alg, gradient_alg_or_symmetrization)
205+
_check_algorithm_combination(boundary_alg, gradient_alg, symmetrization)
205206
206207
Check for allowed combinations of gradient algorithm and boundary algorithm to be used for
207208
computing the gradient of a `leading_boundary` call. Throws an error containing a
208209
recommended fix if the combination is not allowed or broken.
209210
"""
210-
function _check_algorithm_combination(boundary_alg, gradient_alg) end
211+
function _check_algorithm_combination(boundary_alg, gradient_alg_or_symmetrization) end
212+
function _check_algorithm_combination(boundary_alg, gradient_alg, symmetrization)
213+
_check_algorithm_combination(boundary_alg, gradient_alg)
214+
_check_algorithm_combination(boundary_alg, symmetrization)
215+
return nothing
216+
end
211217
function _check_algorithm_combination(::SequentialCTMRG, ::GradMode{:fixed})
212218
msg = "`:fixed` mode is not compatible with `SequentialCTMRG` since the sequential \
213219
application of SVDs does not allow to differentiate through a fixed set of \
@@ -216,10 +222,18 @@ function _check_algorithm_combination(::SequentialCTMRG, ::GradMode{:fixed})
216222
end
217223
function _check_algorithm_combination(::C4vCTMRG{<:C4vEighProjector}, ::GradMode{:diffgauge})
218224
msg = "`:diffgauge` mode is currently not compatible with eigh-based C4v CTMRG; \
219-
either switch to a different projector algorithm (e.g. `c4v_qr`), or use :fixed \
220-
mode for differentiation instead."
225+
either switch to a different projector algorithm (e.g. `c4v_qr`), or use :fixed \
226+
mode for differentiation instead."
221227
throw(ArgumentError(msg))
222228
end
229+
function _check_algorithm_combination(::C4vCTMRG, symm::Union{Nothing, <:SymmetrizationStyle})
230+
if !(symm isa RotateReflect)
231+
msg = "C4vCTMRG optimization is compatible only with RotateReflect symmetrization. \
232+
Make sure to set `symmetrization = RotateReflect()`."
233+
throw(ArgumentError(msg))
234+
end
235+
return nothing
236+
end
223237

224238
#=
225239
Evaluating the gradient of the cost function for CTMRG:

0 commit comments

Comments
 (0)