Repository navigation
Add BufferedBPGateUpdate, BP gate stages with allocator scratch - #11
Open
jack-dunham wants to merge 10 commits into
Open
jack-dunham wants to merge 10 commits into
jack-dunham wants to merge 10 commits into
Conversation
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/apply/apply_operators.jl b/src/apply/apply_operators.jl
index dc9ae4b..b3d9697 100644
--- a/src/apply/apply_operators.jl
+++ b/src/apply/apply_operators.jl
@@ -529,7 +529,8 @@ function bp_gate_factorize!(
subalgorithm::SimpleBPGateUpdate, op::AbstractITensor, state, env, v, w
)
roots = [
- message_gauge(m; alg = subalgorithm.eigh_alg) for m in incoming_messages(env, v => w)
+ message_gauge(m; alg = subalgorithm.eigh_alg) for
+ m in incoming_messages(env, v => w)
]
ψ = absorb_matrices!(subalgorithm.contract_alg, state[v], first.(roots)...)
bondname = only(intersect(names(state[v]), names(env[w => v])))
diff --git a/test/test_apply_operator.jl b/test/test_apply_operator.jl
index 5f78ff1..6148c68 100644
--- a/test/test_apply_operator.jl
+++ b/test/test_apply_operator.jl
@@ -226,7 +226,8 @@ end
end
buffered = BPApplyGate(; subalgorithm = buffered_update)
simple_state, _ = apply_operator(gates[1], network, complex_env)
- buffered_state, _ = apply_operator(gates[1], network, complex_env; alg = buffered)
+ buffered_state, _ =
+ apply_operator(gates[1], network, complex_env; alg = buffered)
@test prod(buffered_state) ≈ prod(simple_state) rtol = rtol
end
|
jack-dunham
force-pushed
the
buffered-bp-gate-update
branch
from
October 8, 2026 18:50
831dfea to
bf5b00d
Compare
jack-dunham
changed the base branch from
blocked-message-update
to
jd/quadratic-form
October 8, 2026 18:53
jack-dunham
changed the base branch from
jd/quadratic-form
to
blocked-message-update
October 8, 2026 18:53
jack-dunham
force-pushed
the
buffered-bp-gate-update
branch
from
October 8, 2026 19:40
bf5b00d to
a19feff
Compare
jack-dunham
force-pushed
the
buffered-bp-gate-update
branch
3 times, most recently
from
October 15, 2026 19:34
97d1b2e to
4df1de4
Compare
jack-dunham
force-pushed
the
buffered-bp-gate-update
branch
from
October 15, 2026 19:36
4df1de4 to
1a4eb44
Compare
jack-dunham
force-pushed
the
buffered-bp-gate-update
branch
from
October 19, 2026 14:41
071f16d to
da26595
Compare
`absorb_matrices!(alg, t, matrices...)` returns `t * matrices[1] * matrices[2] * …` and may overwrite `t`. The generic method folds `*`. The TensorOperations method, for dense `t` and matrices with both legs on one axis and `t`'s element type, alternates between `t` and one scratch tensor taken from `alg`'s allocator and freed on return, keeping each new leg in the contracted leg's place; anything else takes the generic method. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ct_alg` `SimpleBPGateUpdate(; contract_alg = nothing)` absorbs the message roots in `bp_gate_factorize!` and the inverse roots in `bp_gate_restore!` with `absorb_matrices!`. With a `TensorOperationsContract` on dense storage the absorption reuses the vertex tensor's memory and one allocator scratch tensor; graded storage, whose roots change the bond's axis, allocates as before. Tests compare a `TensorOperationsContract`, with the default and a `BufferAllocator`, against the default contraction, including complex messages and graded storage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Q` then occupies the gauged vertex's buffer, so `bp_gate_restore!` holds that buffer and the output rather than three factor-sized buffers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `ITensor` method works out the labels after each absorption and passes arrays and labels on. Dense arrays take the two-buffer method, which now throws through `check_input` for a non-square matrix or one of another element type, and writes outputs of 2^30 elements or more in blocks of the last leg for cuTENSOR 2.7. Other arrays throw, since TensorOperations reads a graded array element by element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the `Diagonal` first, TensorAlgebra allocates a host output for GPU data and then indexes the device array element by element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each operator's vertices are its operator_support in the network, which every reader can compute when it needs them: step!, and StopWhenVertexRevisited from the iterate of its state. A network holding only part of the vertices answers the lookup through has_dimname and dimnamevertices, so apply_operators and apply_operators! drop their vertices keyword. The check that every operator input is on a tensor of the network still runs before any operator is applied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`induced_subgraph_from_vertices` takes the subgraph of the operator's network and keeps the output→input pairs whose output is on it, since the operator constructor throws for a name on no vertex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`BeliefPropagationEnvironmentPreparation(network, env)` and `update_environment` called the `NormNetwork` constructor, which only accepts an `ITensorNetwork`. `normnetwork` lets a package return its own norm network type for its network type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…age gauge cuSOLVER's divide-and-conquer Hermitian eigensolver (`cusolverDnXsyevd`, MatrixAlgebraKit's default for a `CuArray`) returns NaN eigenvalues and eigenvectors for some nearly singular ComplexF32 messages, which `message_gauge` passes into the gate. `eigh_alg = Jacobi()` avoids it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the vertex's storage `apply(op, t)` contracts through `MatricizeContract`, which makes a permuted copy of `t` before the product, so a one-site gate held three copies of the vertex tensor at once. The gate now calls `mulopadd!` with `contract_alg` (cuTENSOR for `TensorOperationsContract` on a GPU), reading a copy of `t` and writing the result over `t`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jack-dunham
force-pushed
the
buffered-bp-gate-update
branch
from
October 20, 2026 18:50
1c7bfb5 to
c1db26a
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on
blocked-message-update(#1), which is stacked onbp-gate-stagesandjd/quadratic-form.Summary
BufferedBPGateUpdateis an opt-in subalgorithm ofBPApplyGate. Itsbp_gate_factorize!andbp_gate_restore!absorb the message roots in place, so each vertex holds two tensors of its own size instead of one per message.absorb_matrices!(alg, ψ, matrices...)overwritesψwithψtimes each operator in turn, alternating betweenψand one scratch tensor of its size. With aTensorOperationsContract, every contraction goes through TensorOperations.message_gaugeroots (Use the asymmetric Gram root for the BP simple-update gauge ITensor/ITensorNetworksNext.jl#204). Each(x, y)pair is wrapped as operators on the bond name, soabsorb_matrices!keepsψ's index names while the leg holds the rank space.ArgumentError.The first commit consolidates the buffered parts of several earlier
bp-gate-stagescommits, rewritten for the current gate API.Tests
BufferedBPGateUpdatematchesSimpleBPGateUpdateon a 2×3 grid in Float32, Float64 and ComplexF64, with the default allocator and with aBufferAllocator.apply_operatorsleaves its input unchanged, andapply_operator!names the new bond as requested.absorb_matrices!matchesapplyfor 0 to 3 matrices, withMatricizeContractandTensorOperationsContract.test_aqua.jl,test_apply_operator.jl,test_prod_tensors.jl,test_blockedmessageupdate.jl,test_beliefpropagation.jl,test_normnetwork.jlandtest_quadraticformnetwork.jlpass (1266 tests).🤖 Generated with Claude Code