Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
### Changed

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

### Deprecated

Expand Down
195 changes: 100 additions & 95 deletions docs/src/examples/heisenberg/index.md

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions docs/src/examples/heisenberg/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,19 @@
"cell_type": "markdown",
"source": [
"Besides the converged environment, `leading_boundary` also returns a `NamedTuple` of\n",
"informational quantities such as the last maximal truncation error - that is, the SVD\n",
"approximation error incurred in the last CTMRG iteration, maximized over all spatial\n",
"directions and unit cell entries:"
"informational quantities which contains, among other things, a `contraction_metric` tuple.\n",
"This may contain different quantities depending on the method of contraction, and for this\n",
"CTMRG variant we return the last maximal truncation error (the SVD approximation\n",
"error maximized over all spatial directions and unit cell entries) as well as the condition\n",
"number of the decomposition (the ratio of largest to smallest singular value):"
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"@show info_ctmrg.truncation_error;"
"@show info_ctmrg.contraction_metrics;"
],
"metadata": {},
"execution_count": null
Expand Down Expand Up @@ -382,11 +384,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.11.7"
"version": "1.12.5"
},
"kernelspec": {
"name": "julia-1.11",
"display_name": "Julia 1.11.7",
"name": "julia-1.12",
"display_name": "Julia 1.12.5",
"language": "julia"
}
},
Expand Down
2 changes: 1 addition & 1 deletion examples/Cache.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ heisenberg_su = "3eb8556d949c0e47e39c679e9e438bc04d3e2a3ffe73e0a682963b37b05f9e9
xxz = "0231f0c1af2013e8edd9e5c192b108e1ab19a7dca22251c3bde525e3eee2a6aa"
fermi_hubbard = "4997680c826e555557c661e605e1d7d363e0cee15522d0895fa0cfd53b1de001"
j1j2_su = "c00fd13c0be323ab5825af59f3e7b31c3e51d3f65211d3836657b64274504c1c"
heisenberg = "d610c92223d41e296348f9858fab52eacbfe2a578f64f4f8ac4c70d486fb4da2"
heisenberg = "80bb9cc57ed85297b1b789a6c5f09494dac81b23631f48c6600ede9424c5d248"
10 changes: 6 additions & 4 deletions examples/heisenberg/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ env₀, info_ctmrg = leading_boundary(env_random, peps₀; boundary_alg...);

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

@show info_ctmrg.truncation_error;
@show info_ctmrg.contraction_metrics;

md"""
## Ground state search
Expand Down
10 changes: 7 additions & 3 deletions src/algorithms/ctmrg/c4v.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ $(TYPEDFIELDS)

C4vQRProjector(; kwargs...)

Construct the C₄ᵥ `qr`-based projector algorithm
based on the following keyword arguments:
Construct the C₄ᵥ `qr`-based projector algorithm based on the following keyword arguments:

* `decomposition_alg=QRAdjoint()` : `left_orth` algorithm including the reverse rule. See [`QRAdjoint`](@ref).
"""
Expand All @@ -104,7 +103,7 @@ PROJECTOR_SYMBOLS[:c4v_qr] = C4vQRProjector
_set_truncation(alg::C4vQRProjector, ::TruncationStrategy) = alg

function check_input(
network::InfiniteSquareNetwork, env::CTMRGEnv, alg::C4vCTMRG; atol = 1.0e-10
::typeof(leading_boundary), network::InfiniteSquareNetwork, env::CTMRGEnv, alg::C4vCTMRG; atol = 1.0e-10
)
# check unit cell size
length(network) == 1 || throw(ArgumentError("C4v CTMRG is only compatible with single-site unit cells."))
Expand Down Expand Up @@ -144,6 +143,10 @@ function ctmrg_iteration(
enlarged_corner = c4v_enlarge(network, env, alg.projector_alg)
corner′, projector, info = c4v_projector!(enlarged_corner, alg.projector_alg)
edge′ = c4v_renormalize_edge(network, env, projector)
info = (;
contraction_metrics = (; info.truncation_error, info.condition_number),
info.D, info.V, info.D_full, info.V_full, info.truncation_indices,
)
return CTMRGEnv(corner′, edge′), info
end
function ctmrg_iteration(
Expand All @@ -155,6 +158,7 @@ function ctmrg_iteration(
projector, info = c4v_projector!(enlarged_corner, alg.projector_alg)
edge′ = c4v_renormalize_edge(network, env, projector)
corner′ = c4v_qr_renormalize_corner(edge′, projector, info.R)
info = (; contraction_metrics = (;), info.Q, info.R)
return CTMRGEnv(corner′, edge′), info
end

Expand Down
45 changes: 15 additions & 30 deletions src/algorithms/ctmrg/ctmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ Perform a single CTMRG iteration in which all directions are being grown and ren
"""
function ctmrg_iteration(network, env, alg::CTMRGAlgorithm) end

"""
check_input(network, env, alg::CTMRGAlgorithm)
Check compatibility of a given network and environment with a specified CTMRG algorithm.
"""
function check_input(network, env, alg::CTMRGAlgorithm) end
@non_differentiable check_input(args...)

"""
leading_boundary(env₀, network; kwargs...) -> env, info
# expert version:
Expand Down Expand Up @@ -91,30 +83,15 @@ supplied via the keyword arguments or directly as an [`CTMRGAlgorithm`](@ref) st
* `projector_alg::Symbol=:$(Defaults.projector_alg)` : Variant of the projector algorithm. See also [`ProjectorAlgorithm`](@ref).
- `:halfinfinite` : Projection via SVDs of half-infinite (two enlarged corners) CTMRG environments.
- `:fullinfinite` : Projection via SVDs of full-infinite (all four enlarged corners) CTMRG environments.
- `:c4v_eigh` : Projection via `eigh` of the Hermitian enlarged corner.
- `:c4v_eigh` : Projection via `eigh` of the Hermitian enlarged corner, works only for [`C4vCTMRG`](@ref).
- `:c4v_qr` : Projection via QR decomposition of the lower-rank column-enlarged corner, works only for [`C4vCTMRG`](@ref).
## Return values
The CTMRG routine returns the final CTMRG environment as well as an information `NamedTuple`
containing the following fields:
* `truncation_error` : Last (maximal) SVD truncation error of the CTMRG projectors.
* `condition_number` : Last (maximal) condition number of the enlarged CTMRG environment.
In case the `alg` is a `SimultaneousCTMRG`, the last SVD will also be returned:
* `U` : Last unit cell of left singular vectors.
* `S` : Last unit cell of singular values.
* `V` : Last unit cell of right singular vectors.
If, in addition, the specified SVD algorithm computes the full, untruncated SVD, the full
set of vectors and values will be returned as well:
* `U_full` : Last unit cell of all left singular vectors.
* `S_full` : Last unit cell of all singular values.
* `V_full` : Last unit cell of all right singular vectors.
For `C4vCTMRG` instead the last eigendecomposition `V` and `D` (and `V_full`, `D_full`) will be returned.
The `leading_boundary` routine returns the final environment as well as an information `NamedTuple`
that generally contains a `contraction_metrics` `NamedTuple` storing different contents depending
on the chosen `alg`. Depending on the contraction method, the information tuple may also contain
the final tensor decomposition (used in the projectors) including its truncation indices.
"""
function leading_boundary(env₀::CTMRGEnv, network::InfiniteSquareNetwork; kwargs...)
alg = select_algorithm(leading_boundary, env₀; kwargs...)
Expand All @@ -123,7 +100,7 @@ end
function leading_boundary(
env₀::CTMRGEnv, network::InfiniteSquareNetwork, alg::CTMRGAlgorithm
)
check_input(network, env₀, alg)
check_input(leading_boundary, network, env₀, alg)
log = ignore_derivatives(() -> MPSKit.IterLog("CTMRG"))
return LoggingExtras.withlevel(; alg.verbosity) do
env = deepcopy(env₀)
Expand Down Expand Up @@ -154,6 +131,14 @@ function leading_boundary(env₀::CTMRGEnv, state, args...; kwargs...)
return leading_boundary(env₀, InfiniteSquareNetwork(state), args...; kwargs...)
end

"""
check_input(::typeof(leading_boundary), network, env, alg::CTMRGAlgorithm)
Check compatibility of a given network and environment with a specified CTMRG algorithm.
"""
function check_input(::typeof(leading_boundary), network, env, alg::CTMRGAlgorithm) end
@non_differentiable check_input(args...)

# custom CTMRG logging
function ctmrg_loginit!(log, η, network, env)
return @infov 2 loginit!(log, η, network_value(network, env))
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/ctmrg/sequential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function ctmrg_iteration(network, env::CTMRGEnv, alg::SequentialCTMRG)
network = rotate_north(network, EAST)
env = rotate_north(env, EAST)
end
return env, (; truncation_error, condition_number)
return env, (; contraction_metrics = (; truncation_error, condition_number))
end

"""
Expand Down
4 changes: 4 additions & 0 deletions src/algorithms/ctmrg/simultaneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function ctmrg_iteration(network, env::CTMRGEnv, alg::SimultaneousCTMRG)
end # expand environment
projectors, info = simultaneous_projectors(enlarged_corners, env, alg.projector_alg) # compute projectors on all coordinates
env′ = renormalize_simultaneously(enlarged_corners, projectors, network, env) # renormalize enlarged corners
info = (;
contraction_metrics = (; info.truncation_error, info.condition_number),
info.U, info.S, info.V, info.U_full, info.S_full, info.V_full, info.truncation_indices,
)
return env′, info
end

Expand Down
22 changes: 18 additions & 4 deletions src/algorithms/optimization/fixed_point_differentiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,19 @@ EigSolver(; kwargs...) = GradMode(; alg = :eigsolver, kwargs...)
GRADIENT_MODE_SYMBOLS[:eigsolver] = EigSolver

"""
_check_algorithm_combination(boundary_alg, gradient_alg)
_check_algorithm_combination(boundary_alg, gradient_alg_or_symmetrization)
_check_algorithm_combination(boundary_alg, gradient_alg, symmetrization)

Check for allowed combinations of gradient algorithm and boundary algorithm to be used for
computing the gradient of a `leading_boundary` call. Throws an error containing a
recommended fix if the combination is not allowed or broken.
"""
function _check_algorithm_combination(boundary_alg, gradient_alg) end
function _check_algorithm_combination(boundary_alg, gradient_alg_or_symmetrization) end
function _check_algorithm_combination(boundary_alg, gradient_alg, symmetrization)
_check_algorithm_combination(boundary_alg, gradient_alg)
_check_algorithm_combination(boundary_alg, symmetrization)
return nothing
end
function _check_algorithm_combination(::SequentialCTMRG, ::GradMode{:fixed})
msg = "`:fixed` mode is not compatible with `SequentialCTMRG` since the sequential \
application of SVDs does not allow to differentiate through a fixed set of \
Expand All @@ -216,10 +222,18 @@ function _check_algorithm_combination(::SequentialCTMRG, ::GradMode{:fixed})
end
function _check_algorithm_combination(::C4vCTMRG{<:C4vEighProjector}, ::GradMode{:diffgauge})
msg = "`:diffgauge` mode is currently not compatible with eigh-based C4v CTMRG; \
either switch to a different projector algorithm (e.g. `c4v_qr`), or use :fixed \
mode for differentiation instead."
either switch to a different projector algorithm (e.g. `c4v_qr`), or use :fixed \
mode for differentiation instead."
throw(ArgumentError(msg))
end
function _check_algorithm_combination(::C4vCTMRG, symm::Union{Nothing, <:SymmetrizationStyle})
if !(symm isa RotateReflect)
msg = "C4vCTMRG optimization is compatible only with RotateReflect symmetrization. \
Make sure to set `symmetrization = RotateReflect()`."
throw(ArgumentError(msg))
end
return nothing
end

#=
Evaluating the gradient of the cost function for CTMRG:
Expand Down
Loading
Loading