Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Introduce partitioned_contract #97

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b256f54
Introduce contraction_sequence_to_directed_graph and simplify contrac…
LinjianMa Jun 22, 2023
1e97948
Introduce approx_itensornetwork with algorithm ttn_svd
LinjianMa Jun 22, 2023
192f129
Merge branch 'rewrite_contract2' into rewrite_contract
LinjianMa Jun 22, 2023
5505385
save changes
LinjianMa Jun 23, 2023
b36d05d
remove contraction_sequence_to_directed_graph
LinjianMa Jun 23, 2023
cdf41f9
Merge branch 'contraction_graph_fix' into rewrite_contract
LinjianMa Jun 23, 2023
e217537
revert changes
LinjianMa Jun 23, 2023
784afe6
save changes
LinjianMa Jun 25, 2023
b875840
save changes
LinjianMa Jun 26, 2023
b2315d2
Merge branch 'mtfishman:main' into rewrite_contract
LinjianMa Jul 1, 2023
81dc16a
api change
LinjianMa Jul 1, 2023
e5d73ed
Add binary tree structure with top down algorithm
LinjianMa Jul 2, 2023
2f3b2b4
Let binary_tree_structure support a vector of inds vectors
LinjianMa Jul 2, 2023
f87d9ba
Merge branch 'recursive_bisection' into rewrite_contract
LinjianMa Jul 2, 2023
9beee04
implement reference ordering
LinjianMa Jul 3, 2023
bfd6f68
Start on adjacency tree
LinjianMa Jul 3, 2023
4936d79
Finish _adjacency_tree, tests to be added
LinjianMa Jul 3, 2023
7c12d44
Implement the first version of _constrained_minswap_inds_ordering
LinjianMa Jul 3, 2023
6c2998f
Finish _constrained_minswap_inds_ordering
LinjianMa Jul 3, 2023
29db3b3
Finish a pass of partitioned_contract
LinjianMa Jul 3, 2023
d685eb5
Finish _ansatz_tree
LinjianMa Jul 3, 2023
7c4405e
finish _ind_orderings
LinjianMa Jul 4, 2023
d8d2fcd
A new partitioned_contract interface
LinjianMa Jul 4, 2023
95eed58
Rewrite _recursive_bisection to better handle the case with target_se…
LinjianMa Jul 4, 2023
37cdd5f
Add _roots
LinjianMa Jul 4, 2023
a638eae
Fix multiple bugs in partitioned_contract
LinjianMa Jul 4, 2023
54fa283
Fix bugs
LinjianMa Jul 5, 2023
1889d99
3d cube running working, performance better than the prev implementation
LinjianMa Jul 5, 2023
d60c21e
Implement contract with partitioned_contract
LinjianMa Jul 5, 2023
53348f3
bug fixes & logging & renaming for partitioned_contract
LinjianMa Jul 5, 2023
2711bbd
randregulargraph works
LinjianMa Jul 5, 2023
0567f1b
rename approx_contract in examples to partitioned_contract
LinjianMa Jul 5, 2023
e842e61
Merge upstream
LinjianMa Jul 6, 2023
00bc6cd
Add quantum circuit simulation. Performance can be improved
LinjianMa Jul 7, 2023
a14267e
Add timer to _mps_order
LinjianMa Jul 8, 2023
2da8714
Make _ind_orderings more efficient, and add c_in_leaves to _constrain…
LinjianMa Jul 8, 2023
0dee11b
Merge branch 'mtfishman:main' into rewrite_contract
LinjianMa Jul 15, 2023
6ff94cf
Add qr-svd option for density matrix algorithm
LinjianMa Jul 15, 2023
27c5779
Fix a big in density matrix alg with qr svd, add args to choose the alg
LinjianMa Jul 18, 2023
55dd8b7
Add bench for tree tn truncate
LinjianMa Jul 18, 2023
d9ef212
Add benchmarks for approx contract
LinjianMa Jul 19, 2023
7e9ce10
change runtest back
LinjianMa Jul 19, 2023
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
Prev Previous commit
Next Next commit
save changes
  • Loading branch information
LinjianMa committed Jun 26, 2023
commit b875840f9a3905ff8a1156e73332485d48ca458e
2 changes: 2 additions & 0 deletions src/approx_itensornetwork/ttn_svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function _approx_itensornetwork_ttn_svd!(
tn = ITensorNetwork()
for v in vertices(input_partition)
add_vertex!(tn, v)
# TODO: use `dense(optcontract(ts))` to convert Diag type to dense
# for QR decomposition TODO: raise an error in ITensors
tn[v] = _optcontract(
Vector{ITensor}(input_partition[v]);
contraction_sequence_alg=contraction_sequence_alg,
Expand Down
1 change: 1 addition & 0 deletions src/partitioned_contract/adjacency_tree.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

120 changes: 116 additions & 4 deletions src/partitioned_contract/partitioned_contract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function partitioned_contract(
inds_orderings = [p_edge_to_ordered_inds[e] for e in p_edges]
v_to_tn[v], log_root_norm = approx_itensornetwork(
tn,
_ansatz_tree(inds_orderings, ansatz);
_ansatz_tree(inds_orderings, _ortho_center(v_to_ordered_p_edges[v]), ansatz);
alg=approx_itensornetwork_alg,
cutoff=cutoff,
maxdim=maxdim,
Expand All @@ -74,12 +74,43 @@ function partitioned_contract(
end
end

# TODO: replace the subarray of `v1` with `v2`
function _is_neighbored_subset(v::Vector, set::Set)
if set == Set()
return true
end
@assert issubset(set, Set(v))
i_begin = 1
while !(i_begin in set)
i_begin += 1
end
i_end = length(v)
while !(i_end in set)
i_end -= 1
end
return Set(v[i_begin:i_end]) == set
end

# replace the subarray of `v1` with `v2`
function _replace_subarray(v1::Vector, v2::Vector)
if v2 == []
return v1
end
v1 = copy(v1)
num = 0
for i in 1:length(v1)
if v1[i] in v2
num += 1
v1[i] = v2[num]
end
end
@assert num == length(v2)
return v1
end

function _neighbor_edges(graph, vs)
return filter(e -> (e.src in vs and !(e.dst in vs)) || (e.dst in vs and !(e.src in vs)), edges(graph))
return filter(
e -> (e.src in vs && !(e.dst in vs)) || (e.dst in vs && !(e.src in vs)), edges(graph)
)
end

function _ind_orderings(partition::DataGraph)
Expand All @@ -90,6 +121,87 @@ function _constrained_mincost_inds_ordering(inds_set::Set, tn::ITensorNetwork, p
# TODO: edge set ordering of tn
end

function _ansatz_tree(inds_orderings::Vector, ansatz::String)
function _ansatz_tree(inds_orderings::Vector, ortho_center::Integer, ansatz::String)
# TODO
end

function _ortho_center(edges_to_contract_edges)
# TODO
end

# function ordered_igs_to_binary_tree(ordered_igs, contract_igs, ig_to_linear_order; ansatz)
# @assert ansatz in ["comb", "mps"]
# @timeit_debug ITensors.timer "ordered_igs_to_binary_tree" begin
# if contract_igs == []
# @info "contract_igs is empty vector"
# end
# # @assert contract_igs != []
# left_igs, right_igs = split_igs(ordered_igs, contract_igs)
# if ansatz == "comb"
# return ordered_igs_to_binary_tree_comb(
# left_igs, right_igs, contract_igs, ig_to_linear_order
# )
# elseif ansatz == "mps"
# return ordered_igs_to_binary_tree_mps(
# left_igs, right_igs, contract_igs, ig_to_linear_order
# )
# end
# end
# end

# function ordered_igs_to_binary_tree(igs, ig_to_linear_order; ansatz, direction)
# @assert ansatz in ["comb", "mps"]
# @assert direction in ["left", "right"]
# if ansatz == "comb"
# return line_to_tree([line_to_tree(ig_to_linear_order[ig]) for ig in igs])
# end
# if direction == "left"
# order = vcat([ig_to_linear_order[ig] for ig in igs]...)
# return line_to_tree(order)
# else
# # First reverse get the order from middle to boundary,
# # and second reverse get the overall inds order from boundary to middle.
# order = vcat([ig_to_linear_order[ig] for ig in reverse(igs)]...)
# return line_to_tree(reverse(order))
# end
# end

# function ordered_igs_to_binary_tree_mps(
# left_igs, right_igs, contract_igs, ig_to_linear_order
# )
# left_order = get_leaves([ig_to_linear_order[ig] for ig in left_igs])
# right_order = get_leaves([ig_to_linear_order[ig] for ig in right_igs])
# contract_order = get_leaves([ig_to_linear_order[ig] for ig in contract_igs])
# if length(left_order) <= length(right_order)
# left_order = [left_order..., contract_order...]
# else
# right_order = [contract_order..., right_order...]
# end
# return merge_tree(line_to_tree(left_order), line_to_tree(reverse(right_order)))
# end

# function ordered_igs_to_binary_tree_comb(
# left_igs, right_igs, contract_igs, ig_to_linear_order
# )
# tree_1 = ordered_igs_to_binary_tree(
# left_igs, ig_to_linear_order; ansatz="comb", direction="left"
# )
# tree_contract = ordered_igs_to_binary_tree(
# contract_igs, ig_to_linear_order; ansatz="comb", direction="left"
# )
# tree_2 = ordered_igs_to_binary_tree(
# reverse(right_igs), ig_to_linear_order; ansatz="comb", direction="left"
# )
# # make the binary tree more balanced to save tree approximation cost
# if tree_1 == []
# return merge_tree(merge_tree(tree_1, tree_contract), tree_2)
# end
# if tree_2 == []
# return merge_tree(tree_1, merge_tree(tree_contract, tree_2))
# end
# if length(vectorize(tree_1)) <= length(vectorize(tree_2))
# return merge_tree(merge_tree(tree_1, tree_contract), tree_2)
# else
# return merge_tree(tree_1, merge_tree(tree_contract, tree_2))
# end
# end