-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,20 +1,38 @@ | ||
default_derivative_algorithm() = "exact" | ||
|
||
function derivative(ψ::AbstractITensorNetwork, vertices::Vector; alg = default_derivative_algorithm(), kwargs...) | ||
return derivative(Algorithm(alg), ψ, vertices; kwargs...) | ||
function derivative( | ||
ψ::AbstractITensorNetwork, vertices::Vector; alg=default_derivative_algorithm(), kwargs... | ||
) | ||
return derivative(Algorithm(alg), ψ, vertices; kwargs...) | ||
end | ||
|
||
function derivative(::Algorithm"exact", ψ::AbstractITensorNetwork, vertices::Vector; contraction_sequence_alg = "optimal", kwargs...) | ||
ψ_reduced = Vector{ITensor}(subgraph(ψ, vertices)) | ||
return contract_exact(ψ_reduced; normalize = false, contraction_sequence_alg, kwargs...) | ||
function derivative( | ||
::Algorithm"exact", | ||
ψ::AbstractITensorNetwork, | ||
vertices::Vector; | ||
contraction_sequence_alg="optimal", | ||
kwargs..., | ||
) | ||
ψ_reduced = Vector{ITensor}(subgraph(ψ, vertices)) | ||
sequence = contraction_sequence(ψ_reduced; alg=contraction_sequence_alg) | ||
return ITensor[contract(ψ_reduced; sequence, kwargs...)] | ||
end | ||
|
||
function derivative(::Algorithm"bp", ψ::AbstractITensorNetwork, vertices::Vector; (bp_cache!) = nothing, bp_cache_update_kwargs = default_cache_update_kwargs(bp_cache)) | ||
function derivative( | ||
::Algorithm"bp", | ||
ψ::AbstractITensorNetwork, | ||
verts::Vector; | ||
(bp_cache!)=nothing, | ||
update_bp_cache=isnothing(bp_cache!), | ||
bp_cache_update_kwargs=default_cache_update_kwargs(bp_cache!), | ||
) | ||
if isnothing(bp_cache!) | ||
bp_cache! = Ref(BeliefPropagationCache(ψ)) | ||
end | ||
|
||
if isnothing(bp_cache!) | ||
bp_cache! = Ref(default_cache(ψ)) | ||
end | ||
if update_bp_cache | ||
bp_cache![] = update(bp_cache![]; bp_cache_update_kwargs...) | ||
return incoming_messages(bp_cache![], vertices) | ||
end | ||
|
||
return incoming_messages(bp_cache![], setdiff(vertices(ψ), verts)) | ||
end | ||
|
This file contains 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 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 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