|
1 | 1 | @eval module $(gensym()) |
2 | 2 | # using EinExprs: Exhaustive, Greedy, HyPar |
3 | | -# using ITensorNetworks: |
4 | | -# contraction_sequence, norm_sqr_network, random_tensornetwork, siteinds |
5 | | -# using ITensors: ITensors, contract |
6 | | -# using NamedGraphs.NamedGraphGenerators: named_grid |
7 | | -# using OMEinsumContractionOrders: OMEinsumContractionOrders |
8 | | -# using StableRNGs: StableRNG |
9 | | -# using TensorOperations: TensorOperations |
| 3 | +using ITensorNetworks: |
| 4 | + contraction_sequence, norm_sqr_network, random_tensornetwork, siteinds |
| 5 | +using ITensors: ITensors, contract |
| 6 | +using NamedGraphs.NamedGraphGenerators: named_grid |
| 7 | +using OMEinsumContractionOrders: OMEinsumContractionOrders |
| 8 | +using StableRNGs: StableRNG |
| 9 | +using TensorOperations: TensorOperations |
10 | 10 | using Test: @test, @testset |
11 | 11 | @testset "contraction_sequence" begin |
12 | | - # ITensors.@disable_warn_order begin |
13 | | - # dims = (2, 3) |
14 | | - # g = named_grid(dims) |
15 | | - # s = siteinds("S=1/2", g) |
16 | | - # χ = 10 |
17 | | - # rng = StableRNG(1234) |
18 | | - # ψ = random_tensornetwork(rng, s; link_space=χ) |
19 | | - # tn = norm_sqr_network(ψ) |
20 | | - # seq_optimal = contraction_sequence(tn; alg="optimal") |
21 | | - # res_optimal = contract(tn; sequence=seq_optimal)[] |
22 | | - # seq_greedy = contraction_sequence(tn; alg="greedy") |
23 | | - # res_greedy = contract(tn; sequence=seq_greedy)[] |
24 | | - # seq_tree_sa = contraction_sequence(tn; alg="tree_sa") |
25 | | - # res_tree_sa = contract(tn; sequence=seq_tree_sa)[] |
26 | | - # seq_sa_bipartite = contraction_sequence(tn; alg="sa_bipartite") |
27 | | - # res_sa_bipartite = contract(tn; sequence=seq_sa_bipartite)[] |
28 | | - # seq_einexprs_exhaustive = contraction_sequence( |
29 | | - # tn; alg="einexpr", optimizer=Exhaustive() |
30 | | - # ) |
31 | | - # res_einexprs_exhaustive = contract(tn; sequence=seq_einexprs_exhaustive)[] |
32 | | - # seq_einexprs_greedy = contraction_sequence(tn; alg="einexpr", optimizer=Greedy()) |
33 | | - # res_einexprs_greedy = contract(tn; sequence=seq_einexprs_exhaustive)[] |
34 | | - # @test res_greedy ≈ res_optimal |
35 | | - # @test res_tree_sa ≈ res_optimal |
36 | | - # @test res_sa_bipartite ≈ res_optimal |
37 | | - # @test res_einexprs_exhaustive ≈ res_optimal |
38 | | - # @test res_einexprs_greedy ≈ res_optimal |
| 12 | + ITensors.@disable_warn_order begin |
| 13 | + dims = (2, 3) |
| 14 | + g = named_grid(dims) |
| 15 | + s = siteinds("S=1/2", g) |
| 16 | + χ = 10 |
| 17 | + rng = StableRNG(1234) |
| 18 | + ψ = random_tensornetwork(rng, s; link_space=χ) |
| 19 | + tn = norm_sqr_network(ψ) |
| 20 | + seq_optimal = contraction_sequence(tn; alg="optimal") |
| 21 | + res_optimal = contract(tn; sequence=seq_optimal)[] |
| 22 | + seq_greedy = contraction_sequence(tn; alg="greedy") |
| 23 | + res_greedy = contract(tn; sequence=seq_greedy)[] |
| 24 | + seq_tree_sa = contraction_sequence(tn; alg="tree_sa") |
| 25 | + res_tree_sa = contract(tn; sequence=seq_tree_sa)[] |
| 26 | + seq_sa_bipartite = contraction_sequence(tn; alg="sa_bipartite") |
| 27 | + res_sa_bipartite = contract(tn; sequence=seq_sa_bipartite)[] |
| 28 | + # seq_einexprs_exhaustive = contraction_sequence( |
| 29 | + # tn; alg="einexpr", optimizer=Exhaustive() |
| 30 | + # ) |
| 31 | + # res_einexprs_exhaustive = contract(tn; sequence=seq_einexprs_exhaustive)[] |
| 32 | + # seq_einexprs_greedy = contraction_sequence(tn; alg="einexpr", optimizer=Greedy()) |
| 33 | + # res_einexprs_greedy = contract(tn; sequence=seq_einexprs_exhaustive)[] |
| 34 | + @test res_greedy ≈ res_optimal |
| 35 | + @test res_tree_sa ≈ res_optimal |
| 36 | + @test res_sa_bipartite ≈ res_optimal |
| 37 | + # @test res_einexprs_exhaustive ≈ res_optimal |
| 38 | + # @test res_einexprs_greedy ≈ res_optimal |
39 | 39 |
|
40 | | - # if !Sys.iswindows() |
41 | | - # # KaHyPar doesn't work on Windows |
42 | | - # # https://github.com/kahypar/KaHyPar.jl/issues/9 |
43 | | - # using Pkg |
44 | | - # Pkg.add("KaHyPar"; io=devnull) |
45 | | - # using KaHyPar |
46 | | - # seq_kahypar_bipartite = contraction_sequence( |
47 | | - # tn; alg="kahypar_bipartite", sc_target=200 |
48 | | - # ) |
49 | | - # Pkg.rm("KaHyPar"; io=devnull) |
50 | | - # res_kahypar_bipartite = contract(tn; sequence=seq_kahypar_bipartite)[] |
51 | | - # @test res_optimal ≈ res_kahypar_bipartite |
52 | | - # seq_einexprs_kahypar = contraction_sequence(tn; alg="einexpr", optimizer=HyPar()) |
53 | | - # res_einexprs_kahypar = contract(tn; sequence=seq_einexprs_kahypar)[] |
54 | | - # @test res_einexprs_kahypar ≈ res_optimal |
55 | | - # end |
56 | | - # end |
| 40 | + if !Sys.iswindows() |
| 41 | + # KaHyPar doesn't work on Windows |
| 42 | + # https://github.com/kahypar/KaHyPar.jl/issues/9 |
| 43 | + using Pkg |
| 44 | + Pkg.add("KaHyPar"; io=devnull) |
| 45 | + using KaHyPar |
| 46 | + seq_kahypar_bipartite = contraction_sequence( |
| 47 | + tn; alg="kahypar_bipartite", sc_target=200 |
| 48 | + ) |
| 49 | + Pkg.rm("KaHyPar"; io=devnull) |
| 50 | + res_kahypar_bipartite = contract(tn; sequence=seq_kahypar_bipartite)[] |
| 51 | + @test res_optimal ≈ res_kahypar_bipartite |
| 52 | + # seq_einexprs_kahypar = contraction_sequence(tn; alg="einexpr", optimizer=HyPar()) |
| 53 | + # res_einexprs_kahypar = contract(tn; sequence=seq_einexprs_kahypar)[] |
| 54 | + # @test res_einexprs_kahypar ≈ res_optimal |
| 55 | + end |
| 56 | + end |
57 | 57 | end |
58 | 58 | end |
0 commit comments