From e7228c0f4996e1be84a3ee068a9fb922e6bdb6d4 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 20 Aug 2026 08:26:08 +0200 Subject: [PATCH 1/7] Allow toggling of svd algorithm in BP with Defaults --- src/algorithms/bp/gaugefix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index 0f074dada..78162af10 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -81,7 +81,7 @@ function _bp_gauge_fix!(I::CartesianIndex{3}, psi::InfinitePEPS, env::BPEnv) @assert dir == NORTH || dir == EAST sqrtM12, isqrtM12, sqrtM21, isqrtM21 = _sqrt_bp_messages(I, env) - U, Λ, Vᴴ = svd_compact!(sqrtM12 * sqrtM21) + U, Λ, Vᴴ = svd_compact!(sqrtM12 * sqrtM21; alg = Defaults.svd_fwd_alg) sqrtΛ = sdiag_pow(Λ, 1 / 2) X = isqrtM12 * U * sqrtΛ invX = sqrtΛ * Vᴴ * isqrtM21 From dbef61abd3304454ec988c763f92339d85e9aa64 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Fri, 21 Aug 2026 08:35:12 +0200 Subject: [PATCH 2/7] Move alg into BPGauge --- src/algorithms/bp/gaugefix.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index 78162af10..81761447e 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -2,9 +2,12 @@ struct BPGauge Algorithm for gauging PEPS with belief propagation fixed point messages. + +Arguments: +- `svd_fwd_alg`: Algorithm to use for the SVD on the forward pass. Default is [`Defaults.svd_fwd_alg`](@ref). """ @kwdef struct BPGauge - # TODO: add options + svd_fwd_alg = Defaults.svd_fwd_alg end """ @@ -18,7 +21,7 @@ function gauge_fix(psi::InfinitePEPS, alg::BPGauge, env::BPEnv) bipartite = _is_bipartite(psi) && _is_bipartite(env) psi′ = copy(psi) XXinv = map(eachcoordinate(psi, 1:2)) do I - _, X, Xinv = _bp_gauge_fix!(CartesianIndex(I), psi′, env) + _, X, Xinv = _bp_gauge_fix!(CartesianIndex(I), psi′, env, alg) return X, Xinv end if bipartite @@ -76,12 +79,12 @@ along the canonical direction of the PEPS arrows (`SOUTH ← NORTH` or `WEST ← Which are then used to update the gauge of `psi`. Thus, by convention `X` is attached to the `SOUTH`/`WEST` directions and `X⁻¹` is attached to the `NORTH`/`EAST` directions. """ -function _bp_gauge_fix!(I::CartesianIndex{3}, psi::InfinitePEPS, env::BPEnv) +function _bp_gauge_fix!(I::CartesianIndex{3}, psi::InfinitePEPS, env::BPEnv, alg::BPGauge) dir, row, col = Tuple(I) @assert dir == NORTH || dir == EAST sqrtM12, isqrtM12, sqrtM21, isqrtM21 = _sqrt_bp_messages(I, env) - U, Λ, Vᴴ = svd_compact!(sqrtM12 * sqrtM21; alg = Defaults.svd_fwd_alg) + U, Λ, Vᴴ = svd_compact!(sqrtM12 * sqrtM21; alg = alg.svd_fwd_alg) sqrtΛ = sdiag_pow(Λ, 1 / 2) X = isqrtM12 * U * sqrtΛ invX = sqrtΛ * Vᴴ * isqrtM21 From 298e1c31094a7527e50cf9377f4227658085f3f6 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Fri, 21 Aug 2026 10:53:48 +0200 Subject: [PATCH 3/7] Fix docstring --- src/algorithms/bp/gaugefix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index 81761447e..190728c36 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -4,7 +4,7 @@ Algorithm for gauging PEPS with belief propagation fixed point messages. Arguments: -- `svd_fwd_alg`: Algorithm to use for the SVD on the forward pass. Default is [`Defaults.svd_fwd_alg`](@ref). +- `svd_fwd_alg`: Algorithm to use for the SVD on the forward pass. Default is $(Defaults.svd_fwd_alg). """ @kwdef struct BPGauge svd_fwd_alg = Defaults.svd_fwd_alg From 9af516ffcf938460b9a5a95b6f24095e2bdf68e6 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Fri, 21 Aug 2026 11:09:41 +0200 Subject: [PATCH 4/7] Make BPGauge parameterized to help inference --- src/algorithms/bp/gaugefix.jl | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index 190728c36..dc03b247a 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -3,11 +3,29 @@ Algorithm for gauging PEPS with belief propagation fixed point messages. -Arguments: -- `svd_fwd_alg`: Algorithm to use for the SVD on the forward pass. Default is $(Defaults.svd_fwd_alg). +## Fields + +$(TYPEDFIELDS) + +## Constructors + + BPGauge(; svd_fwd_alg=:$(Defaults.svd_fwd_alg)) + +The SVD algorithm of the forward pass can either be specified as a `Symbol`, or be passed +as a `MatrixAlgebraKit.Algorithm` instance directly. Note that the algorithm needs to +support a full `svd_compact!` decomposition, such that the "sparse" `:GKL` algorithm is not +supported here. The available algorithms are: + +- `:DefaultAlgorithm` : MatrixAlgebraKit's [default SVD algorithm](@extref MatrixAlgebraKit.DefaultAlgorithm) for a given matrix type. +- `:DivideAndConquer` : MatrixAlgebraKit's [`DivideAndConquer`](@extref MatrixAlgebraKit.DivideAndConquer) +- `:QRIteration` : MatrixAlgebraKit's [`QRIteration`](@extref MatrixAlgebraKit.QRIteration) +- `:Bisection` : MatrixAlgebraKit's [`Bisection`](@extref MatrixAlgebraKit.Bisection) +- `:Jacobi` : MatrixAlgebraKit's [`Jacobi`](@extref MatrixAlgebraKit.Jacobi) +- `:SVDViaPolar` : MatrixAlgebraKit's [`SVDViaPolar`](@extref MatrixAlgebraKit.SVDViaPolar) +- `:SafeDivideAndConquer` : MatrixAlgebraKit's [`SafeDivideAndConquer`](@extref MatrixAlgebraKit.SafeDivideAndConquer) """ -@kwdef struct BPGauge - svd_fwd_alg = Defaults.svd_fwd_alg +@kwdef struct BPGauge{F} + svd_fwd_alg::F = Defaults.svd_fwd_alg end """ From b761446073a26c80c4f0e8d1e4dc2e5ce89fb970 Mon Sep 17 00:00:00 2001 From: Lander Burgelman <39218680+leburgel@users.noreply.github.com> Date: Mon, 31 Aug 2026 10:25:41 +0200 Subject: [PATCH 5/7] Update src/algorithms/bp/gaugefix.jl Co-authored-by: Lukas Devos --- src/algorithms/bp/gaugefix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index dc03b247a..1f272f862 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -25,7 +25,7 @@ supported here. The available algorithms are: - `:SafeDivideAndConquer` : MatrixAlgebraKit's [`SafeDivideAndConquer`](@extref MatrixAlgebraKit.SafeDivideAndConquer) """ @kwdef struct BPGauge{F} - svd_fwd_alg::F = Defaults.svd_fwd_alg + svd_alg::F = Defaults.svd_fwd_alg end """ From 373e2743264d36892e29a47230c0c150113c2b24 Mon Sep 17 00:00:00 2001 From: leburgel Date: Thu, 3 Sep 2026 16:28:17 +0200 Subject: [PATCH 6/7] Address remaining review comment --- src/algorithms/bp/gaugefix.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index 1f272f862..c4a040b00 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -9,12 +9,12 @@ $(TYPEDFIELDS) ## Constructors - BPGauge(; svd_fwd_alg=:$(Defaults.svd_fwd_alg)) + BPGauge(; svd_alg=:$(Defaults.svd_fwd_alg)) -The SVD algorithm of the forward pass can either be specified as a `Symbol`, or be passed -as a `MatrixAlgebraKit.Algorithm` instance directly. Note that the algorithm needs to -support a full `svd_compact!` decomposition, such that the "sparse" `:GKL` algorithm is not -supported here. The available algorithms are: +The SVD algorithm can either be specified as a `Symbol`, or be passed as a +`MatrixAlgebraKit.Algorithm` instance directly. Note that the algorithm needs to support a +full `svd_compact!` decomposition, such that the "sparse" `:GKL` algorithm is not supported +here. The available algorithms are: - `:DefaultAlgorithm` : MatrixAlgebraKit's [default SVD algorithm](@extref MatrixAlgebraKit.DefaultAlgorithm) for a given matrix type. - `:DivideAndConquer` : MatrixAlgebraKit's [`DivideAndConquer`](@extref MatrixAlgebraKit.DivideAndConquer) From a693d94a031ea7a263be0e942b82826aacc6a6a1 Mon Sep 17 00:00:00 2001 From: leburgel Date: Thu, 3 Sep 2026 16:29:36 +0200 Subject: [PATCH 7/7] Missed one rename --- src/algorithms/bp/gaugefix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/bp/gaugefix.jl b/src/algorithms/bp/gaugefix.jl index c4a040b00..15693557a 100644 --- a/src/algorithms/bp/gaugefix.jl +++ b/src/algorithms/bp/gaugefix.jl @@ -102,7 +102,7 @@ function _bp_gauge_fix!(I::CartesianIndex{3}, psi::InfinitePEPS, env::BPEnv, alg @assert dir == NORTH || dir == EAST sqrtM12, isqrtM12, sqrtM21, isqrtM21 = _sqrt_bp_messages(I, env) - U, Λ, Vᴴ = svd_compact!(sqrtM12 * sqrtM21; alg = alg.svd_fwd_alg) + U, Λ, Vᴴ = svd_compact!(sqrtM12 * sqrtM21; alg = alg.svd_alg) sqrtΛ = sdiag_pow(Λ, 1 / 2) X = isqrtM12 * U * sqrtΛ invX = sqrtΛ * Vᴴ * isqrtM21