File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3
3
Documenter = " e30172f5-a6a5-5a46-863b-614d45cd2de4"
4
4
GenericTensorNetworks = " 3521c873-ad32-4bb4-b63d-f4f178f42b49"
5
5
KaHyPar = " 2a6221f6-aa48-11e9-3542-2d9e0ef01880"
6
+ LinearAlgebra = " 37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
6
7
OMEinsum = " ebe7aa44-baf0-506c-a96f-8464559b3922"
7
8
Pkg = " 44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
8
9
Random = " 9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
10
+ StatsBase = " 2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
9
11
Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
Original file line number Diff line number Diff line change 67
67
@testset " sample MPS" begin
68
68
n = 4
69
69
chi = 3
70
+ Random. seed! (140 )
70
71
mps = random_matrix_product_state (n, chi)
71
- Random. seed! (134 )
72
72
num_samples = 10000
73
- # samples = map(1:num_samples) do i
74
- # sample(mps, 1; queryvars=vcat(mps.mars...)).samples[:,1]
75
- # end
73
+ samples = map (1 : num_samples) do i
74
+ sample (mps, 1 ; queryvars= vcat (mps. mars... )). samples[:,1 ]
75
+ end
76
76
samples = sample (mps, num_samples; queryvars= vcat (mps. mars... ))
77
77
indices = map (samples) do sample
78
78
sum (i-> sample[i] * 2 ^ (i- 1 ), 1 : n) + 1
79
79
end
80
80
distribution = map (1 : 2 ^ n) do i
81
81
count (j-> j== i, indices) / num_samples
82
82
end
83
- probs = normalize! (real .(vec (DynamicEinCode (ixs , collect (1 : 4 ))(mps. tensors... ))), 1 )
83
+ probs = normalize! (real .(vec (DynamicEinCode (OMEinsum . getixsv (mps . code) , collect (1 : 4 ))(mps. tensors... ))), 1 )
84
84
negative_loglikelyhood (probs, samples) = - sum (log .(probs[samples]))/ length (samples)
85
85
entropy (probs) = - sum (probs .* log .(probs))
86
86
@show negative_loglikelyhood (probs, indices), entropy (probs)
You can’t perform that action at this time.
0 commit comments